HW#4

//FAN LAN
//HW#4 
//September 16, 2019

float y = 20; //for sun movement
float circleX=0;
float xspeed = 10; //for cloud movement


void setup() {
  size(1200, 580);
  //background(255, 208, 126);
  noStroke(); 
  smooth();
}

void draw() {
  drawSky();
  drawSun();
  drawLawn();
  drawMountain();
  drawRiver();
  drawRoad();
  drawCloud();
  drawTree();
}

void drawSky() {
  //color gradient
  noStroke();
  color orange = color(255, 208, 126);
  color yellow = color(252, 252, 215);

  int gradientSteps = 50; //set up pixel step detail, how detailed will the gradient be
  int gradientStripHeight = height/gradientSteps;//how many strips of the same height 
  for (int i = 0; i < gradientSteps; i++) {//for repeat each gradient strip
    float t = map(i, 0, gradientSteps, 0, 2);//map(value, start1, stop1, start2, stop2)- compute how far to start color change
    color interpolatedColor = lerpColor(orange, yellow, t);
    //Syntax  lerpColor(c1, c2, amt)
    //c1  int: interpolate from this color
    //c2  int: interpolate to this color
    //amt  float: between 0.0 and 1.0
    fill(interpolatedColor);     //use the colour and draw boxes 
    rect(0, i*gradientStripHeight, width, height);
  }
}

void drawSun() {
  fill (252, 130, 15);
  ellipse(615, y, 60, 60);
  y++;
  if (y>width) {
    y=width;
  }
}

void drawLawn() {
  fill (131, 252, 194);
  quad(0, 360, 1200, 300, 1200, 580, 0, 680);
  fill (219, 253, 138);
  quad(0, 480, 1200, 500, 1200, 580, 0, 680);
}

void drawMountain() {
  fill (148, 167, 101);
  triangle(0, 360, 350, 108, 450, 338);
  fill (148, 167, 101);
  triangle(770, 321, 900, 128, 1100, 305);
  fill (184, 214, 112);
  triangle(250, 349, 429, 150, 500, 336);
  fill (184, 214, 112);
  triangle(890, 315, 1000, 158, 1200, 300);
}


void drawRiver() {
  //borrow from J David Eisenberg's tutorial on processing.org
  int[] coords = {
    590, 332, 640, 390, 520, 450, 600, 550, 500, 690, 
    650, 690, 690, 550, 610, 450, 700, 390, 660, 328, 
  };

  fill (35, 223, 235);
  noStroke();
  beginShape();
  curveVertex(590, 332); // the first control point
  curveVertex(590, 332); // is also the start point of curve
  curveVertex(640, 390);
  curveVertex(520, 450);
  curveVertex(600, 550);
  curveVertex(500, 690);
  curveVertex(650, 690);
  curveVertex(690, 550);
  curveVertex(610, 450);
  curveVertex(700, 390);
  curveVertex(660, 328); // the last point of curve
  curveVertex(660, 328); // the last control point
  endShape();
  fill(0, 0, 0);
  noStroke();
  for (int i = 0; i < coords.length; i += 2) {
    ellipse(coords[i], coords[i + 1], 0, 0);
  }
}

void drawRoad() {
  fill (245, 245, 245);
  quad(0, 440, 1200, 440, 1200, 500, 0, 480);
}

void drawCloud() {
  fill(255, 255, 255);
  println("Xspeed = ", xspeed);
  ellipse(30+circleX, 75, 70, 70);
  ellipse(30+35+circleX, 75, 90, 90);
  ellipse(30+70+circleX, 75, 70, 70);
  circleX=circleX + xspeed;
  if (circleX+70+30+70/2>width||circleX<0) {
    //turn around
    xspeed=xspeed*-1;
  }
}

void drawTree() {
  // canopy movement - part1
  for (int x=206; x < width/2-100; x+=70) {
    float mx = 40/10;
    float offsetA= random (-mx, mx);
    fill(161, 113, 64);
    rect(x-6, 380, 12, 55);
    fill (99, 117, 54);
    ellipse(x+offsetA, 380, 50, 50);
  }
  // canopy movement - part2
  for (int x=700; x < width-200; x+=70) {
    float mx = 40/10;
    float offsetA= random (-mx, mx);
    fill(161, 113, 64);
    rect(x-6, 380, 12, 55);
    fill (99, 117, 54);
    ellipse(x+offsetA, 380, 50, 50);
  }
}

Comments

Popular posts from this blog

HW#3 - a

FP#1