@@ -12,31 +12,41 @@ function setup() {
12
12
createCanvas ( 640 , 360 ) ;
13
13
}
14
14
15
+ function drawNoise ( x , y , w , h ) {
16
+ for ( let yp = y ; yp < y + h ; yp ++ ) {
17
+ let yindex = yp * width ;
18
+ for ( let xp = x ; xp < x + w ; xp ++ ) {
19
+ let noiseVal =
20
+ noise ( ( mouseX + xp ) * noiseScale , ( mouseY + yp ) * noiseScale ) * 255 ;
21
+
22
+ let xindex = xp ;
23
+ let index = 4 * ( yindex + xindex ) ;
24
+ pixels [ index ] = noiseVal ;
25
+ pixels [ index + 1 ] = noiseVal ;
26
+ pixels [ index + 2 ] = noiseVal ;
27
+ pixels [ index + 3 ] = 255 ;
28
+ }
29
+ }
30
+ }
31
+
15
32
function draw ( ) {
16
33
background ( 0 ) ;
34
+
35
+ loadPixels ( ) ;
36
+
17
37
// Draw the left half of image
18
- for ( let y = 0 ; y < height - 30 ; y ++ ) {
19
- for ( let x = 0 ; x < width / 2 ; x ++ ) {
20
- // noiseDetail of the pixels octave count and falloff value
21
- noiseDetail ( 2 , 0.2 ) ;
22
- noiseVal = noise ( ( mouseX + x ) * noiseScale , ( mouseY + y ) * noiseScale ) ;
23
- stroke ( noiseVal * 255 ) ;
24
- point ( x , y ) ;
25
- }
26
- }
38
+ noiseDetail ( 2 , 0.2 ) ;
39
+ drawNoise ( 0 , 0 , width / 2 , height - 30 ) ;
40
+
27
41
// Draw the right half of image
28
- for ( let y = 0 ; y < height - 30 ; y ++ ) {
29
- for ( let x = width / 2 ; x < width ; x ++ ) {
30
- // noiseDetail of the pixels octave count and falloff value
31
- noiseDetail ( 5 , 0.5 ) ;
32
- noiseVal = noise ( ( mouseX + x ) * noiseScale , ( mouseY + y ) * noiseScale ) ;
33
- stroke ( noiseVal * 255 ) ;
34
- point ( x , y ) ;
35
- }
36
- }
42
+ noiseDetail ( 5 , 0.5 ) ;
43
+ drawNoise ( width / 2 , 0 , width / 2 , height - 30 ) ;
44
+
45
+ updatePixels ( ) ;
46
+
37
47
//Show the details of two partitions
38
48
textSize ( 18 ) ;
39
49
fill ( 255 , 255 , 255 ) ;
40
- text ( ' Noise2D with 2 octaves and 0.2 falloff' , 10 , 350 ) ;
41
- text ( ' Noise2D with 5 octaves and 0.5 falloff' , 330 , 350 ) ;
50
+ text ( " Noise2D with 2 octaves and 0.2 falloff" , 10 , 350 ) ;
51
+ text ( " Noise2D with 5 octaves and 0.5 falloff" , 330 , 350 ) ;
42
52
}
0 commit comments