HW#3-b


Fan Lan, 3rd-MLA, HW#3-b, Sep. 11,19


float y = 20; //for sun movement
float Xspeed = 10; //for cloud movement

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

void draw() {

  //draw sky 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
    //this value will plug into lerpColor which does the colour interpolation for you
    color interpolatedColor = lerpColor(orange, yellow, t);
    //Syntax  lerpColor(c1, c2, amt)
    //Parameters
    //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);
  }

  // draw sun
  fill (252, 130, 15);
  ellipse(615, y, 60, 60);
  y+=0.5;

  //draw lawn
  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);

  //draw mountain
  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);

  //draw river
  //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);
  }

  //draw road
  fill (245, 245, 245);
  quad(0, 440, 1200, 440, 1200, 500, 0, 480);


  // draw cloud
  fill(255, 255, 255);
  Xspeed+=2;
  println("Xspeed = ", Xspeed);
  ellipse(30+Xspeed, 75, 70, 70);
  ellipse(30+35+Xspeed, 75, 70, 70);
  ellipse(30+70+Xspeed, 75, 70, 70);

  //draw tree
  // 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