gibney.org
:
Technology
:
Javascript
:
Experiments
:
Flow
(Entry Nr. 373, by user 1 |
edit
)
<canvas id=canvas width=300 height=300 style='border: 1px solid #ff0000'></canvas> <script> Flow=new function() { this.Timer=0; }; // -------------------------------------------------------------------------------------------- Flow.LineRotor = function() {} Flow.LineRotor.InnerRotationSpeed=8; Flow.LineRotor.timeStep = function() { var x =150+Math.sin(Flow.Timer/300*3.14159*2)*100; var y =150+Math.cos(Flow.Timer/300*3.14159*2)*100; var px=Math.sin(Flow.Timer/300*3.14159*2*this.InnerRotationSpeed)*1; var py=Math.cos(Flow.Timer/300*3.14159*2*this.InnerRotationSpeed)*1; Flow.drawLine(x,y,px,py); } Flow.drawLine = function(x,y,px,py) { var r=50; var g=50; var b=50; for (i=0;i<300;i++) { this.ctx.fillStyle = "rgb("+r+", "+g+", "+b+")"; this.ctx.fillRect (x,y,1,1); x+=px; y+=py; } } // -------------------------------------------------------------------------------------------- Flow.timeStep = function() { Flow.LineRotor.timeStep(); this.Timer++; if (this.Timer<300) setTimeout("Flow.timeStep()",1); } Flow.start = function() { this.canvas = document.getElementById("canvas"); this.ctx = this.canvas.getContext("2d"); this.ctx.fillStyle = "rgb(0, 0, 100)"; this.x=1; this.LineRotor(); this.timeStep(); } Flow.start() </script>
Create a new entry at this position