Cindy - I

By Cindy Chi
/* CINDY CHI OCT. 20, 2008 DMA 28: INTERACTIVITY EXCERCISE I This program creates a function that draws a pagoda with 4 parameters. Two parameters change the position of the pagoda. One parameter changes the angle and length of the roof borders. One parameter changes the width of the pagoda. */ void setup() { size(400, 400); noStroke(); smooth(); noLoop(); } void draw() { pagoda(68, 0, 5, 35); pagoda(198, 0, 35, 8); pagoda(330, 0, 20, 20); pagoda(68, 133, 26, 15); pagoda(198, 133, 15, 30); pagoda(330, 133, 30, 25); pagoda(68, 266, 10, 8); pagoda(198, 266, 23, 40); pagoda(330, 266, 36, 1); } void pagoda(float x, float y, float pagoda_w, float roof_x) { float top_x = x; //x pos (parameter #1) float top_y = y; //y pos (parameter #2) float half_width = pagoda_w; // width (parameter #3) float roof_border_x = roof_x; //x coord for roof border (parameter #4) float roof_border_y = 10; // y coord for roof border float roof_before_x; //used to get x coord of roof border from the floor above (used in for loop) float floor_height = top_y + 42; float roof_width_growth = 3; //used to increase width for each roof for each floor float width_growth = 0; //used to increase width for each floor //Rooftop fill(255, 204, 18); triangle(top_x, top_y, top_x + 2, top_y + 8, top_x - 2, top_y + 8); rect(top_x - 1, top_y + 8, 2, 2); rect(top_x - 6, top_y + 10, 12, 2); //////////4th floor fill(255, 0, 51); quad(top_x - 6, top_y + 12, top_x + 6, top_y + 12, top_x + (half_width + 3), top_y + 22, top_x - (half_width + 3), top_y + 22); //22 from height of rod (12) + height of roof (10) fill(255, 204, 18); //4th floor roof border beginShape(); vertex(top_x + (half_width + 3), top_y + 22); vertex(top_x - (half_width + 3), top_y + 22); //roof_before_x coord from here vertex(top_x - (half_width + 3) - roof_border_x, (top_y + 22) - roof_border_y); vertex(top_x - (half_width + 8), top_y + 27); //27 from 22 + 5(thickness of roof border) vertex(top_x + (half_width + 8), top_y + 27); vertex(top_x + (half_width + 3) + roof_border_x, (top_y + 22) - roof_border_y); endShape(); //body fill(255, 225, 180); rect(top_x - half_width, top_y + 27, 2 * half_width, 15); //////////Loop to create 3rd thru 1st floors roof_before_x = top_x - (half_width + 3); for(int i = 0; i < 3; i++) { //roof fill(255, 0, 51); quad(roof_before_x, floor_height, roof_before_x + (2 * (half_width + roof_width_growth)), floor_height, roof_before_x + (2 * (half_width + roof_width_growth)) + 3, floor_height + 10, roof_before_x - 3, floor_height + 10) ; //roof border fill(255, 205, 18); beginShape(); vertex(roof_before_x + (2 * (half_width + roof_width_growth)) + 3, floor_height + 10); vertex(roof_before_x - 3, floor_height + 10); vertex(roof_before_x - 3 - roof_border_x, floor_height + 10 - roof_border_y); vertex(roof_before_x - 8, floor_height + 15); vertex(roof_before_x + (2 * (half_width + roof_width_growth)) + 8, floor_height + 15); vertex(roof_before_x + (2 * (half_width + roof_width_growth)) + roof_border_x, floor_height + 10 - roof_border_y); endShape(); //floor body fill(255, 225, 180); rect(roof_before_x, floor_height + 15, 2 * (half_width + roof_width_growth), 15); roof_before_x -= 3; floor_height += 30; width_growth += 8; roof_width_growth += 3; } //Door for bottom floor fill(160, 77, 29); rect(top_x - 4, top_y + 120, 8, 12); }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*