# Ellipse Bewegen

• ### Question

• Hello,

How can i move a Ellise to a random place with Small basic

Wie kann ich eine Ellipse (kreis) zu einem Zufallsort bewegen lassen (Small Basic)

Saturday, February 26, 2011 9:05 AM

• Start with some of the examples above and try to build the application in stages such as:

1] A moving ball with nothing else - how is it moving? does it bounce on walls etc.

2] Stop the ball with a mouse click event

3] Change the speed perhaps with a key press

When you have some code, repost on a new thread with any questions or problems - don't try to do step 2 and 3 before you have step 1.

Good luck.

Tuesday, March 8, 2011 7:32 PM

### All replies

• First you need to create a shape, the returned value is a variable for the shape you created that can be moved, rotated etc:

We can the move the shape (called ball here) using:

Shapes.Move(ball,100,100)

The first argument is the shape name (ball) and the second, third arguments are the top left coordinates (x,y) where the shape will be moved to.

Note that the x direction is left to right and the y coordinate is top to bottom.  Also note that the shape has a width, height and the centre of the shape will be at (x+width/2,y+height/2), therfore if we want to position the shape centre at (x,y), then we move the shape to (x-width/2,y-height/2).  For the ball above this would be:

Shapes.Move(ball,100-25,100-25)

We can get a random number for the window width with:

x = Math.GetRandomNumber(GraphicsWindow.Width)

Similarly, for a random value of the window height (y), then move the ball shape to this positions:

Shapes.Move(ball,x-25,y-25)

• Marked as answer by Sunday, February 27, 2011 9:51 AM
• Unmarked as answer by Monday, February 28, 2011 4:38 PM
Saturday, February 26, 2011 10:38 AM
• ellipse = Shapes.AddEllipse(20, 20)
randomX = Math.GetRandomNumber(GraphicsWindow.Width - 20)
randomY = Math.GetRandomNumber(GraphicsWindow.Height - 20)
Shapes.Move(ellipse, randomX, randomY)

Here is just a code you can copy and paste all at once.

~~AirWaves!!~~
• Marked as answer by Sunday, February 27, 2011 9:52 AM
• Unmarked as answer by Monday, February 28, 2011 4:38 PM
Saturday, February 26, 2011 10:42 PM
• Danke für die hilfreichen Antworten, doch eigendlich dachte ich, dass man die Bälle sehen soll. Vielleich weiß jemand wie dass geht.
Schon einmal danke im Vorraus.

Thanks for the helpful answers, but   I thought that I should see the balls . Perhaps someone knows how to do that .
Ever thank you in advance .

• Marked as answer by Sunday, February 27, 2011 10:01 AM
• Unmarked as answer by Monday, February 28, 2011 4:38 PM
Sunday, February 27, 2011 9:56 AM
• With my suggestions or AirWaves code you should see a single ball positioned at a random point - do you not see this or expect something else?

Monday, February 28, 2011 6:48 PM
• Here is two great random ellipse samples:

This sample moves ellipse to random position when you press key down in GraphicsWindow:

ellipse = Shapes.AddEllipse(20, 20)
GraphicsWindow.KeyDown = OnKeyDown

Sub OnKeyDown
randomX = Math.GetRandomNumber(GraphicsWindow.Width - 20)
randomY = Math.GetRandomNumber(GraphicsWindow.Height - 20)
SpeedX = randomX - Shapes.GetLeft(ellipse)
SpeedX = Math.Abs(SpeedX)
SpeedY = randomY - Shapes.GetTop(ellipse)
SpeedY = Math.Abs(SpeedY)
Speed = SpeedX + SpeedY
Shapes.Animate(ellipse,randomX,randomY,Speed)
EndSub

This sample creates lots of different random ellipses:

While "True"
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
X = Math.GetRandomNumber(GraphicsWindow.Width - 20)
Y = Math.GetRandomNumber(GraphicsWindow.Height - 20)
W = Math.GetRandomNumber(20)
H = Math.GetRandomNumber(20)
GraphicsWindow.FillEllipse(X,Y,W,H)
EndWhile

Sorry My Bad English
Monday, February 28, 2011 8:13 PM
• no , sorry , but thanks for the answers .
I do not think that the click of a button , but still rolling .
So here's a detailed description :
I want rumrollt a ball ( ie 2d disc ) of radius 25th and the ball can only be stopped with pressure of the mouse button werden.das pace should be such that one can see the ball well as it rolls . and perhaps I can still change the speed .
Sorry for the vague expression and my bad English .
Thanks for the reply but I hope for your helpful Supporting UNG

Thank you thank you thank you thank you thank you thank you thank you thank you [:D]
Tuesday, March 1, 2011 1:53 PM
• Start with some of the examples above and try to build the application in stages such as:

1] A moving ball with nothing else - how is it moving? does it bounce on walls etc.

2] Stop the ball with a mouse click event

3] Change the speed perhaps with a key press

When you have some code, repost on a new thread with any questions or problems - don't try to do step 2 and 3 before you have step 1.

Good luck.

Tuesday, March 8, 2011 7:32 PM
• Hallo ???,

importiere das Programm TSG350 dort sind die Zeilen beschrieben. Ich hoffe das Programm hilft dir.

Best Regards Martin
Wednesday, March 9, 2011 8:39 AM