forums

TNT Basic Forums > Programming Q&A
Eye have a problem
< Last Thread     Next Thread >
Author
Thread        Post A Reply

09-27-2006 17:11

Posted by:
Orteil

Location:
Somewhere in France

Find more posts by Orteil

Hey, check this code :




int scx=640,scy=480

window mode scx,scy

int a,b,c,d,e


int n=10
int px[n],py[n],ang[n],siz[n],siz2[n],wink[n]

float angd[n]




for a=0 to n-1
px[a]=random(0,scx)
py[a]=random(0,scy)
siz[a]=random(16,128)
siz2[a]=random(siz[a]/10,siz[a]/3)
next a



repeat

set pen color black
fill rect 0,0 to scx,scy


for a=0 to n-1
if random(0,0)=0
ang[a]=(ang[a]+ang[a]+ang[a]+(-calculate angle(px[a],py[a] to mouse x,mouse y)+180))/4

y)+180 then ang[a]=ang[a]+10
y)+180 then ang[a]=ang[a]-10
x,mouse y)+180))
angd[a]=0
end if
ang[a]=ang[a]+angd[a]


set pen color white
fill oval px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2
set pen color black
fill oval px[a]-siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]-siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a]) to px[a]+siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]+siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a])
set pen color white
fill oval px[a]-siz2[a]/3+sin(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2,py[a]-siz2[a]/3+cos(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2 to px[a]+siz2[a]/3+sin(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2,py[a]+siz2[a]/3+cos(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2

if wink[a]>0
set pen color black
fill oval px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2
set pen color white
fill oval px[a]-siz[a]/2,py[a]-(siz[a]/2)/(wink[a]) to px[a]+siz[a]/2,py[a]+(siz[a]/2)/(wink[a])
set pen color black
fill oval px[a]-siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]-siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a]) to px[a]+siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]+siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a])
end if


set pen color black
frame oval px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2



if point in rect(mouse x,mouse y,px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2) and mouse button
wink[a]=50
end if
if wink[a]>1 then wink[a]=wink[a]-2
if random(0,100)=0
wink[a]=random(10,50)
end if


next a



draw frame

until pressed(0) and pressed(55)





So...
1) does it work well ?
2) when you put the mouse right in the up of an eye, it looks up. Move it slightly on the left : it makes a big 360 round and the same thing if you move to the right. It's pretty normal, but how can I avoid this ?

09-30-2006 13:39

Posted by:
appleide

Click Here to Email appleide   Find more posts by appleide

try something like this?

angle = mouse angle to eye
if mouseangle to eye =0
if angle <90
eye move to left (not go around 360)
end if
if angle >270
eye move to right (not go around 360)
end if
end if



First time I see arrays in action....

09-30-2006 14:35

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

like that =) (PS: 100 lines without a single comment is a very bad programming habit :P )



int scx=640,scy=480

window mode scx,scy

int a,b,c,d,e


int n=10
int px[n],py[n],ang[n],siz[n],siz2[n],wink[n], target_ang[n]

float angd[n]




for a=0 to n-1
px[a]=random(0,scx)
py[a]=random(0,scy)
siz[a]=random(16,128)
siz2[a]=random(siz[a]/10,siz[a]/3)
next a



repeat

set pen color black
fill rect 0,0 to scx,scy


for a=0 to n-1
if random(0,0)=0

'ang[a]=(ang[a]+ang[a]+ang[a]+(-calculate angle(px[a],py[a] to mouse x,mouse y)+180))/4

target_ang[a]=-calculate angle(px[a],py[a] to mouse x,mouse y)+180

'make sure then angle lays between 0 and 260
if target_ang[a]<0 then target_ang[a]=target_ang[a]+360
if target_ang[a]>360 then target_ang[a]=target_ang[a]-360
if ang[a]<0 then ang[a]=ang[a]+360
if ang[a]>360 then ang[a]=ang[a]-360


if target_ang[a]>270 and ang[a]<90
ang[a]=ang[a]+360
else if target_ang[a]<90 and ang[a]>270
target_ang[a]=target_ang[a]+360
end if

ang[a]=(3*ang[a]+target_ang[a])/4


'y)+180 then ang[a]=ang[a]+10
'y)+180 then ang[a]=ang[a]-10
'x,mouse y)+180))
angd[a]=0
end if
ang[a]=ang[a]+angd[a]


set pen color white
fill oval px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2
set pen color black
fill oval px[a]-siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]-siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a]) to px[a]+siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]+siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a])
set pen color white
fill oval px[a]-siz2[a]/3+sin(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2,py[a]-siz2[a]/3+cos(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2 to px[a]+siz2[a]/3+sin(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2,py[a]+siz2[a]/3+cos(ang[a])*(siz[a]/2-siz2[a])-siz2[a]/2

if wink[a]>0
set pen color black
fill oval px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2
set pen color white
fill oval px[a]-siz[a]/2,py[a]-(siz[a]/2)/(wink[a]) to px[a]+siz[a]/2,py[a]+(siz[a]/2)/(wink[a])
set pen color black
fill oval px[a]-siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]-siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a]) to px[a]+siz2[a]+sin(ang[a])*(siz[a]/2-siz2[a]),py[a]+siz2[a]+cos(ang[a])*(siz[a]/2-siz2[a])
end if


set pen color black
frame oval px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2



if point in rect(mouse x,mouse y,px[a]-siz[a]/2,py[a]-siz[a]/2 to px[a]+siz[a]/2,py[a]+siz[a]/2) and mouse button
wink[a]=50
end if
if wink[a]>1 then wink[a]=wink[a]-2
if random(0,100)=0
wink[a]=random(10,50)
end if


next a



draw frame

until pressed(0) and pressed(55)

09-30-2006 14:36

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

i forgot to mention... very nice work! looks scary ;)

09-30-2006 14:38

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

(and the "make sure then angle lays between 0 and 260" should of course read '360' and not '260')

09-30-2006 18:23

Posted by:
swagIT

Location:
Great Wet North (Vancouver)

Find more posts by swagIT

Very cool and scary! =)

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.