0

Here's the full code:

GraphicsWindow.Clear()
GraphicsWindow.CanResize = "false"
GraphicsWindow.Height = Desktop.Height-200
GraphicsWindow.Width = Desktop.Width-200

scount = Math.GetRandomNumber(25)
For s = 1 To scount
  Shx[s] = Math.GetRandomNumber(GraphicsWindow.Width-100)
  Shy[s] = Math.GetRandomNumber(GraphicsWindow.Height-100)
  shsize[s] = Math.GetRandomNumber(50)
  Sh[s] = Shapes.AddEllipse(shsize[s],shsize[s])
  Shapes.Move(Sh[s],Shx[s],Shy[s])
EndFor

loop:
For s = 1 to scount
  op[s] = Math.GetRandomNumber(2)
  If op[s] = 1 Then
    vel[s] = .5
  EndIf
  If op[s] = 2 Then
    vel[s] = -.5
  EndIf
  Shx[s] = Shx[s] + vel[s]
  Shy[s] = Shy[s] + vel[s]  
  Shapes.Move(Sh[s],Shx[s],Shy[s])
EndFor
Goto loop

My guess is the problem is here:

op[s] = Math.GetRandomNumber(2)
  If op[s] = 1 Then
    vel[s] = .5
  EndIf
  If op[s] = 2 Then
    vel[s] = -.5
  EndIf

What do I need to do to make the shapes move in independent directions without them jittering?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Auxhi
  • 5
  • 2

2 Answers2

0

I put:

op[s] = Math.GetRandomNumber(2)
 If op[s] = 1 Then
vel[s] = .5
 EndIf
If op[s] = 2 Then
 vel[s] = -.5
EndIf

in the initialization loop, and the shapes don't jitter anymore. My guess is that the "vel" variable was getting reassigned to the shapes each time, causing the jitter.

Auxhi
  • 5
  • 2
  • That's true, you could have also done the if part in the main loop, but that works I think better what you do, that way you don't have to do the if statements each time – Matthew Feb 22 '17 at 03:00
0

Another thing you could do is do frames per second. let all the objects do the math then update it. tHis is ran after all the math has been done so like usually its 60 frames a second so 1/60 to get amount of seconds per frame. you also need a timer to check the amount of time lapsed so you can then give the computer time to move each shape in proper time. if you need more code I will happily provide some.

  GraphicsWindow.Clear()
GraphicsWindow.CanResize = "false"
GraphicsWindow.Height = Desktop.Height-200
GraphicsWindow.Width = Desktop.Width-200

scount = Math.GetRandomNumber(25)
For s = 1 To scount
  Shx[s] = Math.GetRandomNumber(GraphicsWindow.Width-100)
  Shy[s] = Math.GetRandomNumber(GraphicsWindow.Height-100)
  shsize[s] = Math.GetRandomNumber(50)
  Sh[s] = Shapes.AddEllipse(shsize[s],shsize[s])
  Shapes.Move(Sh[s],Shx[s],Shy[s])
   op[s] = Math.GetRandomNumber(2)
EndFor

loop:
Time = Clock.ElapsedMilliseconds
For s = 1 to scount

  If op[s] = 1 Then
    vel[s] = .5
  EndIf
  If op[s] = 2 Then
    vel[s] = -.5
  EndIf
  Shx[s] = Shx[s] + vel[s]
  Shy[s] = Shy[s] + vel[s]  
  Shapes.Move(Sh[s],Shx[s],Shy[s])
EndFor
frames()
Goto loop

Sub frames
     timeend = Clock.ElapsedMilliseconds
  TextWindow.WriteLine((timeend - Time )/1000)
  framelength = 60
  Timeperframe = 1/framelength
  while (((timeend - Time )/1000) <  Timeperframe)
    timeend = Clock.ElapsedMilliseconds

  EndWhile
  Time = Clock.ElapsedMilliseconds

  endsub
Matthew
  • 157
  • 1
  • 9
  • if you want to keep the velocity the same regardless of frames per second, you just have to edit the velocity based off the frames per second. so lets say you always want 5 pixels movement every second regardless of frames, you do 5/frames and that's the amount of pixels moved per second. so if you have 10 frames per second, you'll move 0.5 pixels every frame adding to 5 pixels in that total second. :-D hope this helps. – Matthew Feb 22 '17 at 03:08