making the road thing wavy
also separate out the code for bouncing spheres
This commit is contained in:
		
							
								
								
									
										56
									
								
								outrun.rkt
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								outrun.rkt
									
									
									
									
									
								
							@@ -17,10 +17,10 @@
 | 
			
		||||
                            #: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 i-range-start -11)
 | 
			
		||||
  (define i-range-end 11)
 | 
			
		||||
  (define j-range-start -3)
 | 
			
		||||
  (define j-range-end 12)
 | 
			
		||||
  (define (calculate-noise-fn f)
 | 
			
		||||
    (lambda (i j)
 | 
			
		||||
      (scale-number (f (scale-number i i-range-start i-range-end -1 1)
 | 
			
		||||
@@ -36,7 +36,8 @@
 | 
			
		||||
                              [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)))]
 | 
			
		||||
                              (vertex (pos i (* (calculate-noise-simplex i j) 3) 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)])
 | 
			
		||||
@@ -47,7 +48,7 @@
 | 
			
		||||
                  #:back? #t))])
 | 
			
		||||
    (combine mesh)))
 | 
			
		||||
 | 
			
		||||
(define (mesh t)
 | 
			
		||||
(define (spheres t)
 | 
			
		||||
  (define (calculate-noise i j)
 | 
			
		||||
    (scale-number (perlin (scale-number i -10 10 -1 1)
 | 
			
		||||
                          (scale-number j -1 10 -1 1)
 | 
			
		||||
@@ -56,6 +57,23 @@
 | 
			
		||||
                  0 4))
 | 
			
		||||
  (define (calculate-pos i j)
 | 
			
		||||
    (pos i (calculate-noise i j) j))
 | 
			
		||||
  (define spheres
 | 
			
		||||
    (for*/list ([i (in-range -10 10)]
 | 
			
		||||
                [j (in-range -1 10)])
 | 
			
		||||
      (let ([x i]
 | 
			
		||||
            [z j]
 | 
			
		||||
            [y (calculate-noise i j)]
 | 
			
		||||
            [alpha (scale-number
 | 
			
		||||
                    (simplex (scale-number i -10 10 -1 1)
 | 
			
		||||
                             (scale-number j -1 10 -1 1)
 | 
			
		||||
                             (scale-number t 0 2000 -1 1))
 | 
			
		||||
                    -1 1
 | 
			
		||||
                    0.33 1)])
 | 
			
		||||
        (with-color (rgba-hex "ff71ce" alpha)
 | 
			
		||||
          (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)])
 | 
			
		||||
@@ -63,22 +81,8 @@
 | 
			
		||||
              (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)])
 | 
			
		||||
                    (let ([x i]
 | 
			
		||||
                          [z j]
 | 
			
		||||
                          [y (calculate-noise i j)]
 | 
			
		||||
                          [alpha (scale-number
 | 
			
		||||
                                  (simplex (scale-number i -10 10 -1 1)
 | 
			
		||||
                                           (scale-number j -1 10 -1 1)
 | 
			
		||||
                                           (scale-number t 0 2000 -1 1))
 | 
			
		||||
                                  -1 1
 | 
			
		||||
                                  0.33 1)])
 | 
			
		||||
                      (with-color (rgba-hex "ff71ce" alpha)
 | 
			
		||||
                        (sphere (pos x y z) 0.2))))])
 | 
			
		||||
         [lines-frozen (freeze (apply combine lines))])
 | 
			
		||||
    (combine lines-frozen
 | 
			
		||||
             spheres
 | 
			
		||||
             (move (rotate-y lines-frozen 90)
 | 
			
		||||
                   (dir -7 0 5)))))
 | 
			
		||||
 | 
			
		||||
@@ -110,8 +114,10 @@
 | 
			
		||||
                            (camera-direction s)))
 | 
			
		||||
           (make-sunlight (scene-state-dsun s))
 | 
			
		||||
           (mesh t)
 | 
			
		||||
           (road t)
 | 
			
		||||
           (scene t)))
 | 
			
		||||
           (move-y (road t) -1)
 | 
			
		||||
           ;;(spheres t)
 | 
			
		||||
           ;;(scene t)
 | 
			
		||||
           ))
 | 
			
		||||
 | 
			
		||||
(define (on-key s n t k)
 | 
			
		||||
  (case k
 | 
			
		||||
@@ -137,6 +143,6 @@
 | 
			
		||||
            #:on-key on-key
 | 
			
		||||
            #:stop-state? stop-state?
 | 
			
		||||
            #:name "sketch"
 | 
			
		||||
            #:width 800
 | 
			
		||||
            #:height 600)
 | 
			
		||||
            #:width 960
 | 
			
		||||
            #:height 760)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user