translating entity references
This commit is contained in:
parent
1f5e848fa0
commit
0d0d38496e
|
@ -1,17 +1,21 @@
|
||||||
#lang planet dyoo/whalesong
|
#lang planet dyoo/whalesong
|
||||||
|
|
||||||
(require (planet dyoo/whalesong/js)
|
(require (planet dyoo/whalesong/js)
|
||||||
(planet dyoo/whalesong/web-world))
|
(planet dyoo/whalesong/image)
|
||||||
|
(planet dyoo/whalesong/web-world)
|
||||||
|
(planet dyoo/whalesong/resource))
|
||||||
|
|
||||||
|
|
||||||
|
(define-resource index.html)
|
||||||
|
|
||||||
;; Boid flocking behavior.
|
;; Boid flocking behavior.
|
||||||
;;
|
;;
|
||||||
;; http://www.vergenet.net/~conrad/boids/pseudocode.html
|
;; http://www.vergenet.net/~conrad/boids/pseudocode.html
|
||||||
;;
|
;;
|
||||||
;;
|
;;
|
||||||
|
|
||||||
;; A Boid has a velocity and position vector, as well as a color
|
;; A Boid has an identity, a velocity and position vector, as well as a color
|
||||||
(define-struct boid (velocity position color))
|
(define-struct boid (id velocity position color))
|
||||||
|
|
||||||
|
|
||||||
(define width (viewport-width))
|
(define width (viewport-width))
|
||||||
|
@ -209,7 +213,8 @@
|
||||||
[new-position
|
[new-position
|
||||||
(vec+ (boid-position b)
|
(vec+ (boid-position b)
|
||||||
(boid-velocity b))])
|
(boid-velocity b))])
|
||||||
(make-boid new-velocity
|
(make-boid (boid-id b)
|
||||||
|
new-velocity
|
||||||
new-position
|
new-position
|
||||||
(boid-color b)))))
|
(boid-color b)))))
|
||||||
|
|
||||||
|
@ -236,11 +241,12 @@
|
||||||
|
|
||||||
;; (: tick ((Listof boid) dom -> (Listof boid)))
|
;; (: tick ((Listof boid) dom -> (Listof boid)))
|
||||||
(define (tick boids dom)
|
(define (tick boids dom)
|
||||||
(for/list ([b boids])
|
(map (lambda (b)
|
||||||
(let ([mass-data (collect-mass-data (boid-neighborhood b boids 40))])
|
(let ([mass-data (collect-mass-data (boid-neighborhood b boids 40))])
|
||||||
(cap-boid-velocity
|
(cap-boid-velocity
|
||||||
(move-boid b boids mass-data)
|
(move-boid b boids mass-data)
|
||||||
15))))
|
15)))
|
||||||
|
boids))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,8 +259,9 @@
|
||||||
|
|
||||||
|
|
||||||
(define (cap-boid-velocity b mag)
|
(define (cap-boid-velocity b mag)
|
||||||
(make-boid (vec-cap (boid-vel b) mag)
|
(make-boid (boid-id b)
|
||||||
(boid-pos b)
|
(vec-cap (boid-velocity b) mag)
|
||||||
|
(boid-position b)
|
||||||
(boid-color b)))
|
(boid-color b)))
|
||||||
|
|
||||||
|
|
||||||
|
@ -268,15 +275,17 @@
|
||||||
|
|
||||||
(define (slow-down-boids boids)
|
(define (slow-down-boids boids)
|
||||||
(map (lambda (b)
|
(map (lambda (b)
|
||||||
(make-boid (vec-scale (boid-vel b) 0.9)
|
(make-boid (boid-id b)
|
||||||
(boid-pos b)
|
(vec-scale (boid-velocity b) 0.9)
|
||||||
|
(boid-position b)
|
||||||
(boid-color b)))
|
(boid-color b)))
|
||||||
boids))
|
boids))
|
||||||
|
|
||||||
(define (speed-up-boids boids)
|
(define (speed-up-boids boids)
|
||||||
(map (lambda (b)
|
(map (lambda (b)
|
||||||
(make-boid (vec-scale (boid-vel b) 1.1)
|
(make-boid (boid-id b)
|
||||||
(boid-pos b)
|
(vec-scale (boid-velocity b) 1.1)
|
||||||
|
(boid-position b)
|
||||||
(boid-color b)))
|
(boid-color b)))
|
||||||
boids))
|
boids))
|
||||||
|
|
||||||
|
@ -298,7 +307,8 @@
|
||||||
;; Makes a random boid that starts near the upper left corner,
|
;; Makes a random boid that starts near the upper left corner,
|
||||||
;; drifting downward.
|
;; drifting downward.
|
||||||
(define (make-random-boid)
|
(define (make-random-boid)
|
||||||
(make-boid (make-vec (random 10)
|
(make-boid (fresh-id)
|
||||||
|
(make-vec (random 10)
|
||||||
(random 10))
|
(random 10))
|
||||||
(make-vec (+ 20 (random 600))
|
(make-vec (+ 20 (random 600))
|
||||||
(+ 20 (random 300)))
|
(+ 20 (random 300)))
|
||||||
|
@ -314,7 +324,16 @@
|
||||||
;; visualize: -> void
|
;; visualize: -> void
|
||||||
;; Animates a scene of the boids flying around.
|
;; Animates a scene of the boids flying around.
|
||||||
(define (visualize)
|
(define (visualize)
|
||||||
(big-bang (new-population)
|
(define population (new-population))
|
||||||
|
(big-bang population
|
||||||
|
(initial-view
|
||||||
|
(view-append-child
|
||||||
|
(view-focus (->view index.html) "playground")
|
||||||
|
(xexp->dom `(div ,@(map (lambda (b)
|
||||||
|
`(div (@ (id ,(boid-id b))
|
||||||
|
(class "boid"))
|
||||||
|
nbsp))
|
||||||
|
population)))))
|
||||||
(on-tick tick)
|
(on-tick tick)
|
||||||
#;(to-draw draw)
|
#;(to-draw draw)
|
||||||
))
|
))
|
||||||
|
|
19
web-world/examples/boid/index.html
Normal file
19
web-world/examples/boid/index.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<html>
|
||||||
|
<head><title>Boid</title>
|
||||||
|
<style>
|
||||||
|
.boid {
|
||||||
|
display: absolute;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
background: #333;
|
||||||
|
-moz-border-radius: 40px;
|
||||||
|
-webkit-border-radius: 40px;
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="playground">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1333,6 +1333,9 @@
|
||||||
if (isString(x)) {
|
if (isString(x)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (isSymbol(x)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (isList(x) && !(isEmpty(x))) {
|
if (isList(x) && !(isEmpty(x))) {
|
||||||
if (isSymbol(x.first)) {
|
if (isSymbol(x.first)) {
|
||||||
children = x.rest;
|
children = x.rest;
|
||||||
|
@ -1396,6 +1399,9 @@
|
||||||
if (isString(x)) {
|
if (isString(x)) {
|
||||||
return document.createTextNode(x);
|
return document.createTextNode(x);
|
||||||
}
|
}
|
||||||
|
if (isSymbol(x)) {
|
||||||
|
return $("<div>&" + x.val + ";</div>").get(0).firstChild;
|
||||||
|
}
|
||||||
if (isList(x) && !(isEmpty(x))) {
|
if (isList(x) && !(isEmpty(x))) {
|
||||||
if (isSymbol(x.first)) {
|
if (isSymbol(x.first)) {
|
||||||
name = x.first.val;
|
name = x.first.val;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user