dg.js weel animation example - Djordje Rakonjac / december, 2015

Weel animation example. Colors are randomly choosen at every script envoke.

dg.js example code

		var canvas = dg.Canvas("testcanvas", { border: "1px solid #ccc"});
		var axes = dg.Axes([canvas.width() / 4, canvas.height() / 1.5]).hide(false);
		
		var r = 3;
		var o = dg.Point([3,3]).label("O").color("rgb(255, 0, 0)").size(10);
		var p = dg.Point([3, 0]).label("P");
		var c = dg.Circle(o,p);
		
		var n = 8;
		var t = 2 * Math.PI / n;
		var k = -Math.PI;
		var lines = [];
		for(var i = 0; i < n; i++) {

			lines.push(dg.Line(o, dg.Point([r * Math.cos(k) + o.x(), r * Math.sin(k) + o.y() ]))
			.color(dg.color.rand()));
			lines[i].p1().color(dg.color.rand());
			k = t * i;
		}
		
		var interval = setInterval(animate, 30);
		k = -Math.PI;
		var step = 0.01;
		function animate() {
			
			for(var i = 0; i < n; i++) {
				
				lines[i].p1().setX(r * Math.cos(step + i * t) + o.x());
				lines[i].p1().setY(r * Math.sin(step + i * t) + o.y());
			}
			step -= 0.01;
		}
					
					
copyright 2016, Djordje Rakonjac