fractalkitty looking for math? fractalkitty.com

codepen challenges

astroidToy

#trig#color#interactive#animation#accumulates#math#codepen-challenge

astroid

let a = 200;
let px = [];
let py = [];
let n = 1;
function setup() {
	createCanvas(windowWidth, windowHeight);
	noStroke();
	angleMode(DEGREES);
	background(0);
	px[0] = 0;
	py[0] = 0;
	colorMode(HSB);
	noStroke();
}
function draw() {
	translate(width / 2, height / 2);
	t = width * 8 * sin(frameCount / 5) * sin(frameCount / 5);

	for (let i = 0; i < n; i++) {
		push();
		translate(px[i], py[i]);
		rotate(frameCount);
		astroid();
		pop();
	}
}
function astroid() {
	g = 1;
	for (let i = 0; i <= 360; i++) {
		a = t / 10 - 20;
		x = a * pow(cos(i), 3);
		y = a * pow(sin(i), 3);
		z = 0;
		fill(90 * sin(i / g) * sin(i / g) + 180, 100, 360);
		circle(x, y, 2);
		fill(90 * cos(i / g) * cos(i / g) + 180, 100, 360);
		circle(x, y, 1);
	}
}

function mousePressed() {
	if (n < 11) {
		px[n] = mouseX - width / 2;
		py[n] = mouseY - height / 2;
		n++;
	} else {
		n = 1;
		background(0);
	}
}