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

Username:   Password: 
 RegisterRegister   
 help me please..about to make a point move randomly...
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cliff.skc




PostPosted: Fri Apr 01, 2005 7:28 pm   Post subject: help me please..about to make a point move randomly...

does anyone can tell me how to make a point in the screen that can move randomly in a circle!?
thanks so much!!
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Fri Apr 01, 2005 7:38 pm   Post subject: (No subject)

If a point is moving randomly, it's probably not moving in a circle. If it's moving in a circle, it's not moving randomly.
Please elaborate. Wink
person




PostPosted: Fri Apr 01, 2005 7:44 pm   Post subject: (No subject)

i think he means that there is a point moving randomly but the randomly moving spots are inside a circle
cliff.skc




PostPosted: Fri Apr 01, 2005 7:48 pm   Post subject: (No subject)

haha sorry guys ...my english sucks eh...haha...
i mean there is a circle..
and now i wanna put a point in this circle...
and it can move randomly in this circle...
hope you guys understand to it...^^"""
Cervantes




PostPosted: Fri Apr 01, 2005 8:05 pm   Post subject: (No subject)

You can use Math.Distance* to determine whether the point is within the circle's radius.

But, I'm still not 100% clear. Do you want the dot to be randomly "teleporting" within the circle, or do you want it to be moving, pixel by pixel, but remaining within the circle?

*Math.Distance is a function of Turing 4.0.5. If you don't have this, you can write your own distance function using the distance formula.
person




PostPosted: Fri Apr 01, 2005 8:17 pm   Post subject: (No subject)

code:

var x, y, xc, yc : int := 1
var xcord, ycord : real := 0
drawoval (400, 300, 50, 50, 1)
loop
    x := Rand.Int (1, 2)
    y := Rand.Int (1, 2)
    if x = 1 and y = 1 then
        xcord += xc
        ycord += yc
    elsif x = 1 and y = 2 then
        xcord += xc
        ycord -= yc
    elsif x = 2 and y = 1 then
        xcord -= xc
        ycord += yc
    elsif x = 2 and y = 2 then
        xcord -= xc
        ycord -= yc
    end if
    if whatdotcolor (400 + round (xcord) + 1, 300 + round (ycord)) not= 1 and whatdotcolor (400 + round (xcord) - 1, 300 + round (ycord)) not= 1 and whatdotcolor (400 + round (xcord), 300 +
            round (ycord) + 1) not= 1 and whatdotcolor (400 + round (xcord), 300 + round (ycord) - 1) not= 1 and whatdotcolor (400 + round (xcord) + 1, 300 + round (ycord) - 1) not= 1 and whatdotcolor
            (400 + round (xcord) + 1, 300 + round (ycord) + 1) not= 1 and whatdotcolor (400 + round (xcord) - 1, 300 + round (ycord) + 1) not= 1
            and whatdotcolor (400 + round (xcord) - 1, 300 + round (ycord) - 1) not= 1 then
        drawdot (400 + round (xcord), 300 + round (ycord), 2)
    else
        if x = 1 and y = 1 then
            xcord -= xc
            ycord -= yc
        elsif x = 1 and y = 2 then
            xcord -= xc
            ycord += yc
        elsif x = 2 and y = 1 then
            xcord += xc
            ycord -= yc
        elsif x = 2 and y = 2 then
            xcord += xc
            ycord += yc
        end if
    end if
end loop


btw: this is using whatdotcolour
cliff.skc




PostPosted: Fri Apr 01, 2005 8:23 pm   Post subject: (No subject)

ahh..sorry again of my stupidness eh...-n-...
hmm...
i want to make the point keep moving around in a circle...
that means theres only 1 point...and it keeps moving in the circle...
RaPsCaLLioN




PostPosted: Fri Apr 01, 2005 8:25 pm   Post subject: (No subject)

Math.Distance is usually better than colour detection. Especially if multiple colours will be displayed withing this circle. I believe you mean something like this...

code:
var iWindow : int := Window.Open ("graphics:300;300, noecho, nocursor, offscreenonly")

const x := 1
const y := 2

var aiDot : array x .. y of int
aiDot (x) := maxx div 2
aiDot (y) := maxy div 2

var aiCenter : array x .. y of int
aiCenter (x) := maxx div 2
aiCenter (y) := maxy div 2

var iRadius : int := 100

function Collision (X, Y : int) : boolean

    if Math.Distance (aiCenter (x), aiCenter (y), X, Y) >= iRadius then
        result true
    end if
    result false

end Collision

var iXtemp, iYtemp : int

loop
    drawoval (aiCenter (x), aiCenter (y), iRadius, iRadius, 2)
    drawfilloval (aiDot (x), aiDot (y), 10, 10, 1)
    Window.Update (iWindow)
    cls
    delay (10)
    iXtemp := Rand.Int (-5, 5)
    iYtemp := Rand.Int (-5, 5)
    if Collision (aiDot (x) + iXtemp, aiDot (y) + iYtemp) = false then
        aiDot (x) += iXtemp
        aiDot (y) += iYtemp
    end if
    exit when buttonmoved ("down")
end loop
Window.Close (iWindow)
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Fri Apr 01, 2005 8:25 pm   Post subject: (No subject)

jump randomly?

code:
setscreen ("offscreenonly")
const RADIUS := 180
const X := maxx div 2
const Y := maxy div 2
const TURNSPEED := 0.5
var radians : real := Rand.Real * 3.14159 * 2

loop
    radians := Rand.Real * 3.14159 * 2
    drawoval (X + round (cos (radians) * Rand.Real * RADIUS), Y + round (sin (radians) * Rand.Real * RADIUS), 2, 2, brightred)
    drawoval (X, Y, RADIUS, RADIUS, 7)
    View.Update
    delay (100)
    cls
end loop


or maybe brownian motion?

code:
setscreen ("offscreenonly")
const RADIUS := 180
const X := maxx div 2
const Y := maxy div 2
const TURNSPEED := 0.5
var radians : real := Rand.Real * 3.14159 * 2

var x : real := X
var y : real := Y

loop
    radians += Rand.Real * TURNSPEED * 2 - TURNSPEED
    if ((x + cos (radians) - X) ** 2 + (y + sin (radians) - Y) ** 2 < RADIUS ** 2) then
        x += cos (radians)
        y += sin (radians)
    end if
    drawoval (X, Y, RADIUS, RADIUS, 7)
    drawoval (round (x), round (y), 2, 2, brightred)
    View.Update
    cls
end loop
RaPsCaLLioN




PostPosted: Fri Apr 01, 2005 8:32 pm   Post subject: (No subject)

Nice code zylum!
cliff.skc




PostPosted: Fri Apr 01, 2005 8:34 pm   Post subject: (No subject)

yeah that's right!! i need the third one...!!
thanks a lot!!
but then i just a gr.10 student...
and those stuffs i haven't learned it yet...
is there any simply codes that can show the similar image!?
person




PostPosted: Fri Apr 01, 2005 8:43 pm   Post subject: (No subject)

i think zylum's code is the best for the computer to read, and Raps' code is also good (using Cervantes idea)...

basicly they have the best code if u can understand them

for ur question, my code would probably be the easiest and the most basic, but if u can understand zylum's use his

just in case that u r considering to use mine, all u need is to make a small change and ull be set Very Happy

btw: i almost forgot

code:

var x, y, xc, yc : int := 1
var xcord, ycord : real := 0
drawoval (300, 200, 190, 190, 1)
loop
    x := Rand.Int (1, 2)
    y := Rand.Int (1, 2)
    if x = 1 and y = 1 then
        xcord += xc
        ycord += yc
    elsif x = 1 and y = 2 then
        xcord += xc
        ycord -= yc
    elsif x = 2 and y = 1 then
        xcord -= xc
        ycord += yc
    elsif x = 2 and y = 2 then
        xcord -= xc
        ycord -= yc
    end if
    if whatdotcolor (400 + round (xcord) + 1, 300 + round (ycord)) not= 1 and whatdotcolor (400 + round (xcord) - 1, 300 + round (ycord)) not= 1 and whatdotcolor (400 + round (xcord), 300 +
            round (ycord) + 1) not= 1 and whatdotcolor (400 + round (xcord), 300 + round (ycord) - 1) not= 1 and whatdotcolor (400 + round (xcord) + 1, 300 + round (ycord) - 1) not= 1 and whatdotcolor
            (400 + round (xcord) + 1, 300 + round (ycord) + 1) not= 1 and whatdotcolor (400 + round (xcord) - 1, 300 + round (ycord) + 1) not= 1
            and whatdotcolor (400 + round (xcord) - 1, 300 + round (ycord) - 1) not= 1 then
        drawdot (400 + round (xcord), 300 + round (ycord), 2)
        delay (10)
        drawfilloval (300, 200, 189, 189, 0)
    else
        if x = 1 and y = 1 then
            xcord -= xc
            ycord -= yc
        elsif x = 1 and y = 2 then
            xcord -= xc
            ycord += yc
        elsif x = 2 and y = 1 then
            xcord += xc
            ycord -= yc
        elsif x = 2 and y = 2 then
            xcord += xc
            ycord += yc
        end if
    end if
end loop
cliff.skc




PostPosted: Fri Apr 01, 2005 8:54 pm   Post subject: (No subject)

alright...thanks you guys very very much!!
cliff.skc




PostPosted: Tue Apr 05, 2005 9:26 am   Post subject: (No subject)

ok, let me rephrase my question....how can i make a circle rotate continuously on a single point??
Cervantes




PostPosted: Tue Apr 05, 2005 10:17 am   Post subject: (No subject)

Well, if a circle is rotating around a point, you won't see any change.
What I think you mean is you want to draw a dot that travels around the circumfrence of the circle. For that, we use some trig.
code:

var r := 40
for a : 1 .. 360
    Draw.Dot (round (cosd (a) * r) + 100, round (sind (a) * r) + 100, black)
    delay (5)
end for

r is the radius, a is the angle. the + 100's move the dot such that it travels around a circle whose centre is (100, 100).
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 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: