-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmanual-noise.scrbl
executable file
·84 lines (64 loc) · 2.67 KB
/
manual-noise.scrbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#lang scribble/manual
@(require scribble/eval
(for-label racket
images/flomap
racket/flonum))
@title{noise: Perlin/Simplex noise generators}
@author{@author+email["John-Paul Verkamp" "[email protected]"]}
This package provides Racket versions of the
@hyperlink["https://en.wikipedia.org/wiki/Perlin_noise"]{Perlin} and
@hyperlink["https://en.wikipedia.org/wiki/Simplex_noise"]{Simplex} noise generators.
@bold{Development} Development of this library is hosted by @hyperlink["http://github.com"]{GitHub} at the following project page:
@url{https://github.com/jpverkamp/noise/}
@section{Installation}
@commandline{raco pkg install noise}
@section{Functions}
@defproc[#:link-target? #f (perlin [x real?] [y real? 0.0] [z real? 0.0]) real?]{
Calculates the 1D, 2D, or 3D Perlin noise value at the given point.
}
@defproc[#:link-target? #f (simplex? [x real?] [y real? 0.0] [z real? 0.0]) real?]{
Calculates the 1D, 2D, or 3D Simplex noise value at the given point.
}
@section{Examples}
@interaction[
(require images/flomap racket/flonum noise)
(define (clamp min max n)
(/ (- n min) (- max min)))
(define (build-perlin-image w h #:scale [scale 1.0])
(flomap->bitmap
(build-flomap*
3 w h
(lambda (x y)
(define g (clamp -1.0 1.0 (perlin (* scale (/ x w)) (* scale (/ y h)))))
(vector g g g)))))
(build-perlin-image 256 256 #:scale 10.0)
(define (build-simplex-image w h #:scale [scale 1.0])
(flomap->bitmap
(build-flomap*
3 w h
(lambda (x y)
(define g (clamp -1.0 1.0 (simplex (* scale (/ x w)) (* scale (/ y h)))))
(vector g g g)))))
(build-simplex-image 256 256 #:scale 10.0)
(define (build-colored-simplex-image w h #:scale [scale 1.0])
(flomap->bitmap
(build-flomap*
3 w h
(lambda (x y)
(vector
(clamp -1.0 1.0 (simplex (* scale (/ x w)) (* scale (/ y h)) -1.0))
(clamp -1.0 1.0 (simplex (* scale (/ x w)) (* scale (/ y h)) 0.0))
(clamp -1.0 1.0 (simplex (* scale (/ x w)) (* scale (/ y h)) 1.0)))))))
(build-colored-simplex-image 256 256 #:scale 10.0)
]
@section{License}
This program is free software: you can redistribute it and/or modify it
under the terms of the
@hyperlink["http://www.gnu.org/licenses/lgpl.html"]{GNU Lesser General
Public License} as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License and GNU Lesser General Public License for more
details.