SHARE
TWEET

Untitled

a guest Dec 11th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Snowy Christmas Tree
  2. // By Christan Shaw and Jacob Carey
  3.  
  4. /* Snow with a christmas tree and lights
  5. When the user clicks, the lights on the tree changes */
  6.  
  7. //Snow Varibles
  8. int number_of_snow = 100;
  9. float[] snow_x = new float[number_of_snow];
  10. float[] snow_y = new float[number_of_snow];
  11. float snow_size = 5;
  12. float snow_speed = 1;
  13.  
  14. //Tree Varibles
  15. color light_colour = color(255, 0, 0);
  16. boolean cycle_colours = false;
  17. int cycle_rate = 15;
  18. int r = 255;
  19. int g = 0;
  20. int b = 0;
  21.  
  22. void setup() {
  23.  size(600,400);
  24.  frameRate(60);
  25.  background(52);
  26.  
  27.  // Snow Init
  28.  for (int i=0; i < snow_x.length; i=i+1) { // Create random x cords
  29.    snow_x[i] = random(1, width);
  30.  }
  31.  for (int i=0; i< snow_y.length; i=i+1) { // Create random y cords
  32.    snow_y[i] = random(1, height);
  33.  }
  34. }
  35.  
  36. void draw_snow() { // Draws snow according to the varibles
  37.   fill(255); // White snow with no stroke
  38.   noStroke();
  39.   for (int i=0; i < snow_x.length; i=i+1) { // Goes through the snow array to draw them
  40.     ellipse(snow_x[i], snow_y[i], snow_size, snow_size); // Circle for the snow
  41.   }
  42. }
  43.  
  44. void update_snow() { // Adds 'snow_speed' to every snow_y, if the snow_y is lowwer than the lenght it then puts it at the top and puts a random x cord.
  45.   for (int i=0; i < snow_y.length; i=i+1) {
  46.     if (snow_y[i] >= height+5) {
  47.      snow_y[i] = 0;
  48.      snow_x[i] = random(1, width);
  49.     } else {
  50.       snow_y[i] = snow_y[i] + 1;
  51.     }
  52.   }
  53. }
  54.  
  55. void draw_tree() {
  56.   //Tree pieces
  57.   fill(139, 69, 19); //Trunk Colour
  58.   rect(265, 350, 70, 100); //Trunk
  59.   fill(0, 255, 0); //Branches Colour
  60.   triangle(300, 50, 250, 110, 350, 110); //Uppermost Branches
  61.   triangle(300, 90, 210, 180, 390, 180); //Second to top Branches
  62.   triangle(300, 150, 170, 270, 430, 270); //Third to top Branches
  63.   triangle(300, 220, 130, 360, 470, 360); //Lowermost Branches
  64.   fill(light_colour);
  65.   stroke(2);
  66.   circle(305, 70, 10);
  67.   circle(280, 90, 10);
  68.   circle(330, 140, 10);
  69.   circle(320, 160, 10);
  70.   circle(260, 150, 10);
  71.   circle(265, 220, 10);
  72.   circle(230, 240, 10);
  73.   circle(360, 230, 10);
  74.   circle(360, 300, 10);
  75.   circle(210, 330, 10);
  76.   circle(290, 320, 10);
  77. }
  78.  
  79. void mouseClicked(){
  80.   if(cycle_colours){
  81.     cycle_colours = false;
  82.     light_colour = color(255, 0, 0);
  83.     r = 255;
  84.     g = 0;
  85.     b = 0;
  86.   }
  87.   else if(!cycle_colours){
  88.     cycle_colours = true;
  89.   }
  90. }
  91. void draw() {
  92.   clear();
  93.   background(52);
  94.  
  95.   //Tree
  96.   draw_tree();
  97.  
  98.   //Snow
  99.   draw_snow();
  100.   update_snow();
  101.  
  102.   //Light Color Cycling
  103.  
  104.   if(cycle_colours){
  105.     light_colour = color(r, g, b);
  106.     if(r < 255 && g == 0 && b == 0){
  107.       r += cycle_rate;
  108.     }
  109.     if(r == 255 && g < 255 && b == 0){
  110.       g += cycle_rate;
  111.     }
  112.     if(r > 0 && g == 255 && b == 0){
  113.       r -= cycle_rate;
  114.     }
  115.     if(r == 0 && g == 255 && b < 255){
  116.       b += cycle_rate;
  117.     }
  118.     if(r == 0 && g > 0 && b == 255){
  119.       g -= cycle_rate;
  120.     }
  121.     if(r < 255 && g == 0 && b == 255){
  122.       r += cycle_rate;
  123.     }
  124.     if(r == 255 && g == 0 && b > 0){
  125.       b -= cycle_rate;
  126.     }
  127.   }
  128. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top