fractalkitty looking for math? fractalkitty.com

Mathober 2026 ยท day 5, Inellipse

Inellipse

#random#trig#vectors#interactive#animation#math#geometry#spiral#mathober

kiss1kiss2kiss3point1point2point3slopeinellipse


let kiss1,kiss2,kiss3
let point1,point2,point3
let t=0

function setup() {
	theSizeThatFits = min(windowWidth, windowHeight)*0.9
	theCanvasThatIsFilled=createCanvas(theSizeThatFits, theSizeThatFits);
	background(20,70,80);
	strokeWeight(2);
	describe("a spiral of triangles that all have three ellipses inside kissig the edges")
	stroke(200,240,255)
	point1 = createVector(random(width/3,2*width/3),20)
	point2 = createVector(20,random(width/3,2*width/3))
	point3 = createVector(width-20,random(width/3,2*width/3))
	
	m1 = slope(point1,point2)
	m2 = slope(point1,point3)
	m3 =slope(point2,point3)


	
	
}
function draw() {
	translate(width/2,height/2)
	
	
	t+=0.005
	background(20,70,80,50);
	
	for(let m = 0;m<6;m++){
		push()
	noFill()
	for(let n = 0;n<6;n++){
		scale(m/4 +m/10*sin(t))
		rotate(2*PI/6*m+t/4)
		push()
		stroke(200 - m*10-n*10,240- m*10-n*10,255- m*10-n*10)
			rotate(n*2*PI/6)
			triangle(point1.x, point1.y,point2.x, point2.y,point3.x, point3.y)
			x1 = point2.x + 20+ (point1.x - point2.x - 40)*abs(sin(t))
			y1 = m1*(x1 - point1.x) + point1.y
			kiss1 = createVector(x1,y1)
			circle(kiss1.x, kiss1.y,2)
			x2 = point1.x + 20+ (point3.x - point1.x - 40)*abs(sin(t/2))
			y2 = m2*(x2 - point1.x) + point1.y
			kiss2 = createVector(x2,y2)
			circle(kiss2.x, kiss2.y,2)
			x3 = point2.x + 20+ (point3.x - point2.x - 40)*abs(sin(t/3))
			y3 = m3*(x3 - point3.x) + point3.y
			kiss3 = createVector(x3,y3)
			circle(kiss3.x, kiss3.y,2)
			inellipse(kiss1,kiss2,point1,point2,point3)
			 inellipse(kiss3,kiss2,point3,point2,point1)
			inellipse(kiss3,kiss1,point2,point3,point1)
		pop()
	
	}
	pop()
	}
	
	
}

function slope(p1,p2){
	return((p1.y-p2.y)/(p1.x-p2.x))
}

function inellipse(k1,k2,A,B,C){
	si = (k1.x - A.x)/(B.x - A.x);
	ti = (k2.x - A.x)/(C.x - A.x);
	k = sqrt((1-si)*(1-ti))
	beginShape()
	for (let h = -HALF_PI; h <= HALF_PI; h += PI / 200) {
	   c = cos(h)
		sn = sin(h);   
	   den = c*c - 2*k*sn*c + sn*sn;
	  vertex(
	    (k1.x*c*c + k2.x*sn*sn - 2*k*sn*c*A.x) / den,
	    (k1.y*c*c + k2.y*sn*sn - 2*k*sn*c*A.y) / den
	  );
}
	endShape()
}

function keyPressed(){
	if(keyCode===83){
		save(theCanvasThatIsFilled,"inellipse","png")
	}
}