Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: NovaProgramming on November 16, 2003, 12:11:02 AM



Title: Making A Spiral
Post by: NovaProgramming 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.


Title: Making A Spiral
Post by: na_th_an 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
radius! = 0
FOR i! = 0 TO 24 STEP .01
   PSET (160 + radius! * COS(i!), 100 - radius! * SIN(i!))
   radius! = radius! + .03
NEXT i!


Title: Making A Spiral
Post by: toonski84 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 :)


Title: re Spiral
Post by: Mango 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


Title: Re: Making A Spiral
Post by: Mango 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
   oldstar(i).z = rad%

 NEXT i
 
LOOP UNTIL INKEY$ <> ""

END


Title: Making A Spiral
Post by: toonski84 on November 16, 2003, 02:57:19 AM
wow, mango, that starfield's insane.  good stuff.


Title: Making A Spiral
Post by: na_th_an on November 16, 2003, 10:58:09 AM
That's the definitive clue:

YOU ARE GEEKS

LOL :D:D:D


Title: Making A Spiral
Post by: toonski84 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.


Title: Making A Spiral
Post by: NovaProgramming on November 17, 2003, 07:25:41 PM
LoL nathan am I a nerd?  I didn't even know hwo to do it.


Title: Making A Spiral
Post by: Antoni Gual 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


Title: Making A Spiral
Post by: Mango on November 17, 2003, 11:11:31 PM
Quote from: "toonski84"
wow, mango, that starfield's insane.  good stuff.


Thanks for the compliment :D

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.


Title: Making A Spiral
Post by: NovaProgramming 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:


Title: Making A Spiral
Post by: na_th_an 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!


Title: Making A Spiral
Post by: Blitz 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.


Title: Making A Spiral
Post by: na_th_an 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.


Title: Making A Spiral
Post by: Blitz on November 18, 2003, 09:51:39 PM
Now now, there's no need to kill yourself. Although it would probably make your mother very happy. But your cat would miss you. Think about the poor cat.


Title: Making A Spiral
Post by: na_th_an on November 18, 2003, 09:57:26 PM
What cat, the one named Blitz? Ah, no, I mistook. Sorry, my bad english. That's not a cat. That's a pussy.


Title: Making A Spiral
Post by: Blitz on November 18, 2003, 10:00:36 PM
You have a pussy? Damn, i didn't now you were a shemale. How's that working out for you?


Title: Making A Spiral
Post by: na_th_an on November 18, 2003, 10:09:47 PM
No, I'm not a shemale. Maybe you got confused 'cause that's common in your family.

If you think that calling me "shemale" is an insult to me, then you must be still living in the past century. Oh, I almost forgot... You are the one who is proud to code in DOS assembly. Then it all makes sense.

And this will be my last quote. I am having so much fun of you, but I just don't want to get banned. I'll leave this thread without further ado, so you can claim your victory and be considered (besides the title of the "best but least used gaming library coder") the very winner.

Good night and don't forget yer diapers.


Title: Making A Spiral
Post by: Blitz on November 18, 2003, 10:28:50 PM
Why would that insult you? You're a shemale and proud of it. We all know that. Well, I code all sorts of asm, real mode, protected mode, long mode, ARM, THUMB. Do you want me to count all the languages and oses i code for as well? Maybe even all the apis? But hey, i think you already know all that but find it funny saying "dos assembly". g'night, and stop dreaming of me.


Title: Making A Spiral
Post by: Rhiannon on November 18, 2003, 10:32:59 PM
Blitz, honestly, you need to turn down your ego a few notches, youre not leaving enough air for the rest of us to breathe. ;)


Title: Making A Spiral
Post by: Blitz on November 18, 2003, 10:36:08 PM
Well rhi, i don't have anymore ego then anyone else here. Though i know saying stuff like that pisses of nathan. Which i find funny. As does he his little comments. And if i did have an ego, it's becuase i have something to back it up with. I'm a nice person, if you don't start to bitch with me. But if you do, i won't back out. And if you look through posts i never were the one starting arguments.


Title: Making A Spiral
Post by: Mango on November 19, 2003, 02:31:45 AM
Quote from: "Blitz"
Well rhi, i don't have anymore ego then anyone else here. Though i know saying stuff like that pisses of nathan. Which i find funny. As does he his little comments. And if i did have an ego, it's becuase i have something to back it up with. I'm a nice person, if you don't start to bitch with me. But if you do, i won't back out. And if you look through posts i never were the one starting arguments.


Blitz...if you post with the sole and explicit purpose of pissing someone off, you are a acting like a jerk, in my book.


Title: Making A Spiral
Post by: relsoft on November 19, 2003, 03:12:19 AM
:roll:  :roll:  :roll:

  8)

I just had to post. ;*)


Title: Making A Spiral
Post by: Blitz on November 19, 2003, 03:26:37 AM
Forget it, i don't have to explain myself to noone. Let's just say that nathan is the bigger jerk. Always trying to get me started. Well nathan, if you can take the game. You shouldn't play it.


Title: Making A Spiral
Post by: adosorken on November 19, 2003, 05:04:05 AM
I think you all need to CALM THE FSCK DOWN. Yeah. I have spoken. Too bad nobody listens.


Title: Making A Spiral
Post by: wildcard on November 19, 2003, 08:54:55 AM
adosorken is right, everyone calm down. You only cause trouble by posting personal insults and such. Don't try "win" the situation with a bigger insult it won't work.


Title: Back to the topic at hand...
Post by: Meg on November 19, 2003, 09:20:38 AM
Here's my spiral:

@

*peace*

Meg.


Title: Making A Spiral
Post by: na_th_an on November 19, 2003, 09:36:07 AM
I am so calmed down that I'm almost asleep. Excuses, forum. That was my fault: I just can't stand Blitz. I have personal reasons and I almost left the forum once for those. I'll try to set my ignore filter to 100%.


Title: Making A Spiral
Post by: toonski84 on November 19, 2003, 11:23:31 AM
..I thought it all was kind of funny.  Think of the cat, folks, won't somebody think of the cat??


Title: Making A Spiral
Post by: Blitz on November 19, 2003, 11:45:38 AM
To be honest nathan, i don't give a rats ass about you. But you keep leaving your comments everywhere. And sooner or later i'll get enough of them.


Title: Making A Spiral
Post by: TheBigBasicQ on November 19, 2003, 11:55:13 AM
Hey look little Blitzy is back with his UGLy library which doesnt work except on his own little computer =P. Stop pissing us all off you midget! There is enough of issues here. So stop creating trouble  :evil:. Dont kill this forum with your flames like you killed Qb45.com's forum OK?

Please dont post here and dirty this board. PM and flame me OK?

I am ignoring this thread  :???:.


Title: Making A Spiral
Post by: na_th_an on November 19, 2003, 12:04:35 PM
Quote from: "Blitz"
To be honest nathan, i don't give a rats ass about you. But you keep leaving your comments everywhere. And sooner or later i'll get enough of them.


And what will happen?
Will you come here and slap me?
Will you hack my computer?

I am fearing.


Title: Making A Spiral
Post by: toonski84 on November 19, 2003, 12:12:10 PM
Oh, jeebus, everybody STOP.

Blitz: Quit hassling Nate, you're just provoking him.
Nate: Leave Blitz alone, you're just provoking him.

I've been here 2 years and the scene for 5.  Whiel that's certainly not long, it's long enough to know nobody ruined anything.  Everyone's just acting like an ass for no good reason.  It's like we need some kind of "time out" chair for the forum.  Compare dicks on the PM system, not here.


Title: Making A Spiral
Post by: Blitz on November 19, 2003, 12:21:33 PM
OMG

Seriously dude, tell me what i have started. I haven't even been here for months nor any other forum. I come back for a week and there are atleast 5-6 people on my back constantly. TheLittleBasicBoy, nathan and the rest. Will you all just get a fucking life and stop these pissing contest with me? I don't give a fuck about any of you. I don't care to have arguments with any of you either. Just leave me the fuck alone, mmkay? If you're that obsessed with me that you can't then you seriously need to get a life. So just let me be.

Now toonski, you look at this thread. Or any other, and tell me if i'm the one provoking anything.


Title: Making A Spiral
Post by: Dav on November 19, 2003, 01:01:07 PM
Wow, this topic really 'spiraled' out of control.

* hides from the bad pun gun *

- Dav