Move the mouse to bring Pikachu near the pokéballs, and watch them converge and grow!
Also, click the mouse to change the berry floating around Pikachu’s head!
tcliu-openproject-03
var pokeWidth = 50;
var buttonW = pokeWidth - 40;
var yStart = 350;
var pikachuW = 100;
var pikachuH = 80;
var pikachuX = 300;
var pikachuY = 200;
var eyeW = 15;
var eyeHighlight = 5;
var noseW = 10;
var mouthW = 15;
var mouthH = 30;
var cheekW = 17;
var berryW = 25;
var berryH = 20;
var berryStem = 20;
var berryDist = 70;
var berryR = 224;
var berryG = 78;
var berryB = 58;
var colorR = 51;
var colorG = 91;
var colorB = 0;
var angle = 0;
function setup() {
createCanvas(600, 480);
}
function draw() {
var mouseA = height - mouseY - pokeWidth;
var pbWidth = height - mouseA;
var colorR1 = min(mouseY + colorR, 252);
var colorG1 = min(mouseY + colorG, 194);
var colorB1 = min(mouseY + colorB, 0);
background(colorR1, colorG1, colorB1);
if (pbWidth >= 200) {
pbWidth = 200;
}
push();
fill("white");
noStroke();
translate(width / 6 + min(max(mouseY, 0), width / 3), yStart);
rotate(radians(angle));
ellipseMode(CENTER);
ellipse(0, 0, pbWidth, pbWidth);
pop();
angle = angle + 0.5;
push();
fill("red");
noStroke();
translate(width / 6 + min(max(mouseY, 0), width / 3), yStart)
rotate(radians(angle));
arc(0, 0, pbWidth, pbWidth, PI, TWO_PI);
pop();
angle = angle + 0.5;
push();
fill("white");
strokeWeight(3);
translate(width / 6 + min(max(mouseY, 0), width / 3), yStart);
rotate(radians(angle));
ellipseMode(CENTER);
ellipse(0, 0, pbWidth / 6, pbWidth / 6);
pop();
angle = angle + 0.5;
push();
fill("white");
noStroke();
translate(width / 2, yStart);
rotate(radians(angle));
ellipseMode(CENTER);
ellipse(0, 0, pbWidth, pbWidth);
pop();
angle = angle + 0.5;
push();
fill("red");
noStroke();
translate(width / 2, yStart);
rotate(radians(angle));
arc(0, 0, pbWidth, pbWidth, PI, TWO_PI);
pop();
angle = angle + 0.5;
push();
fill("white");
strokeWeight(3);
translate(width / 2, yStart);
rotate(radians(angle));
ellipseMode(CENTER);
ellipse(0, 0, pbWidth / 6, pbWidth / 6);
pop();
angle = angle + 0.5;
push();
fill("white");
noStroke();
translate(5 * width / 6 - min(max(mouseY, 0), width / 3), yStart);
rotate(radians(angle));
ellipseMode(CENTER);
ellipse(0, 0, pbWidth, pbWidth);
pop();
angle = angle + 0.5;
push();
fill("red");
noStroke();
translate(5 * width / 6 - min(max(mouseY, 0), width / 3), yStart);
rotate(radians(angle));
arc(0, 0, pbWidth, pbWidth, PI, TWO_PI);
pop();
angle = angle + 0.5;
push();
fill("white");
strokeWeight(3);
translate(5 * width / 6 - min(max(mouseY, 0), width / 3), yStart);
rotate(radians(angle));
ellipseMode(CENTER);
ellipse(0, 0, pbWidth / 6, pbWidth / 6);
pop();
angle = angle + 0.5;
push();
translate(mouseX - pikachuX, mouseY - pikachuY);
fill(252, 239, 0);
noStroke();
ellipse(pikachuX, pikachuY, pikachuW, pikachuH);
triangle(pikachuX - 5 * pikachuW / 8, pikachuY - pikachuH, pikachuX - pikachuW / 4, pikachuY - pikachuH / 2.5,
pikachuX - pikachuW / 2.2, pikachuY - pikachuH / 5);
triangle(pikachuX + 5 * pikachuW / 8, pikachuY - pikachuH, pikachuX + pikachuW / 4, pikachuY - pikachuH / 2.5,
pikachuX + pikachuW / 2.2, pikachuY - pikachuH / 5);
fill("black");
triangle(pikachuX - 5 * pikachuW / 8, pikachuY - pikachuH, pikachuX - pikachuW * 0.5, pikachuY - pikachuH * 0.8,
pikachuX - pikachuW * 0.56, pikachuY - pikachuH * 0.7);
triangle(pikachuX + 5 * pikachuW / 8, pikachuY - pikachuH, pikachuX + pikachuW * 0.5, pikachuY - pikachuH * 0.8,
pikachuX + pikachuW * 0.56, pikachuY - pikachuH * 0.7);
ellipse(pikachuX - pikachuW / 5, pikachuY, eyeW, eyeW);
ellipse(pikachuX + pikachuW / 5, pikachuY, eyeW, eyeW);
fill("white");
ellipse(pikachuX - pikachuW / 5, pikachuY - pikachuH * 0.05, eyeHighlight, eyeHighlight);
ellipse(pikachuX + pikachuW / 5, pikachuY - pikachuH * 0.05, eyeHighlight, eyeHighlight);
fill(227, 45, 25);
ellipse(pikachuX - pikachuW / 3, pikachuY + pikachuH / 5, cheekW, cheekW);
ellipse(pikachuX + pikachuW / 3, pikachuY + pikachuH / 5, cheekW, cheekW);
fill("black");
arc(pikachuX, pikachuY + pikachuH / 8, noseW, noseW / 2, TWO_PI, PI);
fill("pink");
arc(pikachuX, pikachuY + pikachuH / 5, mouthW, mouthH, TWO_PI, PI);
pop();
push();
fill(berryR, berryG, berryB);
noStroke();
translate(mouseX, mouseY);
rotate(radians(angle));
ellipse(berryDist, berryDist, berryW, berryH);
fill(16, 196, 0);
arc(berryDist, berryDist * 1.25, berryStem, berryStem / 1.1, PI, TWO_PI);
pop();
angle = angle + 1 / 100;
}
function mousePressed() {
berryR = random(0, 255);
berryG = random(0, 255);
berryB = random(0, 255);
}
I grew up watching and playing Pokémon, and one of the random tidbits about the original cartoon that stuck with me was how pokéballs expand when they’re removed from the trainer’s belt. I built my program to mimic this dynamic movement; when you move the Pikachu (set to follow the mouse around) towards the pokeballs, they expand while rotating. They also converge into one as an inverse function of the mouse movement to represent Pikachu’s singular pokéball. In addition, the background changes color from a forest green to a warm gold as the mouse moves downward. I was very happy with how my project turned out, as its fun, lighthearted, meaningful, and engagingly dynamic.
The 5 dynamic elements I utilized are having Pikachu follow the mouse, making the pokéballs expand, having them converge, making the background change color, and the rotation of the pokéballs and berry. As an added interactive component, clicking on the berry causes it to change color.