Wish You A White Christmas

Screen Shot 2015-02-15 at 1.45.37 AM
Objective

Image the world without real mirrors, what could a magic mirror look like. San Francisco does not snow over the year, as a girl comes from northern part of the country, I really miss the white Christmas. This prototype is specifically made for Christmas in SF, associate with christmas tree with led light coded in Arduino program, and using camera to reflect the player, and player can catch the snow flakes on the screen to enjoy the White Christmas.

 

Screen Shot 2015-02-15 at 11.48.42 AM

 

Screen Shot 2015-02-15 at 11.49.21 AM

 Source Code:Processing
//Thanks to David Grant for partical snow falling source
// gif animation credits to Valentin Kirilov
//Wish you a white Christmas @SF, merry christmas and happy new year!

import gifAnimation.*;
import processing.video.*;
import ddf.minim.*;

Minim minim;
AudioPlayer player;
color black = color(0, 0, 0);
color white = color(255, 255, 255);

int stoppedParticles;

Gif animation;
Gif animation_1;
Gif animation_2;
Gif animation_3;
 


//snow
Particle[] particles = new Particle[0];
int maxParticles =300;

//pixlate
int cellSize = 5;
int cols, rows;

Capture video;

void setup()
{
 size (640, 480);

 minim = new Minim(this);
 player = minim.loadFile("Jingle-Bells-Singing-Bell.mp3");
 player.play();

 cols = width / cellSize;
 rows = height / cellSize;
 colorMode(RGB, 255, 255, 255, 100);
 ellipseMode(CENTER);

 animation = new Gif(this, "christmas.gif");
 animation_1=new Gif(this, "1.gif");
 animation_2=new Gif(this, "2.gif"); 
 animation_3=new Gif(this, "3.gif");
 
 
 video = new Capture(this, width, height);

 video.start();
}

void draw()
{
 color c;
 background(100);

 if (video.available()) {
 video.read();
 video.loadPixels();
 background(100);
 }




 for (int i = 0; i < cols; i++) {
 for (int j = 0; j < rows; j++) {


 int x = i*cellSize;
 int y = j*cellSize;
 int loc = (video.width-x-1) + y*video.width; // Reversing x to mirror the image

 

 c = video.pixels[loc];
 float sz = (brightness(c) / 255.0) *cellSize;

 noStroke();

 if (brightness(c)>110) {
 fill(255, 0, 0); //red
 } else if (brightness(c)<90) {
 fill (0, 0, 0);//balck
 } else {
 fill (17, 210, 150); //green
 }
 ellipse(x+cellSize*2, y+cellSize*2, 5, 5);
 }
 }

 particles = (Particle[]) append(particles, new Particle(500, 0));

 if (particles.length>maxParticles) {
 particles = (Particle[]) subset(particles, 1);
 }
 loadPixels();
 for (int i=0; i<particles.length; i++) {
 if (particles[i].y<15) {
 particles[i].x += particles[i].xVel;
 particles[i].y += particles[i].yVel;
 }
 if (particles[i].y>15) {

 c = get(floor(particles[i].x), floor(particles[i].y));
 if (c!=black && c!=white) {
 particles[i].x += particles[i].xVel*5;
 particles[i].y += particles[i].yVel*5;

 particles[i].stopped = false;
 } else {
 particles[i].stopped = true;
 }
 }



 ellipse(particles[i].x, particles[i].y, particles[i].partsize, particles[i].partsize);
 fill (255, 255, 255);
 }

 stoppedParticles = 0;
 for (int i=0; i<particles.length; i++) {
 if (particles[i].stopped == true) {
 stoppedParticles++;
 }
 }
 
 
// PFont gothic;
// gothic = loadFont("AdobeGothicStd-Bold.otf");
// textFont(gothic);
 text("Snow Flakes: " + stoppedParticles, 50,80);
 textSize(18);
 
 
 if(stoppedParticles <= 160) {
 if(stoppedParticles<30){
 image(animation_1, 50,-10);
 animation_1.play(); 
 
 }
 else if (stoppedParticles>=30&&stoppedParticles<=100){
 image(animation_2,50,-10);
 animation_2.play();
 
 
 
 }
 else{
 image(animation_3,50,-10);
 animation_3.play();
 
 
 }
 }
 
 else if(stoppedParticles>165) {
 image(animation, -100,-50);
 animation.play();
 animation.ignoreRepeat();
 }
}
 

int colorOfClosestCell(int screenX, int y) {

 return (1);
}

//snow class
class Particle {

 float x; 
 float y; 
 float xVel; 
 float yVel; 
 float partsize; 

 boolean stopped;



 Particle(float xpos, float ypos) {

 x = xpos = random (0, 600);
 y = ypos;
 xVel = random (-2, 2); 
 yVel = random (0, 5); 
 partsize = random (5, 12 );

 stopped = false;
 }
}

class Animation {
 PImage[] images;
 int imageCount;
 int frame;
 //int iWidth;
 //int iHeight;

 Animation(String imagePrefix, int count) {
 imageCount = count;
 images = new PImage[imageCount];

 for (int i = 0; i < imageCount; i++) {
 // Use nf() to number format 'i' into four digits
 String filename = imagePrefix + nf(i, 4) + ".gif";
 images[i] = loadImage(filename);
 }
 }

 void display(float xpos, float ypos, float iWidth, float iHeight) {
 frame = (frame+1) % imageCount;

 imageMode(CENTER);
 image(images[frame], xpos, ypos, iWidth*5.5, iHeight*4);
 //imageMode(CORNER);
 }

 int getWidth() {
 return images[0].width;
 }
}
Source Code:Arduino
#include <Adafruit_NeoPixel.h>

#define PIN 6

 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(90, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
 strip.begin();
 strip.show(); // Initialize all pixels to 'off'
}

void loop() {
 
 theaterChase(strip.Color(127, 127, 127), 100); // White
 theaterChase(strip.Color(127, 0, 0),100); // Red
 theaterChase(strip.Color( 0, 0, 127), 100); // Blue

 rainbow(20);
 theaterChaseRainbow(50);
}


void rainbow(uint8_t wait) {
 uint16_t i, j;

 for(j=0; j<256; j++) {
 for(i=0; i<strip.numPixels(); i++) {
 strip.setPixelColor(i, Wheel((i+j) & 255));
 }
 strip.show();
 delay(wait);
 }
}

 
 
void theaterChase(uint32_t c, uint8_t wait) {
 for (int j=0; j<10; j++) { 
 for (int q=0; q < 3; q++) {
 for (int i=0; i < strip.numPixels(); i=i+3) {
 strip.setPixelColor(i+q, c); 
 }
 strip.show();
 
 delay(wait);
 
 for (int i=0; i < strip.numPixels(); i=i+3) {
 strip.setPixelColor(i+q, 0); 
 }
 }
 }
}

 
void theaterChaseRainbow(uint8_t wait) {
 for (int j=0; j < 256; j++) { 
 for (int q=0; q < 3; q++) {
 for (int i=0; i < strip.numPixels(); i=i+3) {
 strip.setPixelColor(i+q, Wheel( (i+j) % 255)); 
 }
 strip.show();
 
 delay(wait);
 
 for (int i=0; i < strip.numPixels(); i=i+3) {
 strip.setPixelColor(i+q, 0); 
 }
 }
 }
}

 
// r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
 WheelPos = 255 - WheelPos;
 if(WheelPos < 85) {
 return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
 } else if(WheelPos < 170) {
 WheelPos -= 85;
 return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
 } else {
 WheelPos -= 170;
 return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
 }
}

Drop a comment

Your email address will not be published. Required fields are marked *