Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need a small algorithm to make a square in a small FOR loop
#1
I have a popular game I know I can make into 10 lines but first I need some algorithm to make a square out of 32 dots in mode 0. Here:

Code:
FOR i% = 1 TO 32
    LOCATE x%, y%
    PRINT "*"
NEXT i%

And have x% and y% use i% somehow, possibly with MOD or int.divide and have them make a square like this:

Code:
********
*      *
*      *
*      *
*      *
*      *
*      *
********
earn.
Reply
#2
mmm

Code:
FOR i%=1 TO 32
   LOCATE y%-1+i%,x%
   IF i%=1 OR i%=32 THEN
      PRINT STRING$(32,"*")
   ELSE
      PRINT "*";SPACE$(30);"*"
   END IF
NEXT
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
[syntax="qbasic"]PRINT "********"
FOR I%=1 TO 8
PRINT "* *"
NEXT
PRINT "********"[/syntax]

I don't think you can get it smaller, and that will only work in the top left corner of the screen.


Unless you really really need to be able to define the box by the use of I% then here's some good code, 2 lines, for locating and printing it.

[syntax="qbasic"]LOCATE 10, 1 'Locate Y here
'Then add the x amount of space infron of the ******** as shown:

thing$ = " ********"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "* *"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "* *"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "* *"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "* *"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "* *"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "* *"
thing$ = thing$ + SPACE$(72)
thing$ = thing$ + "********"
PRINT thing$;[/syntax]

I divided the string so it would be easier to see, just make it a single line before you release it, and you have a box in 2 lines.

You could even make it a single line by using enough spaces in fron of it.

The bad thing is, you cant write anything before using this, (unless you use locate) and everything done before will be erased.
Reply
#4
Sorry, I should have been more specific.

I need the loop to make the Square be created in the same way you see lights on a restaurant sign flash, in a circular fashion. I know it Must be possible...
earn.
Reply
#5
Then you need 4 for/next loops..

It might be possible with only 2, I don't have time to check, sorry.


you want it to actually draw the box, in a circular fashion?

Like (roughly)
Code:
*
Code:
**
Code:
***
Code:
****
Code:
****
   *
Code:
****
   *
   *

Code:
****
   *
   *
   *

Code:
****
   *
   *
   *
   *

Code:
****
   *
   *
   *
  **

Code:
****
   *
   *
   *
***

Code:
****
   *
   *
   *
****

Code:
****
   *
   *
*  *
****

Code:
****
   *
*  *
*  *
****

Code:
****
*  *
*  *
*  *
****

Something like that?



(sorry for the long, useless post, just clarifying)
Reply
#6
Code:
WIDTH 80,50:x%=2: y%=2

FOR i%=1 TO 128
   IF i%<33 THEN
      LOCATE y%, x%-1+i%
   ELSEIF i%<65 THEN
      LOCATE y%+i%-33,x%+31
   ELSEIF i%<97 THEN
      LOCATE y%+31,x%+96-i%
   ELSE
      LOCATE y%+128-i%,x%
   END IF
   PRINT "*"
NEXT i%
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)