// Project 2 //Erica D. Cochran //ericac@andrew.cmu.edu //Section B //Copyright © Erica D. Cochran //December 1, 2009 //Carnegie Mellon University //Exploring Programming with Graphics //Pittsburgh, PA, USA //All Rights Reserved // Fill in this comment template with the required information // A Printed version is due in class and electronically in the handin folder by 4:30 Friday, November 20/ /* Detailed Description of Project 2 // Interactive Christmas Card where user decorates a tree and the room Idea is similar to internet hallmark or blue mountain electronic greeting cards /* Source of the information if any: Ornaments and windows retrieved from: http://www.freeclipartnow.com/ Ornaments and windows edited in Photoshop Fireplace retrieved from: http://www.clipartguide.com/_small/1386-0812-1516-5625.jpg Fireplace edited in Photoshop Tree drawn in Photoshop. Explain user input or control: //User shall select a choice of background: the Christmas tree has only one option, decorations and ornaments - choice of colors and shapes to decorate tree, and choose from a star or angle to place on top of tree. Other choices shall include a window to place on the wall with choice of curtain colors fire place shall have flame Code will include boolean functions Through a series of choices user will have the potential to decorate several types of rooms and tree decorations then receive a holiday message. */ /** Holiday Card
*/
PFont f1;
PImage candles;
PImage bulbpattern;
PImage bulbred;
PImage bulbyellow;
PImage fireplace2;
PImage hollybasket;
PImage bulborange;
PImage stocking;
PImage tree;
PImage angel;
PImage windowblue;
PImage windowred;
float sectionW, sectionH, offSet;
float bulbD;
boolean toggleSnow = false;
int n = 0;
//snow
int [] xValues = {110, 165, 200, 240, 370, 420, 450, 525, 610, 675, 765, 790};
int [] yValues = {-30, -10, -80, -110, -140, -100, -180, -200, -300, -40, -90, -100};
int [ ] deltaYs = {10, 15, 10, 10, 10, 12, 5, 14, 13, 12, 10, 10 };
//bulb decorations
int [] row1 = {430, 450};
int [] row2 = {410, 415, 435, 470};
int [] row3 = {390, 410, 430, 475, 480};
int [] row4 = {370, 405, 425, 470, 485, 515};
int [] row5 = {350, 415, 435, 460, 480, 520, 535};
int [] row6 = {330, 390, 425, 465, 490, 525, 540, 555};
int [] row7 = {310, 360, 405, 440, 470, 505, 530, 550, 575};
int [] row8 = {295, 340, 375, 400, 420, 455, 470, 500, 525, 570};
int [] row9 = {275, 300, 325, 360, 390, 415, 430, 490, 520, 565, 615};
void setup ()
{
size (800,800);
background (100); // use for start before user selects a color
f1 = loadFont ("f1.vlw");
bulbpattern = loadImage ("bulbpattern.png");
bulbred = loadImage ("bulbred.png");
bulbyellow = loadImage ("bulbyellow.png");
fireplace2 = loadImage ("fireplace2.png");
hollybasket = loadImage ("hollybasket.png");
bulborange = loadImage ("bulborange.png");
stocking = loadImage ("stocking.png");
candles = loadImage ("candles.png");
tree = loadImage ("tree.png");
windowblue = loadImage ("windowblue.png");
windowred = loadImage ("windowred.png");
angel = loadImage ("angel.png");
bulbD=.013*width;
//Sections: screen divided into 4 equal widths
sectionW = width/4;
sectionH = height/4;
offSet = 5;
}
void draw ()
{
ellipseMode(CORNER);
rectMode(CORNER);
fill (0);
textFont (f1, 15);
text ("Press '1' for red background. Press '2' for blue background", sectionW+10, height*.94);
text ("Press '1' or '2' to redraw picture before finished", sectionW+10, height*.97);
if (toggleSnow)
{
if (n <=100)
{
fadeScreen();
n++;
}
else
{
background(0);
drawSnowman();
drawSnow();
moveSnow ();
repeatSnow ();
}
}
}
void keyPressed ()
{
if (key == '1') //brick color
{
drawGrid ();
background1 ();
drawFireplace ();
drawTree ();
windowText ();
}
if (key == '2') //blue color
{
drawGrid ();
background2 ();
drawFireplace ();
drawTree ();
windowText ();
}
// window curtain colors
if (key == 'b')
{
drawWindowblue ();
bulbText ();
println ("ppf"); //test to verify keys worked
}
if (key == 'r')
{
drawWindowred ();
bulbText ();
}
// bulb colors; tree ornaments
if (key == 'p')
{
drawBulbpattern ();
treeTopText ();
}
if (key == 'd')
{
drawBulbred ();
treeTopText ();
}
if (key == 'y')
{
drawBulbyellow ();
treeTopText ();
println ("ppf");
}
if (key == 'o')
{
drawBulborange ();
treeTopText ();
}
// tree tops
if (key == 'a')
{
drawAngel ();
fireText ();
}
if (key == 's')
{
drawStar ();
fireText ();
}
// fireplace decoration
if (key == 'c')
{
drawCandles ();
finishText ();
}
if (key == 't')
{
drawStocking ();
finishText ();
}
if (key == 'h')
{
drawHollybasket ();
finishText ();
}
// finished
else if (key == ' ')
{
toggleSnow = true;
}
}
void background1()
{
background (203, 125, 125);
}
void background2 ()
{
background (88, 114, 203);
}
void drawGrid ()
{
stroke (100);
line (0, sectionH*3, width, sectionW*3);
line (sectionW,0, sectionW, height);
}
void drawFireplace ()
{
//rect (500, 250, 275, 200); //used to locate fireplace
image (fireplace2, width*.7, height*.3125, width*.31, height*.25);
}
void windowText ()
{
fill (255, 252, 15);
textFont (f1, 15);
text ("Press 'r' for red curtains.\nPress 'b' for blue curtains", offSet, height*.15);
}
void drawWindowblue ()
{
// rect (width*.28, height*.05, 175, 175); //used to locate window
image (windowblue, width*.275, height*.01, width*.22, height*.3);
}
void drawWindowred ()
{
image (windowred, width*.275, height*.01, width*.22, height*.3);
}
void fireText ()
{
fill (255, 252, 15);
textFont (f1, 15);
text ("Press 'c' for Candles.\nPress 't' for Stocking & Bear.\nPress 'h' for Holly Basket", offSet, height*.50);
}
void drawStocking ()
{
//rect (580, 280, 75, 100); //used to find general stocking location
//rect (700, 260, 75, 100); //used to find general stocking location
image (stocking, width*.715, height*.34, width*.1, height*.13);
image (stocking, width*.860, height*.325, width*.1, height*.13);
}
void drawCandles ()
{
image (candles, width*.715, height*.235, width*.1, height*.13);
image (candles, width*.860, height*.220, width*.1, height*.13);
}
void drawHollybasket ()
{
image (hollybasket, width*.715, height*.235, width*.1, height*.13);
image (hollybasket, width*.860, height*.220, width*.1, height*.13);
}
void drawTree ()
{
// rect (width*.25, height*.09, width*.625,height*.625);
// rect (270, 130, 360, 350); //general tree location
// rect (290, 130, 320, 350); //general tree next row up on tree
image (tree, width*.25, height*.09, width*.625,height*.625);
}
void treeTopText ()
{
fill (255, 252, 15);
textFont (f1, 15);
text ("Press 'a' for an Angel.\nPress 's' for a Star.", offSet, height*.40);
}
void drawStar ()
{
fill (235, 224, 20);
noStroke ();
triangle (width*.5375, height*.1125, width*.5875, height*.1125, width*.56, height*.15625);
triangle (width*.56, height*.0875, width*.5875, height*.14375, width*.5375, height*.14375);
}
void drawAngel ()
{
image (angel, width*.52, height*.075, width*.088, height*.088);
}
void bulbText ()
{
fill (255, 252, 15);
textFont (f1, 15);
text ("Press 'p' for purple pattern.\nPress 'd' for red.\nPress 'y' for Yellow.\nPress 'o' for Orange", offSet, height*.25);
}
// there are four different bulb ornaments, their sizes vary slightly
// idea to change size for different colors to provide a little difference between options
void drawBulbpattern ()
{
for (int i=0; i < row9.length; i++)
{
image (bulbpattern, row9[i], height*.55, width*.013, width*.013);
}
for (int i=0; i < row8.length; i++)
{
image (bulbpattern, row8[i], height*.50, width*.013, width*.013);
}
for (int i=0; i < row7.length; i++)
{
image (bulbpattern, row7[i], height*.45, width*.015, width*.015);
}
for (int i=0; i < row6.length; i++)
{
image (bulbpattern, row6[i], height*.38, width*.018, width*.018);
}
for (int i=0; i < row5.length; i++)
{
image (bulbpattern, row5[i], height*.33, width*.013, width*.013);
}
for (int i=0; i < row4.length; i++)
{
image (bulbpattern, row4[i], height*.30, width*.013, width*.013);
}
for (int i=0; i < row3.length; i++)
{
image (bulbpattern, row3[i], height*.25, width*.015, width*.015);
}
for (int i=0; i < row2.length; i++)
{
image (bulbpattern, row2[i], height*.225, width*.013, width*.013);
}
for (int i=0; i < row1.length; i++)
{
image (bulbpattern, row1[i], height*.20, width*.013, width*.013);
}
}
void drawBulbred ()
{
for (int i=0; i < row9.length; i++)
{
image (bulbred, row9[i], height*.55, width*.013, width*.013);
}
for (int i=0; i < row8.length; i++)
{
image (bulbred, row8[i], height*.50, width*.012, width*.012);
}
for (int i=0; i < row7.length; i++)
{
image (bulbred, row7[i], height*.45, width*.015, width*.015);
}
for (int i=0; i < row6.length; i++)
{
image (bulbred, row6[i], height*.38, width*.018, width*.018);
}
for (int i=0; i < row5.length; i++)
{
image (bulbred, row5[i], height*.33, width*.013, width*.013);
}
for (int i=0; i < row4.length; i++)
{
image (bulbred, row4[i], height*.30, width*.013, width*.013);
}
for (int i=0; i < row3.length; i++)
{
image (bulbred, row3[i], height*.25, width*.015, width*.015);
}
for (int i=0; i < row2.length; i++)
{
image (bulbred, row2[i], height*.225, width*.013, width*.013);
}
for (int i=0; i < row1.length; i++)
{
image (bulbred, row1[i], height*.20, width*.013, width*.013);
}
}
void drawBulbyellow ()
{
for (int i=0; i < row9.length; i++)
{
image (bulbyellow, row9[i], height*.55, width*.023, width*.023); //bulbD why doesn't it work?
}
for (int i=0; i < row8.length; i++)
{
image (bulbyellow, row8[i], height*.50, width*.023, width*.023);
}
for (int i=0; i < row7.length; i++)
{
image (bulbyellow, row7[i], height*.45, width*.025, width*.025);
}
for (int i=0; i < row6.length; i++)
{
image (bulbyellow, row6[i], height*.38, width*.028, width*.028);
}
for (int i=0; i < row5.length; i++)
{
image (bulbyellow, row5[i], height*.33, width*.023, width*.023);
}
for (int i=0; i < row4.length; i++)
{
image (bulbyellow, row4[i], height*.30, width*.023, width*.023);
}
for (int i=0; i < row3.length; i++)
{
image (bulbyellow, row3[i], height*.25, width*.025, width*.025);
}
for (int i=0; i < row2.length; i++)
{
image (bulbyellow, row2[i], height*.225, width*.023, width*.023);
}
for (int i=0; i < row1.length; i++)
{
image (bulbyellow, row1[i], height*.20, width*.023, width*.023);
}
}
void drawBulborange ()
{
for (int i=0; i < row9.length; i++)
{
image (bulborange, row9[i], height*.55, width*.023, width*.023); //bulbD why doesn't it work?
}
for (int i=0; i < row8.length; i++)
{
image (bulborange, row8[i], height*.50, width*.023, width*.023);
}
for (int i=0; i < row7.length; i++)
{
image (bulborange, row7[i], height*.45, width*.025, width*.0215);
}
for (int i=0; i < row6.length; i++)
{
image (bulborange, row6[i], height*.38, width*.028, width*.028);
}
for (int i=0; i < row5.length; i++)
{
image (bulborange, row5[i], height*.33, width*.023, width*.0213);
}
for (int i=0; i < row4.length; i++)
{
image (bulborange, row4[i], height*.30, width*.023, width*.023);
}
for (int i=0; i < row3.length; i++)
{
image (bulborange, row3[i], height*.25, width*.025, width*.025);
}
for (int i=0; i < row2.length; i++)
{
image (bulborange, row2[i], height*.225, width*.023, width*.023);
}
for (int i=0; i < row1.length; i++)
{
image (bulborange, row1[i], height*.20, width*.023, width*.023);
}
}
void finishText ()
{
fill (255, 15, 7);
textFont (f1, 25);
text ("Thank You for Decorating the Home", sectionW+10, height*.80);
text ("Press [space bar] to finish\nClose screen when done", sectionW+10, height*.85);
}
void drawSnow ()
{
for (int i=0; i < xValues.length; i++)
{
fill (255);
ellipse (xValues[i], yValues[i], width*.01875, height*.01875);
}
}
void moveSnow ()
{
for (int i=0; i < xValues.length; i++)
{
yValues[i] += deltaYs[i];
}
}
void repeatSnow ()
{
for (int i=0; i < xValues.length; i++)
{
if ( yValues[i] >= height)
{
yValues[i] = (int) random (-100, 200);
}
}
}
void fadeScreen ()
{
fill(0,0,0, 10);
rect(0,0,width, height);
}
void drawSnowman ()
{
fill (255);
ellipseMode(CENTER);
//body
ellipse (width/2, height*.75, width/4, height/4);
ellipse (width/2, height*.53, width/5, height/5);
ellipse (width/2, height*.35, width/6, height/6);
rectMode(CENTER);
//hat
fill (255, 0, 0);
rect (width/2, height*.225, width*.0625, height*.1);
stroke (0);
strokeWeight (5);
line ((width/2)-50, height*.275, (width/2)+50, height*.275);
//mouth
line ((width/2)-18, height*.4, (width/2)+18, height*.4);
//eyes
ellipse ((width/2)-20, height*.32, width*.006, height*.006);
ellipse ((width/2)+20, height*.32, width*.006, height*.006);
//buttons on body
ellipse (width/2, height*.48, width*.006, height*.006);
ellipse (width/2, height*.52, width*.006, height*.006);
ellipse (width/2, height*.57, width*.006, height*.006);
//nose
fill (277, 91, 23);
strokeWeight (1);
ellipse (width/2, height*.36, width*.01, height*.01);
//arms
stroke (142, 74, 40);
strokeWeight (3);
line ((width/2)-60, height*.5, (width/2)-120, height*.6);
line ((width/2)+60, height*.5, (width/2)+120, height*.6);
stroke (0);
//message
fill (65, 222, 50);
textFont (f1, 60);
text ("Happy Holidays!!", width/4, height*.125);
}