add a road effect

This commit is contained in:
Dan Frumin 2019-12-28 16:55:17 +01:00
parent eba4fd5d5e
commit 3361c239d9
1 changed files with 49 additions and 12 deletions

View File

@ -16,7 +16,46 @@
#:specular 0.3 #:specular 0.3
#:roughness 0.5)) #:roughness 0.5))
(define (road t)
(define i-range-start -10)
(define i-range-end 10)
(define j-range-start -2)
(define j-range-end 10)
(define (calculate-noise-fn f)
(lambda (i j)
(scale-number (f (scale-number i i-range-start i-range-end -1 1)
(scale-number j j-range-start j-range-end -1 1)
(scale-number t 0 9000 -1 1))
-1 1
0 1)))
(define calculate-noise (calculate-noise-fn perlin))
(define calculate-noise-simplex (calculate-noise-fn simplex))
(let* ([rgba-noise (lambda (i j)
(let* ([r (calculate-noise i j)]
[g (calculate-noise-simplex i j)]
[b (calculate-noise-simplex r g)])
(rgba r g b 1)))]
[vertex-with-noise (lambda (i j)
(vertex (pos i -1 j) #:color (rgba-noise i j)))]
[mesh
(for*/list ([i (in-range i-range-start i-range-end)]
[j (in-range j-range-start j-range-end)])
(quad (vertex-with-noise (add1 i) (add1 j))
(vertex-with-noise i (add1 j))
(vertex-with-noise i j)
(vertex-with-noise (add1 i) j)
#:back? #t))])
(combine mesh)))
(define (mesh t) (define (mesh t)
(define (calculate-noise i j)
(scale-number (perlin (scale-number i -10 10 -1 1)
(scale-number j -1 10 -1 1)
(scale-number t 0 3000 -1 1))
-1 1
0 4))
(define (calculate-pos i j)
(pos i (calculate-noise i j) j))
(let* ([lines (let* ([lines
(for*/list ([i (in-range -10 10)] (for*/list ([i (in-range -10 10)]
[j (in-range 0 10)]) [j (in-range 0 10)])
@ -29,19 +68,15 @@
[j (in-range -1 10)]) [j (in-range -1 10)])
(let ([x i] (let ([x i]
[z j] [z j]
[y (scale-number [y (calculate-noise i j)]
(perlin (scale-number i -10 10 -1 1)
(scale-number j -1 10 -1 1)
(scale-number t 0 2000 -1 1))
-1 1
0 4)]
[alpha (scale-number [alpha (scale-number
(simplex (scale-number i -10 10 -1 1) (simplex (scale-number i -10 10 -1 1)
(scale-number j -1 10 -1 1) (scale-number j -1 10 -1 1)
(scale-number t 0 2000 -1 1)) (scale-number t 0 2000 -1 1))
-1 1 -1 1
0.1 0.8)]) 0.33 1)])
(with-color (rgba-hex "ff71ce" alpha) (sphere (pos x y z) 0.2))))]) (with-color (rgba-hex "ff71ce" alpha)
(sphere (pos x y z) 0.2))))])
(combine lines-frozen (combine lines-frozen
spheres spheres
(move (rotate-y lines-frozen 90) (move (rotate-y lines-frozen 90)
@ -52,9 +87,10 @@
(bend p (bend p
(scale-number (perlin x y z) -1 1 -180 180))) (scale-number (perlin x y z) -1 1 -180 180)))
(define (scene t) (define (scene t)
(rotate-x (move-y (rotate-x
(bend+ my-pipe (/ t 1000) (/ t 1200) 69) (bend+ my-pipe (/ t 3000) (/ t 4000) 69)
90)) 90)
2))
(define (make-sunlight dsun) (define (make-sunlight dsun)
(sunlight (sunlight
@ -74,7 +110,8 @@
(camera-direction s))) (camera-direction s)))
(make-sunlight (scene-state-dsun s)) (make-sunlight (scene-state-dsun s))
(mesh t) (mesh t)
(move-y (scene t) 2))) (road t)
(scene t)))
(define (on-key s n t k) (define (on-key s n t k)
(case k (case k