initial version of boids is doing something
This commit is contained in:
parent
c58bcaf0d8
commit
c0b9dcc4f7
|
@ -290,16 +290,20 @@
|
||||||
boids))
|
boids))
|
||||||
|
|
||||||
|
|
||||||
;; draw: (listof boid) -> scene
|
;; draw: (listof boid) view -> scene
|
||||||
#;(define (draw boids)
|
(define (draw boids dom)
|
||||||
(for/fold ([scene (place-image (rectangle width height 'solid 'black)
|
(foldl (lambda (boid dom)
|
||||||
320 240
|
(define with-left (update-view-css (view-focus dom (boid-id boid))
|
||||||
(empty-scene width height))])
|
"left"
|
||||||
([b boids])
|
(format "~apx"
|
||||||
(place-image (circle 3 'solid (boid-color b))
|
(vec-x (boid-position boid)))))
|
||||||
(vec-x (boid-position b))
|
(define with-left-and-top (update-view-css with-left
|
||||||
(vec-y (boid-position b))
|
"top"
|
||||||
scene)))
|
(format "~apx"
|
||||||
|
(vec-y (boid-position boid)))))
|
||||||
|
with-left-and-top)
|
||||||
|
dom
|
||||||
|
boids))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,25 +322,26 @@
|
||||||
|
|
||||||
|
|
||||||
(define (new-population)
|
(define (new-population)
|
||||||
(build-list 5 (lambda (i) (make-random-boid))))
|
(build-list 20 (lambda (i) (make-random-boid))))
|
||||||
|
|
||||||
|
|
||||||
;; visualize: -> void
|
;; visualize: -> void
|
||||||
;; Animates a scene of the boids flying around.
|
;; Animates a scene of the boids flying around.
|
||||||
(define (visualize)
|
(define (visualize)
|
||||||
(define population (new-population))
|
(define population (new-population))
|
||||||
(big-bang population
|
|
||||||
(initial-view
|
(define view-with-boids (view-append-child
|
||||||
(view-append-child
|
|
||||||
(view-focus (->view index.html) "playground")
|
(view-focus (->view index.html) "playground")
|
||||||
(xexp->dom `(div ,@(map (lambda (b)
|
(xexp->dom `(div ,@(map (lambda (b)
|
||||||
`(div (@ (id ,(boid-id b))
|
`(div (@ (id ,(boid-id b))
|
||||||
(class "boid"))
|
(class "boid"))
|
||||||
nbsp))
|
nbsp))
|
||||||
population)))))
|
population)))))
|
||||||
(on-tick tick)
|
|
||||||
#;(to-draw draw)
|
(big-bang population
|
||||||
))
|
(initial-view view-with-boids)
|
||||||
|
(on-tick tick 1/20)
|
||||||
|
(to-draw draw)))
|
||||||
|
|
||||||
|
|
||||||
(visualize)
|
(visualize)
|
|
@ -2,7 +2,7 @@
|
||||||
<head><title>Boid</title>
|
<head><title>Boid</title>
|
||||||
<style>
|
<style>
|
||||||
.boid {
|
.boid {
|
||||||
display: absolute;
|
position: absolute;
|
||||||
width: 10px;
|
width: 10px;
|
||||||
height: 10px;
|
height: 10px;
|
||||||
background: #333;
|
background: #333;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user