Re: [racket-users] Animation-problem

2016-12-05 Thread Daniel Prager
My pleasure.

Good on you for doing the exercise.

Here's a slightly modified version that:

   - removes the use of set!: it's cleaner "functional" style to avoid
   mutation where possible
   - illustrates the use of match-define to unpack world
   - other small tweaks and tricks

Dan


#lang racket

(require 2htdp/universe)
(require 2htdp/image)

(struct world (foreground background count))

(define (random-color)
  (make-color (random 255) (random 255) (random 255)))

(define (next-state state)
  (world (random-color)
 (random-color)
 (add1 (world-count state

(define (SUPER state)
  (match-define (world fg bg n) state)
  (overlay/align 'left 'top
 (text (~a n) 30 "gray")
 (overlay (text "SUPER" 105 fg)
  (circle 200 "solid" bg

(big-bang (world (random-color) (random-color) 0)
  (on-tick next-state 0.3)
  (to-draw SUPER))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Animation-problem

2016-12-05 Thread Janiho
Thank you Dan, that was very helpful! I haven't used that function big-bang but 
it seems quite simple.

I also add that counter what you suggested. It take some time to figure out how 
I convert that counter's value to image. 

--
#lang racket
(require 2htdp/universe)
(require 2htdp/image)

(struct world (foreground background count) )

(define counter 0)

(define (random-color)
  (make-color (random 255) (random 255) (random 255)))

(define (random-state current)
  (world (random-color) (random-color)
 (set! counter (add1 counter

(define (SUPER state)
  (overlay/offset (text (number->string counter) 30 "black")
  160 180
   (overlay (text "SUPER" 105 (world-foreground state))
   (circle 200 "solid" (world-background state)))
   ))


(big-bang (random-state null)
  (on-tick random-state 0.3) ; change the image every 0.3 seconds   
   
  (to-draw SUPER))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Animation-problem

2016-12-04 Thread Daniel Prager
Hi Janiho

This should help get you get going ...

The function big-bang takes minimally:
*  an initial "state of the world",
* a function that  that takes the current world state and evolves it with
every tick of a notional clock, and
* a function that takes the state of the world and draws it.

In this case there's no dependence on the existing state, so the function
random-state ignores what is passed in, but it has the necessary form to
work with big-bang.

Exercise: add a counter to the world state that increments with every tick,
and show this as a number in the top-left corner of the animated image.

Dan


#lang racket

(require 2htdp/universe)
(require 2htdp/image)

(struct world (foreground background))

(define (random-color)
  (make-color (random 255) (random 255) (random 255)))

(define (random-state current)
  (world (random-color) (random-color)))

(define (SUPER state)
  (overlay (text "SUPER" 105 (world-foreground state))
   (circle 200 "solid" (world-background state

(big-bang (random-state null)
  (on-tick random-state 0.3) ; change the image every 0.3 seconds
  (to-draw SUPER))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Animation-problem

2016-12-04 Thread Janiho
Hello!

The animation in this Pet Shop boys music video (LINK: 
https://www.youtube.com/watch?v=lNLkcOqQSBM (very good song btw!))

gave me a inspiration try to make it with the Racket.

I'm very novice using the Racket, so I got to dead-end early.
 

I get this far:

(require 2htdp/universe)
(require 2htdp/image)


(define SUPER (overlay (text "SUPER" 105 (make-color (random 255)
(random 255)
(random 255)))

   (circle 200 "solid" (make-color (random 255)
(random 255)
(random 255)


SUPER

--

This code does one figure. Now the problem is how I can make them in a row and 
changing colors at the same time. I just don't understand how to get different 
figures in racket's memory. 

Any advices, what might be the easiest way to do it? Using 
map/foldl/place-image -commands maybe? 
 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.