02-29-2004, 08:36 AM
By better I mean more efficient. It should look about the same, but make it smaller(size), faster. And let user have option of side number...
(made it in like 20 mins, feel sorta proud since I haven't touched QB in a few months, and I have a crappy keyboard in which the Ins and Del buttons are moved)
(made it in like 20 mins, feel sorta proud since I haven't touched QB in a few months, and I have a crappy keyboard in which the Ins and Del buttons are moved)
Code:
DEFINT A-Z
RANDOMIZE TIMER
CONST xBound = 310, yBound = 190
SCREEN 13
CLS
TYPE allDots
x AS SINGLE
y AS SINGLE
xAngle AS SINGLE
yAngle AS SINGLE
END TYPE
INPUT "How many sides?", numDots
DIM Dot(1 TO numDots) AS allDots
FOR i = 1 TO numDots
Dot(i).xAngle = (.8 * RND) + .4
Dot(i).yAngle = (.8 * RND) + .4
Dot(i).x = 14
Dot(i).y = 14
NEXT i
DO UNTIL key$ <> ""
FOR i& = 1 TO 20000: NEXT i&
key$ = INKEY$
FOR i = 1 TO numDots - 1
LINE (Dot(i).x, Dot(i).y)-(Dot(i + 1).x + 2, Dot(i + 1).y + 2), 0
NEXT i
LINE (Dot(1).x, Dot(1).y)-(Dot(numDots).x + 2, Dot(numDots).y + 2), 0
FOR i = 1 TO numDots
LINE (Dot(i).x, Dot(i).y)-(Dot(i).x + 2, Dot(i).y + 2), 0, BF
IF Dot(i).x > xBound OR Dot(i).x < 10 THEN Dot(i).xAngle = (.8 * RND + .4) * -SGN(Dot(i).xAngle)
IF Dot(i).y > yBound OR Dot(i).y < 10 THEN Dot(i).yAngle = (.8 * RND + .4) * -SGN(Dot(i).yAngle)
Dot(i).x = Dot(i).x + Dot(i).xAngle
Dot(i).y = Dot(i).y + Dot(i).yAngle
LINE (Dot(i).x, Dot(i).y)-(Dot(i).x + 2, Dot(i).y + 2), 14, BF
NEXT i
FOR i = 1 TO numDots - 1
LINE (Dot(i).x, Dot(i).y)-(Dot(i + 1).x + 2, Dot(i + 1).y + 2), 14
NEXT i
LINE (Dot(1).x, Dot(1).y)-(Dot(numDots).x + 2, Dot(numDots).y + 2), 14
LOOP
earn.