Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var boidPos = { x: 400,
  2.                                 y: 500 };
  3. var circleRadius = 100;
  4. var origin = { x: 400 ,
  5.                            y: 300};
  6.                                
  7.                                
  8. var canvas;
  9.  
  10. function draw() {
  11.         if (canvas.getContext){
  12.                 var ctx = canvas.getContext('2d');
  13.                 ctx.clearRect(0, 0, 800, 600);
  14.                 var lineJoin = ['round','bevel','miter'];
  15.                 ctx.lineWidth = 5;
  16.  
  17.                 ctx.lineJoin = 'miter';
  18.                 ctx.beginPath();
  19.                 ctx.moveTo(boidPos.x - 15 , boidPos.y + 15);
  20.  
  21.                 ctx.lineTo(boidPos.x, boidPos.y - 5);
  22.                 ctx.lineTo(boidPos.x + 15, boidPos.y + 15);
  23.  
  24.                 ctx.stroke();
  25.  
  26.         }
  27. }
  28.  
  29. function update() {
  30.         var time = 0;
  31.         function iterate() {
  32.                 time++;
  33.  
  34.                 boidPos.x = circleRadius * Math.cos(((2*Math.PI)/180) * time);
  35.                 boidPos.y = circleRadius * Math.sin(((2*Math.PI)/180) * time);
  36.  
  37.         }
  38.         return iterate();
  39. }
  40.  
  41. window.onload = function() {
  42.         canvas = document.getElementById('tutorial');
  43.         setInterval(update, 50);
  44.         setInterval(draw, 50);
  45. }