Answered by:
animating lines in small basic
Question

I tried to animate lines from a random position from top of the screen to the bottom of the screen in a straight line keeping the x coordinate constant but the lines drift along the x axis towards the right of the screen.
This doesn't happen when you animate ellipses and rectangles.
I have inserted my code. Any ideas? Thanks
gw = 600 gh = 400 GraphicsWindow.Width = gw GraphicsWindow.Height = gh While (1 = 1) x = Math.GetRandomNumber(gw) y = 0 drop = Shapes.AddLine(x,y,x,10) Shapes.Animate(drop,x,gh,2000) EndWhile
Answers

Try adding a Shapes.Move to initialise the shape position. This looks like a quirk of SmallBasic and the AddLine shape  most shapes AddEllipse etc need to be positioned after creation, The AddLine doesn't, but seems to be needed for subsequent movement.
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
While (1 = 1)
x = Math.GetRandomNumber(gw)
y = 0
drop = Shapes.AddLine(x,y,x,10)
Shapes.Move(drop,x,y)
Shapes.Animate(drop,x,gh,2000)
EndWhileAlso, after a few minutes the 'rain' will slow or bunch because shapes are continuing to be created, even though they are given the same name, all the previously created still remain in the SmallBasic GraphicsWindow. To get round this we need to create a limited number of shapes, and delete old ones that have moved off the bottom. Look at the following for one way to start doing this using arrays with a maximum of 200 drops created at any one time.
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
i = 1
While (1 = 1)
x = Math.GetRandomNumber(gw)
y = 0
Shapes.Remove(drop[i])
drop[i] = Shapes.AddLine(x,y,x,10)
Shapes.Move(drop[i],x,y)
Shapes.Animate(drop[i],x,gh,2000)
i = i+1
If (i > 200) Then
i = 1
EndIf
EndWhile Marked as answer by gosho Friday, September 10, 2010 9:27 PM

try this:
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
x1 = 0
y1 = 0
x2 = gw
y2 = 0
drop = Shapes.AddLine(x1,y1,x2,y2)
Shapes.ShowShape(drop)
While ("True")
y1 = Math.GetRandomNumber(gh)
Shapes.Animate(drop,x1,y1,1000)
Program.Delay(1100)
EndWhileor this:
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
x1 = 0
y1 = 0
xx1 = gw
yy1 = 0
drop1 = Shapes.AddLine(x1,y1,xx1,yy1)
Shapes.ShowShape(drop1)
x2 = 0
y2 = 0
xx2 = 0
yy2 = gw
drop2 = Shapes.AddLine(x2,y2,xx2 ,yy2)
Shapes.ShowShape(drop2)
While ("True")
x2 = Math.GetRandomNumber(gw)
y1 = Math.GetRandomNumber(gh)
Shapes.Animate(drop1,x1,y1,1000)
Shapes.Animate(drop2,x2,y2,1000)
Program.Delay(1100)
EndWhile
Best Regards Martin Proposed as answer by martmen Sunday, August 1, 2010 8:10 AM
 Marked as answer by litdevModerator Friday, August 6, 2010 9:54 PM
All replies

try this:
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
x1 = 0
y1 = 0
x2 = gw
y2 = 0
drop = Shapes.AddLine(x1,y1,x2,y2)
Shapes.ShowShape(drop)
While ("True")
y1 = Math.GetRandomNumber(gh)
Shapes.Animate(drop,x1,y1,1000)
Program.Delay(1100)
EndWhileor this:
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
x1 = 0
y1 = 0
xx1 = gw
yy1 = 0
drop1 = Shapes.AddLine(x1,y1,xx1,yy1)
Shapes.ShowShape(drop1)
x2 = 0
y2 = 0
xx2 = 0
yy2 = gw
drop2 = Shapes.AddLine(x2,y2,xx2 ,yy2)
Shapes.ShowShape(drop2)
While ("True")
x2 = Math.GetRandomNumber(gw)
y1 = Math.GetRandomNumber(gh)
Shapes.Animate(drop1,x1,y1,1000)
Shapes.Animate(drop2,x2,y2,1000)
Program.Delay(1100)
EndWhile
Best Regards Martin Proposed as answer by martmen Sunday, August 1, 2010 8:10 AM
 Marked as answer by litdevModerator Friday, August 6, 2010 9:54 PM

Try adding a Shapes.Move to initialise the shape position. This looks like a quirk of SmallBasic and the AddLine shape  most shapes AddEllipse etc need to be positioned after creation, The AddLine doesn't, but seems to be needed for subsequent movement.
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
While (1 = 1)
x = Math.GetRandomNumber(gw)
y = 0
drop = Shapes.AddLine(x,y,x,10)
Shapes.Move(drop,x,y)
Shapes.Animate(drop,x,gh,2000)
EndWhileAlso, after a few minutes the 'rain' will slow or bunch because shapes are continuing to be created, even though they are given the same name, all the previously created still remain in the SmallBasic GraphicsWindow. To get round this we need to create a limited number of shapes, and delete old ones that have moved off the bottom. Look at the following for one way to start doing this using arrays with a maximum of 200 drops created at any one time.
gw = 600
gh = 400
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
i = 1
While (1 = 1)
x = Math.GetRandomNumber(gw)
y = 0
Shapes.Remove(drop[i])
drop[i] = Shapes.AddLine(x,y,x,10)
Shapes.Move(drop[i],x,y)
Shapes.Animate(drop[i],x,gh,2000)
i = i+1
If (i > 200) Then
i = 1
EndIf
EndWhile Marked as answer by gosho Friday, September 10, 2010 9:27 PM