본문 바로가기
svg

svg paper.js epicycloid : circles

by peach1227 2024. 3. 21.
<!doctype html>
<html>
<head>

<style>
html,
body {
    height: 100%;
}
canvas,svg {
width:800px;
height:800px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.12.17/paper-full.js"></script>
<script type="text/paperscript" canvas="myCanvas">



var R=4,r=1,rad=0;
//R=Math.floor(2+Math.random()*8);

var largeCircle= new Path.Circle({center:[400,400],radius:R*50,strokeColor:"blue"});
var smallCircle= new Path.Circle({center:[400+(R+r)*50,400],radius:r*50,strokeColor:"red"});


function onFrame(event){

var cnt=event.count;
if(cnt==628){view.onFrame=null;}
rad +=.01;
var x=400+((R+r)*Math.cos(rad)-r*Math.cos((R+r)/r*rad))*50;
var y=400-(((R+r)*Math.sin(rad)-r*Math.sin((R+r)/r*rad))*50);

var path= new Path.Circle({center:[x,y],radius:3,strokeColor:"red"});
path.fillColor="red";

smallCircle.position =[400+(R+r)*Math.cos(rad)*50,400-(R+r)*Math.sin(rad)*50];


}

</script>

</head>
<body>

<canvas id="myCanvas" resize></canvas>
<svg id="svg1"></svg>
</body>
</html>

반응형