Qbasicnews.com
November 13, 2019, 04:17:53 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Make a better version of this!  (Read 2832 times)
seph
Na_th_an
*****
Posts: 1915



« on: February 29, 2004, 12:36:55 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)

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
Logged

earn.
seph
Na_th_an
*****
Posts: 1915



« Reply #1 on: February 29, 2004, 11:18:51 AM »

I changed it a little so it's less flickery... For some reason now though, shortly into the program, it goes really slow and I think it's from my XP.

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
SCREEN 7, , 0, 1

DIM Dot(1 TO numDots) AS allDots

FOR i = 1 TO numDots
        Dot(i).xAngle = (1.8 * RND) + .7
        Dot(i).yAngle = (1.8 * RND) + .7

        Dot(i).x = 14
        Dot(i).y = 14
NEXT i

DO UNTIL key$ <> ""
        key$ = INKEY$
        PCOPY 0, 1

        CLS
        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 = (1.8 * RND + .7) * -SGN(Dot(i).xAngle)
                IF Dot(i).y > yBound OR Dot(i).y < 10 THEN Dot(i).yAngle = (1.8 * RND + .7) * -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
Logged

earn.
Squirmanator
New Member

Posts: 10


« Reply #2 on: March 06, 2004, 01:07:05 PM »

Well, I like the program, very neat, but your code is good as far as I can see.  After running it, I just wrote my own version, which is a couple lines shorter, and I got rid of the bug where the points get caught outside of the X and Y bounds sometimes.  here it is
Code:


RANDOMIZE TIMER

start:
CLS
INPUT "How many points do you want"; num
 IF num < 1 OR num <> INT(num) THEN GOTO start

DIM X(num), Y(num), Yangle(num), Xangle(num), Xdir(num), Ydir(num)
Xbound = 310
Ybound = 190

 FOR n = 1 TO num
  X(n) = INT(RND * 100) + 50
  Y(n) = INT(RND * 100) + 50
  Ydir(n) = INT(RND * 2) + 1
  Xdir(n) = INT(RND * 2) + 1
  Xangle(n) = INT(RND * 4) + 1
  Yangle(n) = INT(RND * 4) + 1
 NEXT n

SCREEN 7, 1, 0, 1
DO
 FOR n = 1 TO num
  IF X(n) > Xbound OR X(n) < 10 THEN
   Xangle(n) = (INT(RND * 4) + 1) * (-SGN(Xangle(n)))
   IF X(n) < 10 THEN
    X(n) = 11
   ELSE
    X(n) = Xbound
   END IF
  END IF
  IF Y(n) > Ybound OR Y(n) < 10 THEN
   Yangle(n) = (INT(RND * 4) + 1) * (-SGN(Yangle(n)))
   IF Y(n) < 10 THEN
    Y(n) = 11
   ELSE
    Y(n) = Ybound - 1
   END IF
  END IF

  X(n) = X(n) + Xangle(n)
  Y(n) = Y(n) + Yangle(n)
 NEXT n
 CLS
 FOR n = 1 TO num - 1
  LINE (X(n), Y(n))-(X(n) + 1, Y(n) + 1), 2, BF
  LINE (X(n), Y(n))-(X(n + 1), Y(n + 1)), 4
 NEXT n
  LINE (X(num), Y(num))-(X(num) + 1, Y(num) + 1), 2, BF
  LINE (X(num), Y(num))-(X(1), Y(1)), 4
 PCOPY 0, 1
press$ = INKEY$
LOOP UNTIL press$ <> ""
Logged
Zap
Been there, done that
*****
Posts: 1124


« Reply #3 on: June 21, 2004, 06:16:10 AM »

THIS is where the admins should delete these two posts...
Logged

url=http://www.copy-pasta.com]CopyPasta[/url] - FilePasta
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #4 on: June 21, 2004, 06:57:34 PM »

Pathetic behaviour... if I find one more of those, there's gonna be trouble.
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!