fractalkitty looking for math? fractalkitty.com

codepen challenges

dragonflyVortex

#trig#interactive#animation#math#symmetry#animals#codepen-challenge

dragonflywing

let n = 9;
function setup() {
	createCanvas(720, 720);
	background(250);
	strokeWeight(0.5);
	angleMode(DEGREES);
}
function draw() {
	background(20, 10, 5);
	translate(width / 2, height / 2);
	push();
	t = frameCount / 10;
	rotate(-t);
	for (let j = 0; j < 8; j++) {
		for (let i = 0; i < n; i++) {
			push();
			scale(j * 0.15, j * 0.15);
			rotate((360 / n) * i + j * 10);
			dragonfly(-50 + j * 20 - 10 * sin(t * j + t * i));
			pop();
		}
	}
	pop();
	push();
	translate(320, 300);
	scale(0.2, 0.2);

	dragonfly(1);
	pop();
}

function dragonfly(d) {
	translate(0, d);
	p = height / 3;
	strokeWeight(2);
	line(0, p - 120, 20, p - 118);
	line(0, p - 120, -20, p - 118);
	line(-27, p - 127, -20, p - 118);
	line(27, p - 127, 20, p - 118);
	line(5, p - 120, 17, p - 132);
	line(-5, p - 120, -17, p - 132);
	line(0, p - 120, 20, p - 95);
	line(0, p - 120, -20, p - 95);
	strokeWeight(1);
	line(-17, p - 132, -2, p - 136);
	line(17, p - 132, 2, p - 136);
	line(30, p - 90, 20, p - 95);
	line(-30, p - 90, -20, p - 95);
	strokeWeight(0.1);
	fill(30);
	ellipse(-2, p, 2, 10);
	ellipse(2, p, 2, 10);
	ellipse(0, p - 40, 6, 80);
	fill(26, 61, 72);
	ellipse(0, p - 102, 20, 40);
	fill(33, 159, 181);
	rect(-4, p - 12, 3, 8);
	rect(1, p - 12, 3, 8);
	rect(-4, p - 25, 3, 11);
	rect(1, p - 25, 3, 11);
	rect(-4, p - 40, 3, 13);
	rect(1, p - 40, 3, 13);
	rect(-4, p - 48, 3, 7);
	rect(1, p - 48, 3, 7);
	rect(-4, p - 62, 3, 13);
	rect(1, p - 62, 3, 13);
	rect(-4, p - 71, 3, 7);
	rect(1, p - 71, 3, 7);
	rect(-5, p - 79, 4, 7);
	rect(1, p - 79, 4, 7);
	ellipse(0, p - 90, 15, 10);
	rect(-6, p - 86, 6, 7);
	rect(0, p - 86, 6, 7);
	ellipse(0, p - 124, 25, 12);
	ellipse(0, p - 130, 12, 7);
	wing();
}

function wing() {
	fill(255, 255, 255, 150);
	push();
	rotate(12);
	translate(85, p - 100);
	ellipse(0, 0, 110, 15);
	pop();
	push();
	rotate(-12);
	translate(22, p - 105);
	ellipse(0, 0, 100, 15);
	pop();
	push();
	scale(-1, 1);
	rotate(12);
	translate(80, p - 100);
	ellipse(0, 0, 100, 15);
	pop();
	push();
	scale(-1, 1);
	rotate(-12);
	translate(22, p - 105);
	ellipse(0, 0, 100, 15);
	pop();
}

function mousePressed() {
	n = n + 1;
	if (n > 25) {
		n = 1;
	}
}