Oxoscript turns into NanoPy - more infos

Vector functions

vector3D.toString

  vector3D.toString()->byte[40]

Class: vector3D

Converts a 3D vector into a string.

v = vector3D(x=24,y=32,z=11)
v.toString() # => "[24.000000:32.000000:11.000000]"

vector3D.cross

  vector3D.cross(v:vector3D)->vector3D

Class: vector3D

Calculates the cross product of the 3D vector with the given 3D vector v. The result of a cross product is a new 3D vector.

vector3D.dot

  vector3D.dot(v:vector3D)->float

Class: vector3D

Calculates the scalar product of the 3D vector with the passed 3D vector v.

vector3D.distance

  vector3D.distance(v:vector3D)->float

Class: vector3D

Calculates the distance between two 3D vectors.

vector3D.magnitude

  vector3D.magnitude()->float

Class: vector3D

Calculates the length of the 3D vector.

vector3D.random

  vector3D.random()

Class: vector3D

Creates a random 3D direction vector with length 1.

vector3D.fromAngle

  vector3D.fromAngle(alpha:float, theta:float)

Class: vector3D

Creates a normalized 3D vector with the direction alpha and theta in radians.

vector3D.mulScalar

  vector3D.mulScalar(s:float)

Class: vector3D

Multiplies the value s with the x, y, and z values of the 3D vector (scalar multiplication).

v1 = vector(x=4,y=8,z=2)
v1.mulScalar(10)

vector3D.subScalar

  vector3D.subScalar(s:float)

Class: vector3D

Subtracts the value s from the x, y and z values of the 3D vector (scalar subtraction).

v1 = vector3D(x=4,y=8,z=2)
v1.subScalar(10)

vector3D.addScalar

  vector3D.addScalar(s:float)

Class: vector3D

Adds the value s to the x, y and z values of the 3D vector (scalar addition).

v1 = vector3D(x=4,y=8,z=2)
v1.addScalar(10)

vector3D.sub

  vector3D.sub(v:vector3D)

Class: vector3D

Subtracts the 3D vector v from the 3D vector

v1 = vector3D(x=4,y=8,z=2)
v2 = vector3D(x=3.5,y=1.8,z=1.1)
v1.sub(v2)

vector3D.add

  vector3D.add(v:vector3D)

Class: vector3D

Adds the 3D vector v to the 3D vector.

v1 = vector3D(x=4,y=8,z=2)
v2 = vector3D(x=3.5,y=1.8,z=1.1)
v1.add(v2)

vector3D.normalize

  vector3D.normalize()

Class: vector3D

Normalizes the 3D vector. This means that after the call the vector length is 1.

v = vector3D(x=5,y=10,z=3)
v.normalize()

vector.toString

  vector.toString()->byte[30]

Class: vector

Converts a vector into a string.

v = vector(x=24,y=32)
v.toString() # => "[24.000000:32.000000]"

vector.limit

  vector.limit(xMin:float, xMax:float, yMin:float, yMax:float)

Class: vector

Limits the vector to the defined range (xMin… xMax & yMin… yMax).

vector.limitToScreen

  vector.limitToScreen(offset:int)

Class: vector

Limits the vector to the visible screen area (0… 239).
Optionally, an offset greater than 0 can be selected to reduce the visible area.

v = vector(x=-5,y=250)
v.limitToScreen(0)
v.x # => 0
v.y # => 239
v.limitToScreen(5)
v.x # => 5
v.y # => 234

vector.dot

  vector.dot(v:vector)->float

Class: vector

Calculates the scalar product of the vector with the passed vector v.

vector.angle

  vector.angle()->float

Class: vector

Returns the angle in radians of the vector.

vector.distance

  vector.distance(v:vector)->float

Class: vector

Calculates the distance between two vectors.

vector.magnitude

  vector.magnitude()->float

Class: vector

Calculates the length of the vetor.

vector.random

  vector.random()

Class: vector

Creates a random direction vector with length 1.

The following example draws 3000 random vectors, each with a random length between 0 and 100 pixels and a different brightness.

for i in 3000:
    v:vector
    v.random()
    v.mulScalar(random(0,100))
    strokeHSV(110,255,random(0,255))
    drawLine(120,120,120+v.x,120+v.y)
update()

vector.fromAngle

  vector.fromAngle(angle:float)

Class: vector

Creates a normalized vector with the direction angle in radians.

The following example draws 12 circles u a circle.
2*PI is the circumference of the circle in unit circle. We divide this into 12 parts and use this to initialize the the vector direction. With mulScalar(..) we then change the length of the vector, which corresponds to the radius of the circle.

for i in 12:
    f = PI/6*i
    v:vector
    v.fromAngle(f)
    v.mulScalar(80)
    drawCircle(120+v.x,120+v.y,5)
update()

vector.subScalar

  vector.subScalar(s:float)

Class: vector

Subtracts the value s to each of the x and y values of the vector (scalar subtraction).

v1 = vector(x=4,y=8)
v1.subScalar(10)

vector.mulScalar

  vector.mulScalar(s:float)

Class: vector

Multiplies the value s each by the x and y values of the vector (scalar multiplication).

v1 = vector(x=4,y=8)
v1.mulScalar(10)

vector.addScalar

  vector.addScalar(s:float)

Class: vector

Adds the value s to each of the x and y values of the vector (scalar addition).

v1 = vector(x=4,y=8)
v1.addScalar(10)

vector.sub

  vector.sub(v:vector)

Class: vector

Subtracts the vector v from the vector

v1 = vector(x=4,y=8)
v2 = vector(x=3.5,y=1.8)
v1.sub(v2)

vector.normalize

  vector.normalize()

Class: vector

Normalizes the vector. This means that after the call the vector length is 1.

v = vector(x=5,y=10)
v.normalize()

vector.add

  vector.add(v:vector)

Class: vector

Adds the vector v to the vector

v1 = vector(x=4,y=8)
v2 = vector(x=3.5,y=1.8)
v1.add(v2)