CodePlexProject Hosting for Open Source Software

Returns a number m% of the way between i1 and i2. So for example, say you want an action to occur 30% of the way from the top of the screen. The function call to retrieve the co-ordinates would be:

Math.fNum(0,page.getSize().y,0.3)

This returns a random integer between max and min. There is no error-checking here, so ensure max and min are the right way round. So say you wanted the result of a 6-sided die roll:

Math.randI(6,1)

This returns a random number as above, except that you can now indicate the number of decimal places with the third parameter. By default, Math.randI and Math.rnd can be used interchangeably. Say you wanted to get a random number between 0 and 1 to 6 decimal places, you could use:

Math.rnd(1,0,6)

This forces value n to be between max and min. So if you wanted to force n to be between 0 and 360, you might code this:

n=Math.clamp(n,0,360)

Say you've just used Math.fNum, but now you've forgotten what your value for m was. Or you just want to know what percentage between a and b is integer c. Here is some code that could help you:

m=Math.whereBetween(0,page.getSize().y,answerof_fnum)

To check that a number is even (divisible by 2) use this function. While just using the modulus operator is probably less typing, this is a whole lot more readable.

if(!Math.even(mustbeeven)) mustbeeven+=1;

Taking 2 points as parameters (see below), this function simply finds the distance between them. So say you wanted to know the distance from one end of the screen to the other:

Math.distance(new point(0,0),page.getSize())

Returns the difference between angle a1 and angle a2. For example, the difference between 359 and 1 using this function is 2:

thisis2=Math.angleDifference(359,1)

Experimental AJAX function. Reads the contents of file "url" and returns the string. Can be used, for example, to load the contents of an external file into a DIV layer:

document.getElementById('mydivid').innerHTML=getData('externalfile.txt');

Note that as with all AJAX stuff, only information from your domain can be loaded.

Creates a new virtual point on which mathematical operations may be performed.

myrandompoint=new point(10,50);

Calculates the distance between 2 points, saves you having to write out Pythagoras' formula.

myrandomdistance=myrandompoint.distance(new point(0,0));

Rounds the co-ordinates of a point to the nearest whole numbers. For instance, a point where x=5.26 and y=3.5 would become x=5 and y=4. Why would you do this? To display something on screen at that point, it is a good idea to round it first, because otherwise some browsers behave erratically.

myroundedpoint=new point(5.26,3.5).round();

Very simple yet useful function to move the x and y coordinates a specified distance. So to move that point we just rounded to (10,10), we could use this:

myoffsetpoint=myroundedpoint.offset(5,6);

Returns a duplicate of the point. Quite limited use perhaps, but it's a really small function so I thought I might just throw it in!

myclonedpoint=myoffsetpoint.clone();

Want to move a point 20 units north-west? Now you can! Given a compass co-ordinate and a distance, this function will move the point.

mymovedpoint=myclonedpoint.move(45,20); //20 units north-west

rect(x1,y1,x2,y2)

rect.top()

rect.bottom()

rect.left()

rect.right()

rect.center()

rect.centerOn(p)

rect.clone()

rect.offset(x,y)

rect.overlaps(p || rct)

rect.move(ang,dist)

rect.round()

rect.getPoint(n)

refCount()

refCount.find(k)

refCount.add(k,v)

refCount.remove(n)

color(a,r,g,b || hex)

color.getHex()

color.setAlpha(a)

mergeColors(c1,c2,m)

timeline()

timeline.addEvent(f,t)

timeline.run()

timeline.stop()

page.getSize()

page.size()

page.randomRect()

page.randomSquare(s=Math.randI(300,50))

scene(r,c,id)

scene.getObject(id)

scene.place(p)

scene.offset(x,y)

scene.getPosition()

scene.getObj()

scene.scale(factor,resizeObjects=true,factorIsAbsoluteValue)

scene.setColor(c)

scene.getColor()

scene.clear()

addEllipse(position,color,scn,id)

addRect(position,color,scn,id)

addText(txt,position,color=color_Black,scn,id)

addSprite(src,position,color,scn,id)

ldkobject.outline(color=color_Red)

ldkobject.setDrag(isDraggable)

ldkobject.setColor(c)

ldkobject.drive(dist)

ldkobject.rotate(angle)

ldkobject.move(x,y)

ldkobject.setPosition(rct)

ldkobject.place(rct) - (does same thing as above)

ldkobject.stop(finish)

ldkobject.animate(position,color,time)

ldkobject.clone()

ldkobject.fadeOut(time)

ldkobject.fadeTo(color,time)

ldkobject.getSpeed()

ldkobject.centerOn(p)

ldkobject.remove()

ldkobject.events[]

ldkobject.addCollision(obj)

ldkobject.update()

ldkspriteobject.setSrc(src)

ldktextobject.setContent(con)

ldktextobject.format(b,i,u,s,f)

mouseX, mouseY, mouseButton

keyHandler=0

mouseHandler=0

keys[128]

Last edited Aug 31, 2010 at 12:48 AM by larztheloser, version 11

doesn't work in chrome? or my chrome has been wrong