MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / draw

Function draw

assets/js/cardioid.js:24–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22}
23
24function draw() {
25
26 //to clear the canvas
27 ctx.fillStyle = "#262626";
28 ctx.fillRect(-w / 2, -h / 2, w, h);
29
30 ctx.lineWidth = '0.6';
31
32 //to draw points and line
33 for (let i = 0; i < total; i++) {
34
35 var angle = 2 * Math.PI / total * i + Math.PI;
36 var angle1 = 2 * Math.PI / total * ((i * factor) % total) + Math.PI;
37
38 var x = r * Math.cos(angle);
39 var y = r * Math.sin(angle);
40 var x1 = r * Math.cos(angle1);
41 var y1 = r * Math.sin(angle1);
42
43 //to draw points this can be skipped, still a cardiod will be drawn
44 ctx.beginPath();
45 ctx.fillStyle = "white";
46 ctx.arc(x, y, 2, 0, 2 * Math.PI);
47 ctx.fill();
48 ctx.closePath();
49
50 //to draw required lines
51 ctx.beginPath();
52 ctx.strokeStyle = "cyan";
53 ctx.moveTo(x, y);
54 ctx.lineTo(x1, y1);
55 ctx.stroke();
56 ctx.closePath();
57 }
58
59 factor += 0.008;
60 requestAnimationFrame(draw);
61
62}

Callers 1

cardioid.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected