Instantly share code, notes, and snippets.

@aaronparsekian /snowman Secret
Created Oct 6, 2015

Embed
What would you like to do?
var snow;
var snowman = new Snowman();
var snowArray = [];
function setup() {
initSnow();
}
function draw() {
createCanvas(900, 900);
background(100);
snowman.display();
snowman.move();
for (var i = 0; i <= 30; i++) {
snowArray[i].move();
snowArray[i].display();
}
}
function initSnow() {
for (var i = 0; i <= 30; i++) {
newX = random(0, 900);
newY = random(0, 900);
newXspeed = random(0.5, 1.5);
newYspeed = random(0.5, 1.5);
snowArray[i] = new Snowflake(newX, newY, newXspeed, newYspeed);
}
}
function Snowflake(x, y, xspeed, yspeed) { //obj called Snowflake
this.y = y;
this.x = x;
this.xspeed = xspeed;
this.yspeed = yspeed;
this.display = function() {
stroke(255, 80);
noFill();
strokeWeight(2);
//for snowflake shape
line(this.x, this.y, this.x, this.y + 50);
line(this.x + 10, this.y + 13, this.x - 10, this.y + 38);
line(this.x + 20, this.y + 25, this.x - 20, this.y + 25);
line(this.x + 10, this.y + 38, this.x - 10, this.y + 13);
}
this.move = function() {
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
if (this.y == height) {} else {
this.xspeed = 2 + sin(frameCount * 0.005) * 100;
this.yspeed += 1;
}
//if (this.y === 900) {
// initSnow();
//}
}
//this.reInit = function() {
//}
}
/*
function initSnow(SX, SY, SXspeed, SYspeed) {
SX = this.newX ;
SY = this.newY ;
SXspeed = this.newXspeed ;
SYspeed = this.newYspeed ;
for (var i = 0; i <= 30; i++) {
this.newX = random(0, 900);
this.newY = random(0, 900);
this.newXspeed = random(0.5, 1.5);
this.newYspeed = random(0.5, 1.5);
snowArray[i] = new Snowflake(newX, newY, newXspeed, newYspeed);
}
}
*/
function Snowman() {
this.armX = 145;
this.armY = 300;
this.armX2 = 260;
this.armY2 = 290;
this.display = function() {
line(this.armX, this.armY, this.armX2, this.armY2); //arms 145,300,260,290
ellipse(200, 268, 25, 25); //body
ellipse(200, 300, 40, 40);
ellipse(200, 350, 60, 60);
ellipse(205, 262, 5, 5); //eyes
ellipse(195, 262, 5, 5);
fill(0);
ellipse(200, 268, 5, 5); //nose
}
this.move = function() {
if ((second() % 2) === 0) {
this.armX = 155;
this.armY = 300;
this.armX2 = 240;
this.armY2 = 290;
} else {
this.armX = 140;
this.armY = 310;
this.armX2 = 250;
this.armY2 = 290;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment