Skip to content

Instantly share code, notes, and snippets.

@sabha
Created April 27, 2018 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sabha/9f9b8c18d71c91f19652e382adf93251 to your computer and use it in GitHub Desktop.
Save sabha/9f9b8c18d71c91f19652e382adf93251 to your computer and use it in GitHub Desktop.
Dynamic
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="600" height="600" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
function circle(x,y,r){
ctx.beginPath();
ctx.arc(x,y,r,0,2*Math.PI);
ctx.stroke();
}
function line(p1,p2){
ctx.beginPath();
ctx.moveTo(p1.x,p1.y);
ctx.lineTo(p2.x,p2.y);
ctx.stroke();
}
function color() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
var w = c.width, h = c.height, cx = w/2, cy = h/2;
var r1 = 10, r2 = r1, angle = 0 , angle2 = 0, lv = .5 ;
ctx.strokeStyle = color();
setInterval(function(){
//ctx.clearRect(0,0,w,h);
ctx.lineWidth=lv;
//circle(cx,cy,r1);
var cx1 = (r2*Math.cos(angle*Math.PI/180)) + cx, cy1 = (r2*Math.sin(angle*Math.PI/180)) + cy ;
//circle(cx1,cy1,r2);
angle+=10;
if(angle === 361) angle = 0;
//line({x: cx, y:cy}, {x: cx1, y:cy1});
angle2+=150;
line({x: cx1, y:cy1}, {
x: cx1+(r2*Math.cos(angle2-10*Math.PI/180)),
y: cy1+(r2*Math.sin(angle2-10*Math.PI/180))
});
line({x: cx1-10, y:cy1-10}, {
x: cx1+((r2*40)*Math.cos(angle2-10*Math.PI/180)),
y: cy1+((r2*40)*Math.sin(angle2-10*Math.PI/180))
});
//lv -= 2;
//if(lv <= .5) lv = .5;
}, .1)
</script>
</body>
</html>
@sabha
Copy link
Author

sabha commented Apr 27, 2018

screen shot 2018-04-27 at 3 16 52 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment