Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Commit fe23d71

Browse files
committed
NOC_I_05_NoiseWalk : Screenshot added,title added,code updated,comments added
1 parent 2095401 commit fe23d71

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<head>
2-
<script language="javascript" type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
2+
<script language="javascript" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
33
<script language="javascript" type="text/javascript" src="noise.js"></script>
4-
<script language="javascript" type="text/javascript" src="sketch.js"></script>
4+
<script language="javascript" type="text/javascript" src="sketch.js"></script>
5+
<title>Noise Walk</title>
56
</head>
67

78
<body>
8-
</body>
9+
</body>
84.6 KB
Loading

chp00_introduction/NOC_I_05_NoiseWalk/sketch.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,35 @@
55
var walker;
66

77
function setup() {
8-
createCanvas(640,360);
9-
walker = new Walker();
10-
background(127);
8+
createCanvas(640,360); //creating canvas of size 640 x 360
9+
walker = new Walker(); //creating an instance/object of class Walker
10+
background(127); // creating a grey background for canvas
1111
}
1212

1313
function draw() {
14-
walker.walk();
14+
walker.step();
1515
walker.display();
1616
}
1717

1818
function Walker() {
19-
this.position = createVector(width/2,height/2);
20-
this.noff = createVector(random(1000),random(1000));
19+
this.tx = 0; //perlin noise x-offset
20+
this.ty = 10000; //perlin noise y-offset
21+
this.x = width/2; //x position for drawing ellipse initialized to center of canvas
22+
this.y = height/2; //x position for drawing ellipse initialized to center of canvas
23+
2124

2225
this.display = function() {
23-
strokeWeight(2);
24-
fill(51);
25-
stroke(0);
26-
ellipse(this.position.x, this.position.y, 48, 48);
26+
strokeWeight(2); //stroke thickness of 2
27+
fill(51); //adding a fill of dark grey
28+
stroke(0); //black stroke
29+
ellipse(this.x, this.y, 48, 48); //ellipse of width 48x48 drawn a pos this.x,this.y
2730
};
2831

29-
this.walk = function() {
30-
this.position.x = map(noise(this.noff.x),0,1,0,width);
31-
this.position.y = map(noise(this.noff.y),0,1,0,height);
32-
this.noff.add(0.01,0.01,0);
32+
this.step = function() {
33+
this.x = map(noise(this.tx),0,1,0,width); //noise returns a value between 0 & 1 -> Mapping it to (0,canvas width)
34+
this.y = map(noise(this.ty),0,1,0,height); //Mapping perlin noise to (0,canvas.height)
35+
this.tx += 0.01; //incrementing perlin noise x offset
36+
this.ty += 0.01; //incrementing perlin noise y offset
3337
};
3438
}
39+

0 commit comments

Comments
 (0)