Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Pivoting...Rotating...HELP!!!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Neo




PostPosted: Wed Nov 10, 2004 6:06 pm   Post subject: Pivoting...Rotating...HELP!!!!

Ok what Im trying to do is pivot a line in the centre of a circle.
For example the hand on a clock. I want to be able to move that hand,to
different numbers on the clock as if you were setting up the time. My
question is how do I keep the line or hand the same length while
rotating the hand? I want to pivot the hand around the center but
I dont want it to go out side of the circle or get any shorter.
It may be kind of hard to understand but if you try my program
you will understand what I mean. To change the hand you have to
click on the blue dot and hold the left mouse button down and then drag it to where you want the hand to point. But How do I keep the blue dot on the green outline of the circle...
You know what I mean? Please HELP!!!

code:
View.Set ("graphics:320;320,nobuttonbar")
var xm, ym, bm : int
var x, y := 150

setscreen ("offscreenonly")
loop
    Mouse.Where (xm, ym, bm)
    drawfillbox (0, 0, maxx, maxy, grey)

    drawoval (150, 200, 50, 50, green)
    Draw.ThickLine (150, 200, x, y, 4, blue) %line

    drawfilloval (150, 200, 4, 4, brightgreen)
    drawfilloval (x, y, 4, 4, brightblue) %target

    if whatdotcolour (xm, ym) = brightblue and bm = 1 then
        x := xm
        y := ym
    end if
   
    delay (8)
    View.Update
end loop
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Wed Nov 10, 2004 6:29 pm   Post subject: (No subject)

You need to use some trig:
code:

View.Set ("graphics:320;320,nobuttonbar,offscreenonly")
var x, y := 150.0
const lineLength := 100
const line_X_origin := maxx div 2
const line_Y_origin := maxy div 2
var angle := 90
loop
    cls

    x := cosd (angle) * lineLength + line_X_origin
    y := sind (angle) * lineLength + line_Y_origin
    angle += 1
    if angle > 360 then
        angle -= 360
    end if

    drawline (line_X_origin, line_Y_origin, round (x), round (y), black)

    delay (5)
    View.Update
end loop


If you want to use the mouse, you'll probably need to find the angle. (ie. use the find_angle function)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: