making the road thing wavy

also separate out the code for bouncing spheres
This commit is contained in:
Dan Frumin 2019-12-28 17:09:20 +01:00
parent 3361c239d9
commit b570b75cb7
1 changed files with 31 additions and 25 deletions

View File

@ -17,10 +17,10 @@
#:roughness 0.5)) #:roughness 0.5))
(define (road t) (define (road t)
(define i-range-start -10) (define i-range-start -11)
(define i-range-end 10) (define i-range-end 11)
(define j-range-start -2) (define j-range-start -3)
(define j-range-end 10) (define j-range-end 12)
(define (calculate-noise-fn f) (define (calculate-noise-fn f)
(lambda (i j) (lambda (i j)
(scale-number (f (scale-number i i-range-start i-range-end -1 1) (scale-number (f (scale-number i i-range-start i-range-end -1 1)
@ -36,7 +36,8 @@
[b (calculate-noise-simplex r g)]) [b (calculate-noise-simplex r g)])
(rgba r g b 1)))] (rgba r g b 1)))]
[vertex-with-noise (lambda (i j) [vertex-with-noise (lambda (i j)
(vertex (pos i -1 j) #:color (rgba-noise i j)))] (vertex (pos i (* (calculate-noise-simplex i j) 3) j)
#:color (rgba-noise i j)))]
[mesh [mesh
(for*/list ([i (in-range i-range-start i-range-end)] (for*/list ([i (in-range i-range-start i-range-end)]
[j (in-range j-range-start j-range-end)]) [j (in-range j-range-start j-range-end)])
@ -47,7 +48,7 @@
#:back? #t))]) #:back? #t))])
(combine mesh))) (combine mesh)))
(define (mesh t) (define (spheres t)
(define (calculate-noise i j) (define (calculate-noise i j)
(scale-number (perlin (scale-number i -10 10 -1 1) (scale-number (perlin (scale-number i -10 10 -1 1)
(scale-number j -1 10 -1 1) (scale-number j -1 10 -1 1)
@ -56,15 +57,8 @@
0 4)) 0 4))
(define (calculate-pos i j) (define (calculate-pos i j)
(pos i (calculate-noise i j) j)) (pos i (calculate-noise i j) j))
(let* ([lines (define spheres
(for*/list ([i (in-range -10 10)] (for*/list ([i (in-range -10 10)]
[j (in-range 0 10)])
(with-color (rgba-hex "05ffa1")
(move (cylinder (pos (- 0.1) (- 0.1) -5)
(pos 0.1 0.1 10))
(dir i 0 j))))]
[lines-frozen (freeze (apply combine lines))]
[spheres (for*/list ([i (in-range -10 10)]
[j (in-range -1 10)]) [j (in-range -1 10)])
(let ([x i] (let ([x i]
[z j] [z j]
@ -76,9 +70,19 @@
-1 1 -1 1
0.33 1)]) 0.33 1)])
(with-color (rgba-hex "ff71ce" alpha) (with-color (rgba-hex "ff71ce" alpha)
(sphere (pos x y z) 0.2))))]) (sphere (pos x y z) 0.2)))))
(combine spheres))
(define (mesh t)
(let* ([lines
(for*/list ([i (in-range -10 10)]
[j (in-range 0 10)])
(with-color (rgba-hex "05ffa1")
(move (cylinder (pos (- 0.1) (- 0.1) -5)
(pos 0.1 0.1 10))
(dir i 0 j))))]
[lines-frozen (freeze (apply combine lines))])
(combine lines-frozen (combine lines-frozen
spheres
(move (rotate-y lines-frozen 90) (move (rotate-y lines-frozen 90)
(dir -7 0 5))))) (dir -7 0 5)))))
@ -110,8 +114,10 @@
(camera-direction s))) (camera-direction s)))
(make-sunlight (scene-state-dsun s)) (make-sunlight (scene-state-dsun s))
(mesh t) (mesh t)
(road t) (move-y (road t) -1)
(scene t))) ;;(spheres t)
;;(scene t)
))
(define (on-key s n t k) (define (on-key s n t k)
(case k (case k
@ -137,6 +143,6 @@
#:on-key on-key #:on-key on-key
#:stop-state? stop-state? #:stop-state? stop-state?
#:name "sketch" #:name "sketch"
#:width 800 #:width 960
#:height 600) #:height 760)