HW#8
//FAN LAN
//HW#8 revised
//Oct.8, 2019
//for cloud movement
float circleX=0;
float xspeed = 10;
void setup() {
size(600, 600);
//background(255, 208, 126);
noStroke();
smooth();
}
void draw() {
drawSky();
drawLandform();
drawTrees();
drawSun();
drawClouds();
}
void drawSky() {
color skycolor = color(13, 238, 252); //use the colour yellow
fill(skycolor);
rect(0, 0, width, height/2);
}
void drawLandform() {
color landcolor = color(252, 252, 215);
fill(landcolor);
rect(height/2, 0, width, height/2);
}
void drawSun() {
fill (252, 130, 15);
int SunRadius=40;
ellipse(width/2, height/3, SunRadius, SunRadius);
}
void drawClouds() {
color white= color(255, 255, 255);
fill(white); //use the colour and draw clouds
int a=70; //radius of first ellipse
int b=90;//radius of second ellipse
int y=75;
ellipse(circleX+a/2, y, a, a);
ellipse(a+circleX, y, b, b);
ellipse(a+a/2+circleX, y, a, a);
circleX=circleX + xspeed;
if (circleX+a+a/2>width||circleX<0) {
xspeed=xspeed*-1; //turn around
}
}
void drawTrees() {
//draw trunk
color trunkcolor = color(161, 113, 64);
fill(trunkcolor);
rectMode(RADIUS);
int trunk_y=320;
int trunkWeight=6;
int trunkHeight=35;
for (int x=50; x < width-50; x+=70) {
TreeTrunk treeTrunk = new TreeTrunk(x, trunk_y, trunkWeight, trunkHeight);
treeTrunk.drawtrunk();
}
//draw canopy
color canopycolor = color(99, 117, 54);
fill(canopycolor);
int canopyRadius=50; //canopy size
int canopy_y=300;
for (int x=50; x < width-50; x+=70) {
TreeCanopy treeCanopy = new TreeCanopy(x, canopy_y, canopyRadius, canopyRadius);
treeCanopy.drawcanopy();
// ellipse(x, y, CanopyRadius, CanopyRadius);
}
}
class TreeTrunk {
//fields global varaibles
int trunkheight;
int trunkwidth;
int x;
int y;
//scope
//constructor = special function
TreeTrunk(int tempx, int tempy, int temptrunkwidth, int temptrunkheight) {
//local variables
trunkwidth=temptrunkwidth;
trunkheight = temptrunkheight;
x=tempx;
y=tempy;
}
void drawtrunk() {
noStroke();
fill(50, 24, 0);
rect(x, y, trunkwidth, trunkheight);
}
}
class TreeCanopy {
float canopy_radius;
float canopy_radius2;
float x;
float y;
TreeCanopy(float tempx, float tempy, float tempcanopy_radius, float tempcanopy_radius2) {
x=tempx;
y=tempy;
canopy_radius = tempcanopy_radius;
canopy_radius2 = tempcanopy_radius2;
}
void drawcanopy() {
noStroke();
fill(60, 180, 120);
ellipse(x, y, canopy_radius, canopy_radius2);
}
}
Comments
Post a Comment