BenjaminFox1 / sin_cos_orbit

Simple Illustration of Sin and Cos (credit Pythagoras et al)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sin_cos_orbit

Simple Illustration of Sin and Cos (credit Pythagoras et al)

Thanks to Amed Kino for his addition.

// Sin and Cosine - An illustration of their path

var orbitX = 400;
var orbitY = 400;
var orbitRadius = 200;
var angle = 0;
var speed = 0.02;

function setup() {
 createCanvas(800, 800);

}

function draw() {
 background(200);
 
 text("An illustration of Sin and Cos",20,50)
 
 fill(255);
 ellipse(400,400,400)

 var x = orbitX + orbitRadius * cos(angle);
 var y = orbitY + orbitRadius * sin(angle);
 
 //ellipse(orbitX, orbitY, 50, 50);
 ellipse(x, y, 1, 1);
 angle -= speed;

 //triangle
 fill(255);

 line(400,400,x,y); //hypoteneuse
 line(x,y,x,400); //opposite
 line(400,400,x,400); //adjacent
 
 ellipse(150,y,100,100)
 ellipse(x,150,100,100)

 
 // Show Sin, Cos, Tan
 fill(0);
 text("Sin: "+ 
 round(sin(-angle),2),120,y);
 
 text("Cos: "+ 
 round(cos(-angle),2),x-30,150);

}

About

Simple Illustration of Sin and Cos (credit Pythagoras et al)

License:MIT License


Languages

Language:JavaScript 100.0%Language:HTML 0.0%Language:CSS 0.0%