Skip to content

Instantly share code, notes, and snippets.

@naoyashiga
Last active August 29, 2015 13:57
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 naoyashiga/9578171 to your computer and use it in GitHub Desktop.
Save naoyashiga/9578171 to your computer and use it in GitHub Desktop.
A Pen by naoyashiga.
<script type="text/javascript" src="http://jsrun.it/assets/1/X/K/K/1XKKp"></script>
<script type="text/paperscript" canvas="myCanvas">
function Ball(point,speed){
this.path = new Path.Circle({
center:point,
radius:5,
fillColor:"white"
});
this.speed = speed;
}
function Star(){
this.center = view.center;
this.points = 5;
this.radius1 = 50;
this.radius2 = 100;
this.path = new Path.Star(this.center, this.points, this.radius1, this.radius2);
this.path.strokeColor = 'black';
this.path.strokeWidth = 25;
this.path.rotate(36);
}
var balls = [],
stars = [],
numBalls = 10,
numStars = 3;
for(var i = 0;i < numStars;i++){
stars.push(new Star());
stars[i].path.scale(i + 1);
for(var j = 0;j < numBalls;j++){
balls.push(new Ball(stars[i].path.getPointAt(0),0.1 * (j + 1)));
}
}
function onFrame(event){
for(var i = 0;i < numStars;i++){
for(var j = 0;j < numBalls;j++){
offset = stars[i].path.length * (event.count * balls[i * numBalls + j].speed % 100) / 100;
point = stars[i].path.getPointAt(offset);
balls[i * numBalls + j].path.position = point;
}
}
}
</script>
<canvas id="myCanvas" resize></canvas>
body {
background: #fff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment