Guest User

Untitled

a guest
Dec 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. // Chris Jernigan 2012
  2. // CSCI 182 hw2 "Fall Scene"
  3.  
  4.  
  5. void setup(){
  6.  
  7. size(600,600);
  8. smooth();
  9. }
  10.  
  11.  
  12. void draw(){
  13.  
  14. //Sunset Background
  15. color c1 = color(#34516C);
  16. color c2 = color(#FA9D12);
  17. sunSet(0,0,width,height,c1,c2,1);
  18.  
  19. //fading sun
  20. fill(#CE873A,250);
  21. ellipse(190,350,30,30);
  22.  
  23. //background mountains
  24. mountain(50,-150,#504458);
  25. mountain(270,-100,#504458);
  26. mountain(200,-50,#504458);
  27. mountain(-200,-100,#504458);
  28. mountain(-200,-100,#504458);
  29.  
  30. //bg mountains level 2
  31. mountain(170,-90,#362650);
  32. mountain(-100,-50,#362650);
  33.  
  34. //bg mountains level 3
  35. mountain(2,2,#191A3E);
  36. mountain(200,2,#191A3E);
  37. mountain(150,-50,#191A3E);
  38. mountain(-200,2,#191A3E);
  39.  
  40.  
  41. //big hill
  42. pushMatrix();
  43. translate(37,0);
  44. fill(0);
  45. beginShape();
  46. curveVertex(20,500);
  47. curveVertex(-50,650);
  48.  
  49. curveVertex(190,400);
  50. curveVertex(300,350);
  51. curveVertex(450,420);
  52.  
  53. curveVertex(650,650);
  54. curveVertex(680,500);
  55. endShape();
  56. popMatrix();
  57.  
  58. tree(); //tree?
  59.  
  60. //falling leaves!
  61. h1.leaves();
  62. h2.leaves();
  63. h3.leaves();
  64. h4.leaves();
  65. h5.leaves();
  66. h6.leaves();
  67. h7.leaves();
  68. h8.leaves();
  69. }
  70.  
  71. //setting variables for leaves
  72. Leaf h1 = new Leaf(300,300, 2.0);
  73. Leaf h2 = new Leaf(325,300, 1.7);
  74. Leaf h3 = new Leaf(233,300, 1.12);
  75. Leaf h4 = new Leaf(307,300, 1.0);
  76. Leaf h5 = new Leaf(275,300, 1.1);
  77. Leaf h6 = new Leaf(248,300, 1.2);
  78. Leaf h7 = new Leaf(292,300, 1.3);
  79. Leaf h8 = new Leaf(250,300, 0.5);
  80.  
  81. //creating leaf object
  82. class Leaf {
  83. float xpos,ypos,speed;
  84. Leaf (float xp, float yp, float s){
  85. xpos = xp;
  86. ypos = yp;
  87. speed = s;
  88. }
  89.  
  90. //controls falling of leaves
  91. void leaves(){
  92. pushMatrix();
  93. translate(290,100);
  94. ypos += speed;
  95. if (ypos >= 300) {
  96. ypos = 200;
  97. xpos += random(-100,50);
  98. }
  99. if (xpos <= 0 || xpos >= 100){
  100. xpos = random(150);
  101. }
  102. fill(#A54E14,255);
  103. ellipse(xpos, ypos, 5, 3);
  104. popMatrix();
  105. }
  106.  
  107.  
  108. }
  109.  
  110. //tree
  111. void tree(){
  112.  
  113. pushMatrix();
  114. translate(120,80);
  115. rect(200,210,15,55);
  116. strokeWeight(10);
  117. stroke(0);
  118. line(200,210,180,180);
  119. line(210,210,240,180);
  120. line(210,210,200,160);
  121. line(210,230,215,160);
  122.  
  123. noStroke();
  124. beginShape();
  125. vertex(187,275);
  126. vertex(207,260);
  127. vertex(233,275);
  128. endShape();
  129.  
  130. fill(#CE5A3A,200);
  131. ellipse(200,180,40,40);
  132. fill(#F7E23C,100);
  133. ellipse(190,170,40,40);
  134. fill(#894E16,200);
  135. ellipse(220,170,40,40);
  136. fill(#E84200,100);
  137. ellipse(220,200,40,40);
  138. fill(#D9FF08,100);
  139. ellipse(180,200,50,50);
  140. fill(#B93E0D,100);
  141. ellipse(240,200,50,50);
  142.  
  143.  
  144. popMatrix();
  145.  
  146.  
  147.  
  148. }
  149.  
  150.  
  151. //mountain object used to create background mountains
  152. void mountain(float m1, float m2, color c){
  153. fill(c);
  154. noStroke();
  155. pushMatrix();
  156. translate(m1,m2);
  157. beginShape();
  158. curveVertex(20,500);
  159. curveVertex(0,600);
  160.  
  161. curveVertex(200,500);
  162. curveVertex(300,470);
  163. curveVertex(400,500);
  164.  
  165. curveVertex(600,600);
  166. curveVertex(680,500);
  167. endShape();
  168. popMatrix();
  169. }
  170.  
  171.  
  172. //Gradient creates sunset effect
  173. int Y_AXIS = 1;
  174. int X_AXIS = 2;
  175. void sunSet(int x, int y, float w, float h, color c1, color c2, int axis ){
  176. // calculate differences between color components
  177. float deltaR = red(c2)-red(c1);
  178. float deltaG = green(c2)-green(c1);
  179. float deltaB = blue(c2)-blue(c1);
  180.  
  181. // choose axis
  182. if(axis == Y_AXIS){
  183. /*nested for loops set pixels
  184. in a basic table structure */
  185. // column
  186. for (int i=x; i<=(x+w); i++){
  187. // row
  188. for (int j = y; j<=(y+h); j++){
  189. color c = color(
  190. (red(c1)+(j-y)*(deltaR/h)),
  191. (green(c1)+(j-y)*(deltaG/h)),
  192. (blue(c1)+(j-y)*(deltaB/h))
  193. );
  194. set(i, j, c);
  195. }
  196. }
  197. }
  198. else if(axis == X_AXIS){
  199. // column
  200. for (int i=y; i<=(y+h); i++){
  201. // row
  202. for (int j = x; j<=(x+w); j++){
  203. color c = color(
  204. (red(c1)+(j-x)*(deltaR/h)),
  205. (green(c1)+(j-x)*(deltaG/h)),
  206. (blue(c1)+(j-x)*(deltaB/h))
  207. );
  208. set(j, i, c);
  209. }
  210. }
  211. }
  212. }
Add Comment
Please, Sign In to add comment