Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Snowy Christmas Tree
- // By Christan Shaw and Jacob Carey
- /* Snow with a christmas tree and lights
- When the user clicks, the lights on the tree changes */
- //Snow Varibles
- int number_of_snow = 100;
- float[] snow_x = new float[number_of_snow];
- float[] snow_y = new float[number_of_snow];
- float snow_size = 5;
- float snow_speed = 1;
- //Tree Varibles
- color light_colour = color(255, 0, 0);
- boolean cycle_colours = false;
- int cycle_rate = 15;
- int r = 255;
- int g = 0;
- int b = 0;
- void setup() {
- size(600,400);
- frameRate(60);
- background(52);
- // Snow Init
- for (int i=0; i < snow_x.length; i=i+1) { // Create random x cords
- snow_x[i] = random(1, width);
- }
- for (int i=0; i< snow_y.length; i=i+1) { // Create random y cords
- snow_y[i] = random(1, height);
- }
- }
- void draw_snow() { // Draws snow according to the varibles
- fill(255); // White snow with no stroke
- noStroke();
- for (int i=0; i < snow_x.length; i=i+1) { // Goes through the snow array to draw them
- ellipse(snow_x[i], snow_y[i], snow_size, snow_size); // Circle for the snow
- }
- }
- 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.
- for (int i=0; i < snow_y.length; i=i+1) {
- if (snow_y[i] >= height+5) {
- snow_y[i] = 0;
- snow_x[i] = random(1, width);
- } else {
- snow_y[i] = snow_y[i] + 1;
- }
- }
- }
- void draw_tree() {
- //Tree pieces
- fill(139, 69, 19); //Trunk Colour
- rect(265, 350, 70, 100); //Trunk
- fill(0, 255, 0); //Branches Colour
- triangle(300, 50, 250, 110, 350, 110); //Uppermost Branches
- triangle(300, 90, 210, 180, 390, 180); //Second to top Branches
- triangle(300, 150, 170, 270, 430, 270); //Third to top Branches
- triangle(300, 220, 130, 360, 470, 360); //Lowermost Branches
- fill(light_colour);
- stroke(2);
- circle(305, 70, 10);
- circle(280, 90, 10);
- circle(330, 140, 10);
- circle(320, 160, 10);
- circle(260, 150, 10);
- circle(265, 220, 10);
- circle(230, 240, 10);
- circle(360, 230, 10);
- circle(360, 300, 10);
- circle(210, 330, 10);
- circle(290, 320, 10);
- }
- void mouseClicked(){
- if(cycle_colours){
- cycle_colours = false;
- light_colour = color(255, 0, 0);
- r = 255;
- g = 0;
- b = 0;
- }
- else if(!cycle_colours){
- cycle_colours = true;
- }
- }
- void draw() {
- clear();
- background(52);
- //Tree
- draw_tree();
- //Snow
- draw_snow();
- update_snow();
- //Light Color Cycling
- if(cycle_colours){
- light_colour = color(r, g, b);
- if(r < 255 && g == 0 && b == 0){
- r += cycle_rate;
- }
- if(r == 255 && g < 255 && b == 0){
- g += cycle_rate;
- }
- if(r > 0 && g == 255 && b == 0){
- r -= cycle_rate;
- }
- if(r == 0 && g == 255 && b < 255){
- b += cycle_rate;
- }
- if(r == 0 && g > 0 && b == 255){
- g -= cycle_rate;
- }
- if(r < 255 && g == 0 && b == 255){
- r += cycle_rate;
- }
- if(r == 255 && g == 0 && b > 0){
- b -= cycle_rate;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement