News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

help with 180 degrea arc movement please

Started by micky4fun, December 27, 2009, 07:59:35 AM

Previous topic - Next topic

micky4fun

Hi all

was wondering if someone with more maths know how than me , proberly quite simple

i want to move the blue box along the red curve , keeping the same distance from the center dot , by moving the mouse along its x axis
ie using mousex() command , can anyone show me how

thanks
mick

kevin

#1
PlayBASIC Code: [Select]
   do
Cls 0

mx#=MouseX()

// Convert X# to scaler (Inverted)
XScaler# = (GetScreenWidth()-mX#)/GetScreenWidth()

// size of arc
Radius =100

// get angle
Angle#=180*xScaler#

// get screen pos
X#=400+cos(angle#)*Radius
Y#=300+sin(angle#)*Radius

// draw the circle to present the arc
circlec 400,300,radius,false,rgb(255,0,0)


// draw line between object and center
linec x#,y#,400,300,rgb(255,255,0)

// draw object on path
circlec x#,y#,5,true,rgb(0,0,255)


Sync
loop







micky4fun

#2
Hi Kevin

Thanks for the code snippet , took you about 10 seconds to sort out , i do and try and have ago myself for a few hours before posting any questions
but this is just beyond me ,
wonder if you can go a little further with this and get the blue box to move along the yellow line with using the mousey() command , so it moves up
and down the yellow line when the mouse moves up and down ,

thanks
mick :)

kevin


To move along the hypot,  the Y value is being inpretered as the circles radius.  So take the mouse's Y position, then dividie it by the screen height.   This gives you a scaler between 0.0 and 1.0.     Mult this scaler by the radius, job done..

stevmjon

to micky4fun

since you are having some trouble understanding this, i have used kev's code above, to give an example.

i have explained it as best i can. i hope it helps.

  stevmjon

p.s. i hope i haven't made it more confusing...lol
It's easy to start a program, but harder to finish it...

I think that means i am getting old and get side tracked too easy.

micky4fun

Hi stevmjon

Thanks for posting the code for kevin explanation , thats just what i was looking for , nice of you to explain it in code
lucky you guys know what you are doing , i was never taught this at school
and would have took me hours to suss out , if i ever did that is.

thanks
mick