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
// require https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.js
console.log("hello, grass");
function setup() {
console.log("setup, grass");
createCanvas(windowWidth, windowHeight);
noStroke();
fill(255, 255, 255);
noLoop();
}
function draw() {
console.log("draw, grass");
background(40, 40, 40);
fill(220, 220, 220);
rect(0, height * 0.5, width, height * 0.5);
stroke(220, 220, 220);
drawGrass(0, height * 0.5 - 100, width, 100);
//stroke(240, 240, 240);
drawGrass(0, height * 0.5 - 100, width, 100);
//drawGrass(0, height * 0.5 - 100, width, 100);
}
function drawGrass(left, top, width, height) {
// loop from the left to the right, one pixel per step
for (let x = left; x < left + width; x++) {
// x and y are the base of the blade of grass
const y = top + height;
// height of the grass
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
⌥⌘j Open Console | ⌘s/ctrl-s Update Preview |