I've posted this in the homework section since it is an assinment.(adsbygoogle = window.adsbygoogle || []).push({});

I am required to write a program in VB than creats N number of 'particles' in a random position within a caresian co-ordinate system. The x and y axis are to go from -100 to 100 and be bounded i.e if a particle's x or y component reach 100 or -100 then it`s angle of incidence must equal it angle of reflection.

Now I`ve started off by writing a simplified program for a single particle that just bounces around in it's 'box' heres the code so you can see what i`ve done.

The first problem i have is i can`t randdomly generate the inital (x, y) co-ordinates, remebersinf the Rnd command creates a positive number between 0 and 1. Scaling this isn`t a problem, but getting it to appear anywhere other than (x, y) for X>0 and y>0, is causing me a head ache.Code (Text):

Option Explicit

Dim x, y, speed_x, speed_y As Double

Dim i, j, delta_t, t As Long

Private Sub Command1_Click()

[COLOR="SeaGreen"]'defines the dimentions of the box[/COLOR]

Picture1.Scale (-100, 100)-(100, -100)

[COLOR="seagreen"]'declare variables[/COLOR]

speed_x = Rnd * 10

speed_y = Rnd * 10

delta_t = 1

[COLOR="seagreen"]'make the circle move[/COLOR]

For t = 1 To 200 Step delta_t

x = x + speed_x

y = y + speed_y

If x > 95 Or x < -95 Then speed_x = -speed_x

If y > 95 Or y < -95 Then speed_y = -speed_y

Call plot(x, y)

Call Delay(t)

Picture1.Cls

Next t

End Sub

[COLOR="seagreen"]'create a purple circle in a subroutine called plot (x,y)[/COLOR]

Sub plot(x, y)

Picture1.FillStyle = 0

Picture1.FillColor = RGB(255, 0, 255)

Picture1.Circle (x, y), 5, RGB(255, 0, 255)

End Sub

[COLOR="seagreen"]'pause circle with a subroutine called delay (t)[/COLOR]

Sub Delay(t)

For i = 1 To 1000000

Next i

End Sub

Once i can work than out i don`t know how to generate more than one circle in a picture box?

PLEASE, PLEASE HELP

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: Visual Basics programming help required

**Physics Forums | Science Articles, Homework Help, Discussion**