|
5 | 5 | var walker;
|
6 | 6 |
|
7 | 7 | 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 |
11 | 11 | }
|
12 | 12 |
|
13 | 13 | function draw() {
|
14 |
| - walker.walk(); |
| 14 | + walker.step(); |
15 | 15 | walker.display();
|
16 | 16 | }
|
17 | 17 |
|
18 | 18 | 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 | + |
21 | 24 |
|
22 | 25 | 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 |
27 | 30 | };
|
28 | 31 |
|
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 |
33 | 37 | };
|
34 | 38 | }
|
| 39 | + |
0 commit comments