xxxxxxxxxx
84
//Dragonball's functions (Used ChatGPT to help achieve the ideal functions from Line 2-49, Prompt: Help me achieve the function of an interactable Rim Light and Zoom on click function with the dragonball.)
let scaleFactor = 1; // Start at normal size
let growthSpeed = 0.02; // Speed of zooming
let growing = false; // Only zoom when clicked
function setup() {
createCanvas(600, 400);
}
function draw() {
background(30);
// Apply scaling transformation
translate(width / 2, height / 2);
scale(scaleFactor);
translate(-width / 2, -height / 2);
drawDragonBall(width / 2, height / 2, mouseX, mouseY);
// Increase scale only if growing is true
if (growing) {
scaleFactor += growthSpeed;
// Reset when it grows too large
if (scaleFactor > 3) {
scaleFactor = 1; // Reset to normal size
growing = false; // Stop growing until next click
}
}
}
function mousePressed() {
growing = true; // Start growing when the mouse is clicked
}
function drawDragonBall(cx, cy, tx, ty) {
let ballSize = 200;
let lightSize = 50;
// Position of Rim Light
let angle = atan2(ty - cy, tx - cx);
let lightX = cx + cos(angle) * ballSize * 0.3;
let lightY = cy + sin(angle) * ballSize * 0.3;
// Calculate distance between the center of the ball and the rim light
let distance = dist(cx, cy, lightX, lightY);
// Adjust stroke based on distance from rim light (dynamic stroke weight)
let strokeWeightValue = map(distance, 0, ballSize * 0.5, 7, 2);
// Dragon Ball Color
fill(255, 140, 0);
stroke(255, 100, 0);
strokeWeight(strokeWeightValue);
ellipse(cx, cy, ballSize);
// Rim lighting
noStroke();
fill(255, 200, 100, 150);
ellipse(lightX, lightY, lightSize);
// Evenly Aligned Stars
fill(255, 50, 50);
drawStar(cx - 40, cy - 20, 10, 20, 5);
drawStar(cx - 40, cy + 30, 10, 20, 5);
drawStar(cx + 40, cy - 20, 10, 20, 5);
drawStar(cx + 40, cy + 30, 10, 20, 5);
}
function drawStar(x, y, radius1, radius2, npoints) {
let angle = TWO_PI / npoints;
let halfAngle = angle / 2.0;
beginShape();
for (let a = 0; a < TWO_PI; a += angle) {
let sx = x + cos(a) * radius2;
let sy = y + sin(a) * radius2;
vertex(sx, sy);
sx = x + cos(a + halfAngle) * radius1;
sy = y + sin(a + halfAngle) * radius1;
vertex(sx, sy);
}
endShape(CLOSE);
}