javascript - Canvas rotating particles -
do might know how make kind of animation. how managed see more word canvas javascript technique.
thank you
here's single arc on blue background going around , around. achieved drawing white arc on blue background.
fiddle:
https://jsfiddle.net/07d69v39/1/
//coordinates of rectangle var xp = 125; var yp = 125; var radius = 45; //how far move arc each time: var anglestep = math.pi * 0.1; //how move arc: var steptime = 50; var currentstep = 0; function dodraw() { var can = document.getelementbyid("mycanvas"); can.width = 250; can.height = 250; var context = can.getcontext("2d"); //erase canvas painting blue: context.fillstyle="#0000ff"; context.fillrect(0, 0, 250, 250); //set drawing color white: context.strokestyle="#ffffff"; context.linewidth=5; context.arc(xp, yp, radius, 0 + currentstep, 1.5*math.pi + currentstep); context.stroke(); //make sure maintain currentstep angle doesn't overflow: currentstep = currentstep + anglestep; if (currentstep>math.pi * 2) { currentstep = currentstep - math.pi * 2; } //wait, , call function again animate: settimeout(function() { dodraw(); }, steptime); } dodraw();
to complete effect, need multiple concentric arcs, traveling in opposite directions:
i placed values individual arc behavior in circles[] array:
https://jsfiddle.net/07d69v39/3/
//coordinates of rectangle var xp = 125; var yp = 125; var circles = [ { radius: 45, step: 0, direction: true, speed: math.pi * 0.1, }, { radius: 42, step: 0, direction: false, speed: math.pi * 0.05 }, { radius: 39, step: 0, direction: true, speed: math.pi * 0.07 }, { radius: 36, step: 0, direction: false, speed: math.pi * 0.02 }, { radius: 33, step: 0, direction: true, speed: math.pi * 0.06 }, { radius: 30, step: 0, direction: false, speed: math.pi * 0.04 } ]; //how move arc: var steptime = 50; function dodraw() { var can = document.getelementbyid("mycanvas"); can.width = 250; can.height = 250; var context = can.getcontext("2d"); context.imagesmoothingenabled= true; //erase canvas painting blue: context.fillstyle="#0000ff"; context.fillrect(0, 0, 250, 250); //set drawing color white: context.strokestyle="#ffffff"; context.linewidth = 4; (var = 0; i<circles.length;i++) { var arc = circles[i]; maintainarc(context, arc); } //wait, , call function again animate: settimeout(function() { dodraw(); }, steptime); } function maintainarc(context, arc) { var radius = arc.radius; var step = arc.step; context.beginpath(); context.arc(xp, yp, radius, 0 + step, 1.5*math.pi + step); context.stroke(); //maintain step angle differently clockwise , counter clockwise if (arc.direction) { step = step + arc.speed; if (step>math.pi * 2) { step = step - math.pi * 2; } } else { step = step - arc.speed; if (step<math.pi * 2) { step = step + math.pi * 2; } } arc.step = step; } dodraw();
what's missing artistic flare make revolving circles align 'c' @ proper moment. see 'c' in example provided fades out page load completes. not that.
Comments
Post a Comment