xxxxxxxxxx
67
function setup() {
w = 400;
h = 400;
totalRice = 800;
initialRiceHeight = 150;
HeightInc = 15;
riceHeight = initialRiceHeight;
createCanvas(w, h);
background(50,230,255);
}
function draw() {
startT = millis()
if(riceHeight == initialRiceHeight) {
while(millis()<startT+1000);
}
else{
while(millis()<startT+300);
}
clear();
background(50,230,255);
// startT = millis()
if (riceHeight>h) {
background(255, 176, 59);
noStroke();
arc(200, 200, 300, 300, 0, 0.35*PI);
arc(200, 200, 300, 300, 0.65*PI, PI);
rect(125, 200, 150, 140);
stroke(206,206,206);
riceHeight = initialRiceHeight;
}
else {
rice = new Rice(riceHeight);
rice.display();
riceHeight+=HeightInc;
}
}
class Rice{
constructor(currHeight) {
this.w = w;
this.h = currHeight;
this.width = currHeight*currHeight/totalRice/7;
this.height = currHeight*currHeight/totalRice/17;
strokeWeight(this.h*this.h/h/100);
stroke(206,206,206);
fill(255)
}
display() {
var colNum = 1.5*this.w/this.width+1;
for (var i = 0; i <= colNum; i++){
for (var j = 0; j <= totalRice/colNum; j++){
this.OneRice(i*this.width, h-(j*this.height));
}
}
}
OneRice(x, y){
push();
translate(x+random(0,this.width),y+random(0,this.height));
rotate(random(0, PI));
ellipse(0, 0, this.width, this.height);
pop();
}
}