Pulsating Points with CindyJS

https://github.com/CindyJS/CindyJS/issues/722

by Kajus

HTML

<script src="https://cindyjs.org/dist/latest/Cindy.js"></script>
<script src="https://cindyjs.org/dist/v0.8.7/Cindy.js"></script>
<div id="cscanvas-beliebiges-dreieck">
</div>

JavaScript

var cdy = CindyJS({

		scripts: {
			init: `
polar(alpha) := (cos(alpha),sin(alpha));

anglemark(P, degstart, degend, r, line, fillcolor, fillalpha) := (
	// degstart can be number or number°, convert - https://github.com/CindyJS/CindyJS/issues/801

	zA = P + polar(degstart);
	zB = P + polar(degend);
	d = det(P,zA,zB);
	shape = if(
		d~=0,
		halfplane(join(P,zA), P+[ [0,-1], [1,0] ]*(zA-P)),
		if(
			d>0,
			halfplane(join(P,zA),zB)~~halfplane(join(P,zB),zA),
			screen()--(halfplane(join(P,zA),zB)~~halfplane(join(P,zB),zA))
		)
	)~~circle(P,r);
	fill(shape, alpha->fillalpha, color->fillcolor);
	if(line, draw(shape));
);

getrotation(rpA, rpB, rpC) := (
	rotangle = 0;
	
	// get orientation
	if(rpB.y < rpC.y, 
			
	);
	rotangle;
);

linea = 0;
lineb = 0;
linec = 0;

anglea = 50°;
angleb = 50°;
anglec = 80°;
angler = 0.7;
anglepos = (4,4);

circumference = 0;

// colors
cblack = (0.1,0.1,0.1);
cblue = (0.1,0.1,1.0);
cred = (1.0,0.1,0.1);
cgreen = (0.1,1.0,0.1);
cbluelight = (0.4,0.4,1.0);
credlight = (1.0,0.4,0.4);
cgreenlight = (0.4,1.0,0.4);
`,
			draw: `

// calculate length of all lines via Pythagoras
linec = sqrt( pow(B.x-A.x, 2) + pow(B.y-A.y, 2) ); // lineAB
linea = sqrt( pow(C.x-B.x, 2) + pow(C.y-B.y, 2) ); // lineBC
lineb = sqrt( pow(C.x-A.x, 2) + pow(C.y-A.y, 2) ); // lineAC
// print(lineAB+" / "+lineBC+" / "+lineAC);

circumference = linea + lineb + linec;

// calculate angles via Kosinussatz
anglea = arccos( (-pow(linea,2) + pow(lineb,2) + pow(linec,2)) / ( 2*lineb*linec ) );
angleb = arccos( (-pow(lineb,2) + pow(linea,2) + pow(linec,2)) / ( 2*linea*linec ) );
anglec = arccos( (-pow(linec,2) + pow(linea,2) + pow(lineb,2)) / ( 2*linea*lineb ) );

// calculate area
flache = (A.x * B.y - B.x * A.y) + (B.x * C.y - C.x * B.y) + (C.x * A.y - A.x * C.y);

// calculate centroid
centroid = [ (A.x+B.x+C.x)/3, (A.y+B.y+C.y)/3];


// top right angle set
anglemark(anglepos, 0, anglea, angler, true, cbluelight, 1);
anglemark(anglepos, anglea, anglea+angleb, angler,...