> show canvas only <


/* built with Studio Sketchpad: 
 *   https://sketchpad.cc
 * 
 * observe the evolution of this sketch: 
 *   https://studio.sketchpad.cc/sp/pad/view/ro.vWw6caQBYZ5/rev.322
 * 
 * authors: 
 *   Eric Fickes

 * license (unless otherwise specified): 
 *   creative commons attribution-share alike 3.0 license.
 *   https://creativecommons.org/licenses/by-sa/3.0/ 
 */ 



/**
*************************************************************
** THIS IS A SKETCH BACKUP OF http://joshuadavis.com/xmas/ **
** YOU SHOULD REALLY GO THERE AND TRY THIS OUT BECAUSE YOU **
** CAN MAKE, SHARE, AND SAVE PNGs OF YOUR CUSTOM ARTWORK.  **
*************************************************************

This sketch brought to you by: 


- Joshua Davis
        >> http://www.joshuadavis.com/


- Jon Contino
        >> http://joncontino.com/


- Chuck Anderson
        >> http://www.nopattern.com/


- Si Scott
        >> http://www.siscottstudio.com/


- Eric Fickes
        >> http://www.ericfickes.com/
        >> http://www.behance.net/ericfickes


- and the entire Satellite Office family.
>> http://satelliteoffice.tv/


Wishing you and yours a happy holiday this 2012 


Create and share your own holiday card here.

        >> http://joshuadavis.com/xmas/


--
Instructions

1. Press the SPACEBAR to scroll through 5 Greetings illustrated by Jon Contino and Si Scott.

2. CLICK & DRAG in the white canvas area to decorate your card. Each time you click and drag, a random number of reflections will map artwork from Joshua Davis, Jon Contino, and Chuck Anderson. A secondary animation slowly scales the artwork up and down as you paint. Yellow, Green, Black and Red are mapped to each of the 4 corners.

3. Click SHARE when you're done decorating to render a .PNG of your greeting that you can post to Twitter, Facebook, E-mail or simply download.
--

* SHARE only available at http://joshuadavis.com/xmas/

**/



int[] reflections = {
  3, 6, 9, 12, 15
};

int ranReflection;
float scaleNumStep = 0.003;
float scaleNumMin = 0.5;
float scaleNumMax = 1.5;
float ranScale = scaleNumMin;
boolean scaleToggle = true;

int numFlakes = 300;
SnowClass[] myStorm = new SnowClass[numFlakes];

ArrayList CARDlist;
PImage curCard, card1, card2, card3, card4, card5;
PGraphics bg;
PVector lastMousePos;

ArrayList SVGlist;
PShape curSVG, img1, img2, img3, img4, img5;

void setup() {
  size(900, 600);
  background(#FFFFFF);
  smooth();

  for (int i =0; i<numFlakes; i++)
  {
    myStorm[i] = new SnowClass();
    myStorm[i].myScale = 3;
    myStorm[i].xPos = random(0, width);
    myStorm[i].yPos = random(0, height);
    myStorm[i].xSpeed = random(0, 1);
    myStorm[i].ySpeed = random(1, 3);
  }

  bg = createGraphics(width, height);
  lastMousePos = new PVector(mouseX, mouseY);

  rectMode(CENTER);
  cursor(CROSS);

  // load in top card assets
  card1 = loadImage("/static/uploaded_resources/p.4146/cover_01.png");
  card2 = loadImage("/static/uploaded_resources/p.4146/cover_02.png");
  card3 = loadImage("/static/uploaded_resources/p.4146/cover_03.png");
  card4 = loadImage("/static/uploaded_resources/p.4146/cover_04.png");
  card5 = loadImage("/static/uploaded_resources/p.4146/cover_05.png");

  CARDlist = new ArrayList();
  CARDlist.add(card1);
  CARDlist.add(card2);
  CARDlist.add(card3);
  CARDlist.add(card4);
  CARDlist.add(card5);

  curCard = (PImage)CARDlist.get( (int)random(CARDlist.size()) );

  // load in drawing assets
  img1 = loadShape("/static/uploaded_resources/p.4146/SVG_ca_01.svg");
  img2 = loadShape("/static/uploaded_resources/p.4146/SVG_ca_02.svg");
  img3 = loadShape("/static/uploaded_resources/p.4146/SVG_jc_01.svg");
  img4 = loadShape("/static/uploaded_resources/p.4146/SVG_jc_02.svg");
  img5 = loadShape("/static/uploaded_resources/p.4146/SVG_jd_01.svg");

  SVGlist = new ArrayList();
  SVGlist.add(img1);
  SVGlist.add(img2);
  SVGlist.add(img3);
  SVGlist.add(img4);
  SVGlist.add(img5);

  ranReflection = reflections[(int)random(reflections.length)];
  pickRanSVG();
}

void draw() {
  bg.beginDraw();

  if (mousePressed && (lastMousePos.x != mouseX || lastMousePos.y != mouseY)) {    
    bg.pushMatrix();
    float x = mouseX-(width/2), y = mouseY-(height/2), px = pmouseX-(width/2), py = pmouseY-(height/2);
    bg.translate(width/2, height/2);

    for (int i=0; i<ranReflection; i++) {      
      bg.noStroke();
      bg.fill( (width / 2) - (mouseX / 2), (height / 2) - (mouseY / 2), 0, 255   );      
      bg.rotate( TWO_PI/ranReflection );

      if (scaleToggle) {
        ranScale += scaleNumStep;
        if (ranScale >= scaleNumMax) {
          ranScale = scaleNumMax;
          scaleToggle = false;
        }
      } 
      else {
        ranScale -= scaleNumStep;
        if (ranScale <= scaleNumMin) {
          ranScale = scaleNumMin;
          scaleToggle = true;
        }
      }

      bg.shape(curSVG, x, y, curSVG.width * ranScale, curSVG.height * ranScale);
    }
    bg.popMatrix();
  }
  bg.endDraw();

  background(#FFFFFF);
  image(bg, 0, 0);
  image(curCard, 0, 0);
  for (int i =0; i<numFlakes; i++) myStorm[i].update();

  lastMousePos.x = mouseX;
  lastMousePos.y = mouseY;
}

class SnowClass
{
  int myScale = 1;
  float xPos = width/2;
  float yPos = height/2;
  float xSpeed = 3;
  float ySpeed = 2;

  void update()
  {
    noStroke();
    fill(#FFFFFF);
    ellipse(xPos, yPos, myScale, myScale);

    if (ySpeed < 2.0) myScale = 1;
    if (ySpeed < 1.5) myScale = 2;
    if (ySpeed < 1.0) myScale = 3;

    xPos += xSpeed;
    if (xPos > width) xPos = 0;
    if (xPos < 0) xPos = width;

    yPos += ySpeed;
    if (yPos > height) yPos = 0;
    if (yPos < 0) yPos = height;
  }
}

void pickRanSVG() {
  curSVG = (PShape)SVGlist.get( (int)random(SVGlist.size()) );
  curSVG.disableStyle();
}

void mouseReleased() {
  pickRanSVG();
  ranScale = scaleNumMin;
  ranReflection = reflections[(int)random(reflections.length)];
}

void keyPressed() {
  if (key == ' ') {
    bg.beginDraw();
    bg.background(#FFFFFF);
    bg.endDraw();

    background(#FFFFFF);
    curCard = (PImage)CARDlist.get( (int)random(CARDlist.size()) );
    ranReflection = reflections[(int)random(reflections.length)];
    ranScale = scaleNumMin;
  }
}