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

Username:   Password: 
 RegisterRegister   
 Calculation of a ball move to a certain coordinate.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
8749236




PostPosted: Tue Mar 08, 2011 1:25 pm   Post subject: Calculation of a ball move to a certain coordinate.

What is it you are trying to achieve?
I'm trying to write a program, it will draw a ball, and move it to any coordinate

What is the problem you are having?
i got calculation problem, i don't know how to do the calculation to make the ball move to the coordinate i want


Describe what you have tried to solve this problem
i have tried to calculate the slope between the ball's coordiante and the target's coordinate, but the mostly the numbers don't have a GCF..

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


var numOfObject : int := 5
var targetX, targetY : int
var objectX, objectY : array 1 .. numOfObject of int
var speedToTargetX, speedToTargetY : array 1 .. numOfObject of int

View.Set ("offscreenonly")

procedure drawObject

    for i : 1 .. numOfObject
        drawfilloval (objectX (i), objectY (i), 2, 2, black)
    end for

end drawObject

procedure drawTarget

    drawfillstar (targetX, targetY, targetX + 15, targetY + 15, blue)

end drawTarget

loop

    for i : 1 .. numOfObject
        randint (objectX (i), 1, 639)
        randint (objectY (i), 350, 800)

        randint (targetX, 1, 639)
        randint (targetY, 10, 150)
    end for


    for i : 1 .. numOfObject
        speedToTargetX (i) := round ((objectX (i) - targetX) / 120)
        speedToTargetY (i) := round ((objectY (i) - targetY) / 120)
    end for


    loop
        for i : 1 .. numOfObject

            drawObject
            drawTarget


            /*
             put speedToTargetX
             put speedToTargetY
             put objectX
             put objectY
             put targetX
             put targetY
             */


            objectX (i) := objectX (i) - speedToTargetX (i)
            objectY (i) := objectY (i) - speedToTargetY (i)




            View.Update
            Time.Delay (1)
            cls
        end for
    end loop
end loop



Please specify what version of Turing you are using
Turing 4.1
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Tue Mar 08, 2011 2:06 pm   Post subject: RE:Calculation of a ball move to a certain coordinate.

You want to use the real variable type. This will let you represent numbers like 1.2, 3.1415, or 0.1113. You can then represent your slope was a "real" variable.

You will also need to look at the round(), floor() or ceil() functions to convert real numbers back into integers for drawing coordinates.
Grim




PostPosted: Tue Mar 08, 2011 7:12 pm   Post subject: RE:Calculation of a ball move to a certain coordinate.

There are common algorithms that compute the shortest path between two points.
8749236




PostPosted: Wed Mar 09, 2011 10:27 am   Post subject: RE:Calculation of a ball move to a certain coordinate.

ok..
i'll try...
and.. what is 'floor' and 'ceil' function?
DemonWasp




PostPosted: Wed Mar 09, 2011 10:34 am   Post subject: RE:Calculation of a ball move to a certain coordinate.

Look them up in the Turing help.
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  [ 5 Posts ]
Jump to:   


Style:  
Search: