xxxxxxxxxx
//alison yang
//creative coding section d
//final
var snowflakes = [];
var f = 0;
var giselle;
var startscreen = false;
var inp = '';
var rs;
var b;
function preload(){
//manual motion capture from svetlana zakharova in 'giselle' at teatro alla scala,2015
giselle = loadImage('loop.GIF');
}
function setup() {
createCanvas(windowWidth, windowHeight);
imageMode(CENTER);
//set up a starter page
var box = createInput('Enter whatever to start: ');
box.position(width/2-90, 30);
box.style('font-size','25px')
box.size(300);
box.input(boxtyped);
//each refresh returns the gif in a random size
rs = random(200,500);
giselle.resize(rs, rs);
//each refresh returns a random blue
b = random(89,255);
}
function draw() {
//starter
if (!startscreen){
background(0);
}
//start the screen
if (startscreen){
//changing background color with mouse movement
background(mouseX*0.3,mouseY*0.6,b,200);
//from https://p5js.org/examples/simulate-snowflakes.html
let t = frameCount / 60; // update time
// create a random number of snowflakes each frame
for (let i = 0; i < random(5); i++) {
snowflakes.push(new Snowflake()); // append snowflake object
}
for (let i=0;i<snowflakes.length;i++){
if (snowflakes[i].alive) {
snowflakes[i].fall(t);
snowflakes[i].drawsnowflakes();
}
}
}
image(giselle,width/2,height/2);
}
function mouseClicked(){
//click to play
giselle.setFrame(f);
giselle.play();
}
function keyTyped(){
//press key to pause
f = giselle.getCurrentFrame();
giselle.pause();
}
function boxtyped(){
inp = this.value;
startscreen = true;
}
//rewrite class from https://p5js.org/examples/simulate-snowflakes.html
class Snowflake {
constructor(x,y,ia,s,r){
this.x = 0;
this.y = random(-50,0);
this.ia = random(0,2*PI);
this.s = random(2,6);
this.r = sqrt(random(pow(width / 2, 2)));
this.alive = true;
}
fall(t){
let w = 0.6;
let a = w * t + this.ia;
this.x = width/2 + this.r * sin(a);
this.y += pow(this.s, 0.5);
if (this.y > height) {
this.alive = false;
}
}
drawsnowflakes(){
noStroke();
ellipse(this.x, this.y, this.s);
}
}