Source

Example Codes

Don't worry! There is a guide here consists of example codes for warming you up. You can just copy (Ctrl+C) and paste (Ctrl+V) to run, then modify it.


Create random points.

var count = 6;

for (var i = 0; i < count; i++) {
    var x = getRandomInt(100, view.size.width - 100); //random int between 100 and width-100
    var y = getRandomInt(100, view.size.height - 100);

    printLog('x:'+x+', y:'+y)      // log the result in log window
    var tmpP = new TextPoint(x,y); // it creates a visual point with a text
}

By accepting view center as origin this code puts 6 TextPoint's with different radius.

var count = 6;
var origin = view.size/2;            // scene center

for (var i = 0; i < count;i++) {
    var vector = new Point({         // a Point not visual
        angle: 360/count * i,        // change angle as from 0 to 300
        length: getRandomInt(50,200) // random int between 50 and 200
    });

    var location = origin+vector;
	printLog(location)               // log the result in log window
	new TextPoint(location)          // a visual point
}

Using point subtraction, create two vectors and determine the direction points create

    var p0 = new TextPoint(100,100);  // create a visual point with text at 100,100
    var p1 = new TextPoint(200,200);
    var p2 = new TextPoint(100,300);

    var v1 = subtract(p1, p0);        // create a vector p0 -> p1
    var v2 = subtract(p2, p1);

    var dir = v1.cross(v2) > 0 ? 'left' : 'right'; // cross product
    printLog(dir)