Advertisement
Guest User

Untitled

a guest
Mar 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.82 KB | None | 0 0
  1. (define (aimant)
  2.   (local [
  3.           ;(define rand_color (make-color (random 256) (random 256) (random 256)))
  4.           (define WIDTH 800)
  5.           (define HEIGHT 800)
  6.           (define MAGNET_RADIUS 100)
  7.           (define BALL_PARTICLE_RADIUS 10)
  8.           (define FOND (underlay(rectangle WIDTH HEIGHT 'solid "yellow")
  9.                                 (circle MAGNET_RADIUS 'solid "red")))
  10.           (define-struct bille(x y dx dy color)) ;particules de billes
  11.          
  12.           ;(define BILLE (circle BALL_PARTICLE_RADIUS 'solid (make-color (random 256) (random 256) (random 256))))
  13.           (define (random-bille)
  14.             (make-bille 0 400 (+ 5 (random 6)) (- (random 11)) (make-color (random 256) (random 256) (random 256)) ))
  15.          
  16.           ;le monde est une liste de billes
  17.           (define INIT
  18.             (build-list 400 (lambda (i) (random-bille))))
  19.        
  20.           (define (suivant L) ;monde -> monde
  21.             (if (empty? L)
  22.                 L
  23.                 (local [(match-define (bille x y dx dy color) (first L))]
  24.                   (cond ((or (> x WIDTH) (> y HEIGHT))
  25.                          (cons (random-bille) (suivant (rest L))))
  26.                         ((< (+ (sqr (- x 400)) (sqr (- y 400))) 10000)
  27.                          (suivant (rest L)))
  28.                         (else (cons (make-bille (+ x dx) (+ y dy) dx (+ dy #i0.3) color) (suivant(rest L))))))))
  29.           (define (dessiner L)
  30.             (if (empty? L)
  31.                 FOND
  32.                 (local [(match-define (bille x y dx dy color) (first L))
  33.                         (define BILLE2 (circle BALL_PARTICLE_RADIUS 'solid color))]
  34.                   (place-image BILLE2 x y (dessiner (rest L))))))]
  35.     (big-bang INIT
  36.               (on-tick suivant 1/20)
  37.               (on-draw dessiner)
  38.               )))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement