|
Download
the Open Source Here
Primer on Lingo
Math
Provided by Colin
Coupland
Maths
is a subject which should
really be studied all
on
its own. However the
programming community
need to
know only a certain amount.
However, its difficult
to
begin to
understand the
hard core elements of
pure maths. Often I see
signs which I don't know
the
meaning of.
This
tutorial will try to
bring together some common
treads within maths.If
you understand Director
lingo you can go
straight to
downloading
the
files.
The
example I have used for
this demo is the "Lissajous.dir"
curve. This is a good
curve. It moves in a figure
of eight type movement.
It is nice and smooth.
There are several curves
demonstrated here though.
Some more useful than
others.
Maths is mainly used to
move
sprites. First of
all you declare variables.
You do
this with
the
property
commando. Then
you set
up the
values which you want the
variables to
start off with
- by using the
beginsprite
commando.
property t,a,b,c,n
on beginsprite me
a=100
b=62
c=73
t=0
n=2
end
Then
you start the
core part of
the
program. This involves the
exitframe
handle. Everytime a frame
finishes this source
will be accessed.
on exitframe
me
t=t+0.02
xx = a* cos(n*t + c)
yy = b *cos(t)
member(3).image.setPixel(xx+200,
300+yy, rgb(255,255,255))
member(3).image.copypixels(member(4).image,member(3).rect,member(3).rect,[#blendlevel:3])
end
You will notice one or two
things here. Firstly the T variable. All curves
involve the manipulation of
cosines and sines. These Trigonometry functions are usually used to
calculate angles. However, they are also extremely useful for moving sprites.
They give nice smooth movement. Just look at the
T variable. Each frame it is increased by 0.02
That is what gives the animation. All the
other variables are a contradiction - they just do
not vary. You can manipulate those in other ways.
But for the purposes of
this simple demonstartion we will manipulate only the
T variable. Also notice that the T variable is only incresed by a very small
amount. With other curves the increase per frame is 1 or even two degrees. It
all depend on the curve.
You will also notice the member(3).image.setpixel line. You can ignore this for the purposes of the maths. That simply draws a new white dot on the image. The next line fades the image.
So in short the main calculation is in the lines.
xx = a* cos(n*t + c) yy = b *cos(t)
These two variables calculate the position along (xx) and up (yy) to draw the new dot. You will find that Maths curves all have these several common features.
And of
course all cosines and
sines end
up at exactly the
same position
so that after
360
degrees have passed the
animation simply repeats
itself.
The
other exampamples that
are included in the down
load look somthing like
this:
|