Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js cyclic motion based on cosine

let x = 100  // center x
let y = 50   // center y
let r = 50   // radius
let a = 0    // angle (from 0 to Math.PI * 2)

function rotate(a) {
  
  let px = x + r * Math.cos(a); 
  let py = y + r * Math.sin(a);
  
  console.log( px, py );
  
}

setInterval(function() {
  a = (a + Math.PI / 360) % (Math.PI * 2);
  rotate(a);
}, 5);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #cyclic #motion #based #cosine
ADD COMMENT
Topic
Name
8+1 =