Qbasicnews.com
May 26, 2020, 12:58:53 AM
 Welcome, Guest. Please login or register. 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length
 Home Help Search Login Register
 Pages: [1] 2 3
 Author Topic: Making A Spiral  (Read 7920 times)
NovaProgramming
Been there, done that

Posts: 1025

 « on: November 16, 2003, 12:11:02 AM »

I have been fidgeting around with QBasic trying to make a spiral thingy... but I can't do it!  I don't really care whether or not it is a square spiral or a circular one... but I don't know how.  The original idea was to ...  (pardon my newbie coding) ...

Code:

SCREEN 13
loops = 0
FOR i = 1 to 50
loops = loops + 1
IF loops = 5 THEN loops = 1
IF loops = 1 THEN DRAW "Ui"
IF loops = 2 THEN DRAW "Ri"
IF loops = 3 THEN DRAW "Di"
IF loops = 4 THEN DRAW "Li"
NEXT I

You know, something like that, where it would draw a line the direction (depending on the number of "loops" and the length depending on the value of 'i')

However, it doens't work, so I was wondering what the most condensed way to make a spiral is.  I guess this is more of a challenge... but hey, it's not a very good challenge.  Thanks.
 Logged

ovaProgramming.

One night I had a dream where I was breaking balls.  The next morning, BALLSBREAKER was born.

Quote from: "Haye, Phillip J."
Excellent.  Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it .
-----------------------------
na_th_an
*/-\*

Posts: 8244

 « Reply #1 on: November 16, 2003, 12:16:23 AM »

Use STR\$:

Code:
DRAW "u"+LTRIM\$(STR\$(i))

You need the string to contain the actual number. The interpreter reads "ui" and that's "ui". "i" isn't a variable inside the string. It is just "i".

To make a nice spiral you can use PSET, COS and SIN

Code:
SCREEN 1
FOR i! = 0 TO 24 STEP .01
PSET (160 + radius! * COS(i!), 100 - radius! * SIN(i!))
NEXT i!
 Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
toonski84
__/--\__

Posts: 2567

 « Reply #2 on: November 16, 2003, 12:19:38 AM »

Code:
SCREEN 13

pi = ATN(1) * 4
theta = 0
PSET (319, 99)
FOR distance = 160 TO 0 STEP -1
theta = theta + 8
x = COS(theta * pi / 180) * distance
y = SIN(theta * pi / 180) * distance
LINE -(x + 159, y + 99)
NEXT distance

if you can't figure out how it works, pm me and i'll help you out.

EDIT:  Nuts, nate beat me to it
 Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Mango
Wandering Guru

Posts: 360

 « Reply #3 on: November 16, 2003, 12:40:13 AM »

Re Spirals...this one's a bit different than nate's and aga's...it doesn't have constant spacing.  The code is tediously long...but it gives the nice effect of having the spiral drawn from the inside out...getting larger as it grows...

Code:
'************************************
'*2002 Joe Campbell
'*I wrote the base of this program as an excercise trying to figure out how to code for a spiral
'*I added the superfulous stuff and it makes a pretty nice screen saver
'*Enjoy!!!
'*************************************

RANDOMIZE TIMER

begin:
SCREEN 12
CLS

DO
rf = .001 + RND * 1.5       'how tight is the spiral
maxsize = RND * 600         'max size
xini = RND * 640            'position
yini = RND * 480            'position
cini = (RND * 16) - 1       'color
r = 1
x = -.707 * r
DO
FOR j = 1 TO 4        'the 4 quadrants of the expanding circle
p = rf / 10
SELECT CASE j
CASE 1
b = 1
c = 1
d = 1
xy = -1
CASE 2
b = 1
c = 1
d = -1
xy = 1
CASE 3
b = -1
c = -1
d = 1
xy = -1
CASE 4
b = -1
c = -1
d = -1
xy = 1
END SELECT
x = x + d
DO WHILE x <= .707 * r AND x >= -.707 * r
y = SQR((r ^ 2) - (x ^ 2))
IF xy = 1 THEN SWAP x, y
PSET (xini + x * b, yini + y * c), cini
IF xy = 1 THEN SWAP x, y
x = x + d
r = r + p
FOR g = 1 TO 10                  'erase 10 points for each spiral point
PRESET (RND * 640, RND * 480)
NEXT g
LOOP
NEXT j
LOOP UNTIL r > maxsize
a\$ = INKEY\$
LOOP UNTIL a\$ <> ""
PRINT "Play again (y/n)"
DO
a\$ = INKEY\$
LOOP UNTIL a\$ <> ""
IF a\$ = "y" OR a\$ = "Y" THEN GOTO begin
END
 Logged
Mango
Wandering Guru

Posts: 360

 « Reply #4 on: November 16, 2003, 12:58:05 AM »

Quote from: "NovaProgramming"
I have been fidgeting around with QBasic trying to make a spiral thingy... I don't really care whether or not it is a square spiral or a circular one.

Here's kinda a square spiral...I posted it a while back in the starfield challenge...I can make it a bit shorter (see the 25 line challenge) but this works....

Code:
'Through the ring of saturn...
'JKC 2003

DEFINT I
DEFINT T
TYPE star
x AS INTEGER
y AS INTEGER
z AS INTEGER
END TYPE

starnum% = 300
xoff% = 575
yoff% = 300
depth% = 300

DIM astar(0 TO starnum% + 40) AS star
DIM oldstar(0 TO starnum% + 40) AS star

RANDOMIZE TIMER

DO WHILE i < starnum%
FOR t = 0 TO 640 STEP 40
i = i + 1
IF i > starnum% THEN EXIT DO
astar(i).x = t
astar(i).y = 0
astar(i).z = i
NEXT t
FOR t = 0 TO 480 STEP 40
i = i + 1
IF i > starnum% THEN EXIT DO
astar(i).x = 640
astar(i).y = t
astar(i).z = i
NEXT t
FOR t = 640 TO 0 STEP -40
i = i + 1
IF i > starnum% THEN EXIT DO
astar(i).x = t
astar(i).y = 480
astar(i).z = i
NEXT t
FOR t = 480 TO 0 STEP -40
i = i + 1
IF i > starnum% THEN EXIT DO
astar(i).x = 0
astar(i).y = t
astar(i).z = i
NEXT t
LOOP

FOR i = starnum% TO starnum% + 40
astar(i).x = RND * 640
astar(i).y = RND * 480
astar(i).z = RND * depth%
NEXT i
starnum% = starnum% + 40

SCREEN 11

DO
FOR i = 0 TO starnum%
IF astar(i).z < 1 THEN astar(i).z = depth% ELSE astar(i).z = astar(i).z - 1
zscale = astar(i).z / depth%    'scales 0 to 1
scalex% = astar(i).x / (1 + (5 * zscale))
scaley% = astar(i).y / (1 + (5 * zscale))
xoffset = xoff% * zscale
yoffset = yoff% * zscale
x = xoffset + scalex%
y = yoffset + scaley%
rad% = 5 / (1 + astar(i).z / 20)

FOR p% = 0 TO oldstar(i).z
CIRCLE (oldstar(i).x, oldstar(i).y), p%, 0
NEXT p%
FOR p% = 0 TO rad%
CIRCLE (x, y), p%
NEXT p%

oldstar(i).x = x
oldstar(i).y = y

NEXT i

LOOP UNTIL INKEY\$ <> ""

END
 Logged
toonski84
__/--\__

Posts: 2567

 « Reply #5 on: November 16, 2003, 02:57:19 AM »

wow, mango, that starfield's insane.  good stuff.
 Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
na_th_an
*/-\*

Posts: 8244

 « Reply #6 on: November 16, 2003, 10:58:09 AM »

That's the definitive clue:

YOU ARE GEEKS

LOL :D:D
 Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
toonski84
__/--\__

Posts: 2567

 « Reply #7 on: November 16, 2003, 12:19:47 PM »

...I think that was settled when we started attending a forum about programming on an archaic, mediocre 1987 dos compiler.
 Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
NovaProgramming
Been there, done that

Posts: 1025

 « Reply #8 on: November 17, 2003, 07:25:41 PM »

LoL nathan am I a nerd?  I didn't even know hwo to do it.
 Logged

ovaProgramming.

One night I had a dream where I was breaking balls.  The next morning, BALLSBREAKER was born.

Quote from: "Haye, Phillip J."
Excellent.  Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it .
-----------------------------
Antoni Gual
Na_th_an

Posts: 1434

 « Reply #9 on: November 17, 2003, 09:28:16 PM »

Don't forget Wizardlife's entry for Rel screensaver compo:
Code:

1 SCREEN 12
2 FOR colour = 0 TO 15
3 PALETTE colour, colour * 4
4 NEXT
5 angle! = angle! + .1
6 colour = colour + 1
7 IF colour > 15 THEN colour = 0 ELSE IF angle! > 360 THEN angle! = angle! - 360
8 PSET (INT(SIN(angle!) * angle!) + 320, INT(COS(angle!) * angle!) + 240), colour
9 IF INKEY\$ = "" THEN GOTO 5
 Logged

Antoni
Mango
Wandering Guru

Posts: 360

 « Reply #10 on: November 17, 2003, 11:11:31 PM »

Quote from: "toonski84"
wow, mango, that starfield's insane.  good stuff.

Thanks for the compliment

The "engine" essentially gives me a 3d screen that is easy to address as x-y-z.  If you are interested...in my starfield challenge entry I put 3 closely related programs...look at the last one.  I put text on the y-z plane, and it makes a nice flying banner comming at you.  If you put text on the x-y plane it doesn't look so cool because each "page" obstructs the next.  if you put the text on the x-z plane it's like the starwars intro text.
 Logged
NovaProgramming
Been there, done that

Posts: 1025

 « Reply #11 on: November 18, 2003, 06:55:25 PM »

Good thing I posted this in the "Newbie Help" section, lol... I don't know how to do any of this stuff!  I thought THIS was really cool though... and PARDON THE NEWBIE PROGGING because that's what I am  :king:
Code:

SCREEN 12
DO
LOOPS = LOOPS + 1
IF LOOPS = 640 + 640 + 480 + 480 THEN LOOPS = 1
IF LOOPS < 640 THEN X = X + 1
IF LOOPS > 640 AND LOOPS < 640 + 430 THEN Y = Y + 1
IF LOOPS > 640 + 480 AND LOOPS < 640 + 640 + 480 THEN
X = X - 1: END IF
IF LOOPS > 640(2) + 480 AND LOOPS < 640(2) + 480(2) THEN
Y = Y - 1: END IF
C = C + 1
IF C = 12 THEN C = 9
LINE (320, 240) - (X, Y), c
LOOP UNTIL INKEY\$ <> ""

Kinda looks weird... but the coding is all unprofessional  :oops:

Oh well, that's why it's in the NEWBIE HELP  :bounce:
 Logged

ovaProgramming.

One night I had a dream where I was breaking balls.  The next morning, BALLSBREAKER was born.

Quote from: "Haye, Phillip J."
Excellent.  Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it .
-----------------------------
na_th_an
*/-\*

Posts: 8244

 « Reply #12 on: November 18, 2003, 09:02:47 PM »

Quote from: "NovaProgramming"
Kinda looks weird... but the coding is all unprofessional  :oops:

What it does is what it's important, no how "1337" is your code

Ass I told one, nobody is born knowing. Well, except Blitz, of course. You like what you do, and you put your effort. You'll be a great coder for sure!
 Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Blitz
I hold this place together

Posts: 853

 « Reply #13 on: November 18, 2003, 09:16:42 PM »

I worked hard for my knowledge and experience.
Now, i know it must be hard that i'm so much better then you nathan.  I know that your cry yourself to sleep every night becuase you're not 1/100 th of a coder i am. But there's always smarter then smart nathan. I happen to be that one to you. But i'm sure there's atleast a 12 people or so on this world who are smarter then me.
 Logged

oship me and i will give you lots of guurrls and beeea
na_th_an
*/-\*

Posts: 8244

 « Reply #14 on: November 18, 2003, 09:27:47 PM »

Yeah, in fact I am crying right now.

You ruined the goal in my life: being better code than you. Now I give up. I'll suicide tomorrow. I can't code using a deprecated language for a deprecated operating system. My life has no sense.
 Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
 Pages: [1] 2 3