Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Chris Jernigan 2012
- // CSCI 182 hw2 "Fall Scene"
- void setup(){
- size(600,600);
- smooth();
- }
- void draw(){
- //Sunset Background
- color c1 = color(#34516C);
- color c2 = color(#FA9D12);
- sunSet(0,0,width,height,c1,c2,1);
- //fading sun
- fill(#CE873A,250);
- ellipse(190,350,30,30);
- //background mountains
- mountain(50,-150,#504458);
- mountain(270,-100,#504458);
- mountain(200,-50,#504458);
- mountain(-200,-100,#504458);
- mountain(-200,-100,#504458);
- //bg mountains level 2
- mountain(170,-90,#362650);
- mountain(-100,-50,#362650);
- //bg mountains level 3
- mountain(2,2,#191A3E);
- mountain(200,2,#191A3E);
- mountain(150,-50,#191A3E);
- mountain(-200,2,#191A3E);
- //big hill
- pushMatrix();
- translate(37,0);
- fill(0);
- beginShape();
- curveVertex(20,500);
- curveVertex(-50,650);
- curveVertex(190,400);
- curveVertex(300,350);
- curveVertex(450,420);
- curveVertex(650,650);
- curveVertex(680,500);
- endShape();
- popMatrix();
- tree(); //tree?
- //falling leaves!
- h1.leaves();
- h2.leaves();
- h3.leaves();
- h4.leaves();
- h5.leaves();
- h6.leaves();
- h7.leaves();
- h8.leaves();
- }
- //setting variables for leaves
- Leaf h1 = new Leaf(300,300, 2.0);
- Leaf h2 = new Leaf(325,300, 1.7);
- Leaf h3 = new Leaf(233,300, 1.12);
- Leaf h4 = new Leaf(307,300, 1.0);
- Leaf h5 = new Leaf(275,300, 1.1);
- Leaf h6 = new Leaf(248,300, 1.2);
- Leaf h7 = new Leaf(292,300, 1.3);
- Leaf h8 = new Leaf(250,300, 0.5);
- //creating leaf object
- class Leaf {
- float xpos,ypos,speed;
- Leaf (float xp, float yp, float s){
- xpos = xp;
- ypos = yp;
- speed = s;
- }
- //controls falling of leaves
- void leaves(){
- pushMatrix();
- translate(290,100);
- ypos += speed;
- if (ypos >= 300) {
- ypos = 200;
- xpos += random(-100,50);
- }
- if (xpos <= 0 || xpos >= 100){
- xpos = random(150);
- }
- fill(#A54E14,255);
- ellipse(xpos, ypos, 5, 3);
- popMatrix();
- }
- }
- //tree
- void tree(){
- pushMatrix();
- translate(120,80);
- rect(200,210,15,55);
- strokeWeight(10);
- stroke(0);
- line(200,210,180,180);
- line(210,210,240,180);
- line(210,210,200,160);
- line(210,230,215,160);
- noStroke();
- beginShape();
- vertex(187,275);
- vertex(207,260);
- vertex(233,275);
- endShape();
- fill(#CE5A3A,200);
- ellipse(200,180,40,40);
- fill(#F7E23C,100);
- ellipse(190,170,40,40);
- fill(#894E16,200);
- ellipse(220,170,40,40);
- fill(#E84200,100);
- ellipse(220,200,40,40);
- fill(#D9FF08,100);
- ellipse(180,200,50,50);
- fill(#B93E0D,100);
- ellipse(240,200,50,50);
- popMatrix();
- }
- //mountain object used to create background mountains
- void mountain(float m1, float m2, color c){
- fill(c);
- noStroke();
- pushMatrix();
- translate(m1,m2);
- beginShape();
- curveVertex(20,500);
- curveVertex(0,600);
- curveVertex(200,500);
- curveVertex(300,470);
- curveVertex(400,500);
- curveVertex(600,600);
- curveVertex(680,500);
- endShape();
- popMatrix();
- }
- //Gradient creates sunset effect
- int Y_AXIS = 1;
- int X_AXIS = 2;
- void sunSet(int x, int y, float w, float h, color c1, color c2, int axis ){
- // calculate differences between color components
- float deltaR = red(c2)-red(c1);
- float deltaG = green(c2)-green(c1);
- float deltaB = blue(c2)-blue(c1);
- // choose axis
- if(axis == Y_AXIS){
- /*nested for loops set pixels
- in a basic table structure */
- // column
- for (int i=x; i<=(x+w); i++){
- // row
- for (int j = y; j<=(y+h); j++){
- color c = color(
- (red(c1)+(j-y)*(deltaR/h)),
- (green(c1)+(j-y)*(deltaG/h)),
- (blue(c1)+(j-y)*(deltaB/h))
- );
- set(i, j, c);
- }
- }
- }
- else if(axis == X_AXIS){
- // column
- for (int i=y; i<=(y+h); i++){
- // row
- for (int j = x; j<=(x+w); j++){
- color c = color(
- (red(c1)+(j-x)*(deltaR/h)),
- (green(c1)+(j-x)*(deltaG/h)),
- (blue(c1)+(j-x)*(deltaB/h))
- );
- set(j, i, c);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment