Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 2.38 KB | None | 0 0
  1. ;; Width of the final picture
  2. (define WIDTH 512)
  3. ;; Height of the final picture
  4. (define HEIGHT 512)
  5. ;; Number of grid cells
  6. (define SCALE 64)
  7. ;; The width of the grid
  8. (define GWIDTH (/ WIDTH SCALE))
  9. ;; The height of the grid
  10. (define GHEIGHT (/ HEIGHT SCALE))
  11.  
  12. ;; Defines a 2D Vector
  13. ;; x - The x-value of the vector
  14. ;; y - The y-value of the vector
  15. (define-struct vector2d (x y))
  16.  
  17. ; create-gradients: number -> (list of vector)
  18. ; Ruft die local Funktion "create" auf
  19. ; Bsp: (create-gradients 2) ergibt:
  20. ;(list(make-vector2d #i-0.9916790270710302 #i0.5249526803021658)(make-vector2d #i0.5993336254015262 #i0.8165964304676605))
  21. (define (create-gradients n)
  22.  
  23.   ;create: list number -> (listof vector)
  24.   ;Erzeugt eine Liste, mit der Länge des übergebenen Parameter, von zufälligen Gradienten
  25.   ;Bsp: (create '() 2) ergibt (list (make-vector2d #i0.5557147071202895 #i0.16166538194593366) (make-vector2d #i-0.8928569845064996 #i0.6875843026669924))
  26.   (local
  27.     ((define (create lst n)
  28.      (cond
  29.        [(= n (length lst)) lst]
  30.        [else (create (append lst (cons (make-vector2d (cos(* 2 pi (random))) (sin (* 2 pi (random)))) '()))n)]
  31.        )))
  32.     (create '() n)
  33.     ))
  34.  
  35.  
  36. ;; fade: number -> number
  37. ;; Uses a Sigmoid function to smooth numbers betwenn 0 to 1
  38. ;; Example: (fade 1) -> 1
  39. (define (fade t)
  40.   (+ (- (* 6 t t t t t) (* 15 t t t t)) (* 10 t t t))
  41.   )
  42.  
  43. (check-expect (fade 1) 1)
  44. (check-within (fade 0.5) 0.5 0.001)
  45. (check-within (fade 0.3) 0.16308 0.001)
  46. (check-within (fade 0.8) 0.94208 0.001)
  47.  
  48. ;; Globally store the list of gradients
  49. (define gradients (create-gradients (* (+ 1 GWIDTH) (+ 1 GHEIGHT))))
  50.  
  51. ; linear-interpolation: number number number -> number
  52. ; Führt die lineare Interpolation zwischen zwei Werten x,y mit einem Gewicht w durch.
  53. ; Bsp: (linear-interpolation 3 4 5) ergibt 8
  54. (define (linear-interpolation x y w)
  55.   (+ (* ( - 1 w) x)(* w y))    
  56. )
  57.  
  58. (check-expect (linear-interpolation 3 4 5) 8)
  59. (check-expect (linear-interpolation 7 8 9) 16)
  60.  
  61. ;dot-grid-gradient: number number number number -> number
  62. ;Berechnet das Skalarprodukt von zwei Vektoren
  63. ;Bsp: (dot-grid-gradient 5 8 40 50) ergibt 77
  64. (define (dot-grid-gradient ix iy x y)
  65.   (+ (* (- x ix)) (* (- y iy) ))
  66. )
  67.  
  68.  
  69. (define (perlin-noise x y)
  70.   1
  71.   )
  72.  
  73. (define (create-land width height)
  74.   1
  75.   )
  76.  
  77. ;(save-image (color-list->bitmap (create-land WIDTH HEIGHT) WIDTH HEIGHT) "land.png")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement