JS based orbits in Isadora

Posted by on 23 November 2015 | Comments

Tags: ,

I have been doing a lot with dynamic Javascript based drawing in Isadora lately.
2 recent YouTube videos show some JS orbits in action as the engine for a live drawn clock component, and in some collision detection tests.


Here is the basic code for drawing orbits in Isadora via Javascript

function main()
{
	var h = arguments[0]; // center X
	var k = arguments[1]; // center Y
	var r = arguments[2]; // radius
	var t = arguments[3]; // radians


	var x = (r* Math.cos(t)) + h;
	var y = (r* Math.sin(t)) + k;

	var data = [];
	data.push(x);
	data.push(y);

	return data;
}

This code expects the 4th argument to be in radians. So the next function will allow for easy conversion of degrees to radians.

function main() 
{ 
return arguments[0] * 0.0174532925; 
}

They are both main() functions because I had them in separate JS actors.. it would probably be worth combining these.

Note: that the XY co-ordinates are based on a 1:1 ratio space.. Isadoras stages are not 1:1
You will need to divide the width by the height to find the ratio, and then multiple one of the X or Y coordinates as needed to true up the data. I generally adjust the width... but that's just my preference.

Tip: Setup a user actor with Global variables that calculates this ratio (and other environment data) to share within each scene. Add it to your global toolbin and carefully add to it as you discover config data that would be useful throughout all your projects.