//Sarah Yae
//smyae@andrew.cmu.edu
//Section B
//Project 10
var nails = [];
function setup() {
createCanvas(400, 300);
//Creation of initial nail polish
for (var i = 0; i < 10; i++) {
var rx = random(width);
nails[i] = makeNails(rx);
}
frameRate(30);
}
function draw() {
background(color(255,231,218));
displayText();
updateAndDisplayNails();
removeOldNails();
addNewNails();
//Tabletop
noStroke();
fill(230);
rect(0, 260, width, height);
}
function displayText() {
textSize(25);
textAlign(CENTER);
textStyle(BOLD);
fill("Salmon");
text("Welcome to Sarah's Nail Salon!", width / 2, 50);
}
function updateAndDisplayNails() {
for (var i = 0; i < nails.length; i++) {
nails[i].move();
nails[i].display();
}
}
function removeOldNails() {
var nailskeep = [];
for (var i = 0; i < nails.length; i++) {
if (nails[i].x + 50 > 0) {
nailskeep.push(nails[i]);
}
}
nails = nailskeep;
}
function addNewNails() {
var chance = 0.01;
if (random(0,1) < chance) {
nails.push(makeNails(width));
}
}
function nailsMove() {
this.x += this.speed;
}
function nailsDisplay() {
var nailbody = 90;
var nailtip = 60;
noStroke();
push();
translate(this.x, height - 40);
//Body of Nail Polish
fill(this.randomColor);
rect(this.x, -nailbody, this.bodybreadth, nailbody);
//Tip of Nail Polish
fill(80);
rect(this.x + 7, -nailbody - nailtip, this.tipbreadth, nailtip);
pop();
}
function makeNails(birthlocationX) {
var nails = {x: birthlocationX,
bodybreadth: 40,
tipbreadth: 25,
speed: -1.0,
randomColor: color(random(255), random(255), random(255)),
move: nailsMove,
display: nailsDisplay}
return nails;
}
This project was difficult to tackle; I did not have any idea on which animation I wanted to do, nor did I have too much technical knowledge on where to start. However, I got inspired from my friend’s nail kit. My friends and I would go to her room and do each other’s nails sometimes- and I thought it would be a cool idea to display different nail polishes that circulate. For the code, I referred to the template to get initial ideas on where to develop my code. Overall, this was an interesting project!