Help with program to find average of random psets

by JeremyHopper

Hi, I've posted on this forum before when I needed some help, and the responses I've gotten have been extremely useful. I'm a bit rusty, as I haven't used QB for quite a while. An idea popped into my head the other day of making a program as follows:

It would place a point on the screen at a random location, clear the screen, and then a second point, BUT, the second would be an average between the two (average between the x/y coordinates). So it would generate about 500 different x/y locations and average them out, but in real time, so you would be able to see the point on the screen migrating to the average spot. I've gone to my wits end in the program I've made, which doesn't seem to work:

DIM x(500)
DIM y(500)
z = 0
CLS
SCREEN 13
x1 = INT(RND * 320) + 1
y1 = INT(RND * 200) + 1
x(1) = x1
y(1) = y1
z = 1
FOR i = 2 TO 500
x1 = INT(RND * 320) + 1
y1 = INT(RND * 200) + 1
z = z + 1
g = i
FOR u = 2 TO z
x(g) = (x(z - 1) + x(z))
y(g) = (y(z - 1) + x(z))
NEXT u
x(i) = x(i) + x1
y(i) = y(i) + y1
x(i) = x(i) / 2
y(i) = y(i) / 2
PSET (x(i), y(i)), 15
PSET (x(i), y(i)), 0
NEXT i

I'm sure the answer's obvious, but I just can't see it. Any help would be greatly appreciated.

Posted on Mar 21, 2008, 7:39 AM
from IP address 24.115.134.126

Respond to this message   

Goto Forum Home


Response TitleAuthor and Date
just keep a running totalDavid on Mar 21
 *Thanks so much, I knew I was just making it too complicated :)JeremyHopper on Mar 21