Qbasicnews.com

QbasicNews.Com => Challenges => Topic started by: ravenxau on March 31, 2004, 07:57:12 AM



Title: raycaster in 6 lines
Post by: ravenxau on March 31, 2004, 07:57:12 AM
here is a raycaster i knocked up in 6-lines. anybody else want to share their take on the subject? (btw - this code is gwbasic compatible too!)

Matt :)


Code:
1 DIM L(7, 7): FOR Y = 0 TO 7: FOR X = 0 TO 7: READ L(X, Y): NEXT X: NEXT Y: X = 24: Y = 24: F = 45: SCREEN 1
2 FOR S = -160 TO 149 STEP 10: R = F + (S * .1875): R = R + 360 * ((R > 360) - (R < 0)): XI = COS(R / 57): YI = SIN(R / 57): X1 = X: Y1 = Y
3 X1 = X1 + XI: Y1 = Y1 + YI: IF L(X1 / 16, Y1 / 16) = 0 THEN GOTO 3
4 D = ABS((X - X1) / COS(R / 57)): H = (1816 / D): LINE (S + 160, 100 - H)-(S + 169, 100 + H), 1, BF: LINE (S + 160, 0)-(S + 169, 99 - H), 0, BF: LINE (S + 160, 101 + H)-(S + 169, 320), 0, BF
5 NEXT S: A$ = INKEY$: F = F + 5 * (A$ = ",") - 5 * (A$ = "."): F = F - 355 * (F = -5) + 360 * (F = 365): IF A$ = " " AND (L((X + COS(F / 57)) / 16, (Y + SIN(F / 57)) / 16) = 0) THEN X = X + COS(F / 57): Y = Y + SIN(F / 57)
6 GOTO 2: DATA 1,1,1,1,1,1,1,1,1,0,0,1,0,0,0,1,1,1,0,1,0,1,0,1,1,0,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1


Title: raycaster in 6 lines
Post by: na_th_an on March 31, 2004, 09:23:44 AM
Really cool, and impressive.

But not 6 lines: you cheated using ":" :P. Anyways, impressive :)


Title: raycaster in 6 lines
Post by: relsoft on April 01, 2004, 07:56:48 AM
Hah! With colon joined lines, I could make a raycaster in 1 line!!! LOL

Nice job though. :*)


Title: raycaster in 6 lines
Post by: ravenxau on May 05, 2004, 03:20:37 AM
it is 6 lines of code. i forgot to specify it is 6 lines of GW-BASIC compatible code. sorry for the misdirection. :)


Title: raycaster in 6 lines
Post by: relsoft on May 05, 2004, 08:39:24 AM
Actually I was with the assumption that each line should not have colons for joining.

Like this:



Code:

'Felix the Helix
'By Jelly

1 IF I% = 0 THEN SCREEN 7, , 0, 1 ELSE PCOPY 0, 1
2 A! = (A! + .03) * -(A! < 6.283186)
3 FOR I% = 0 TO 200
4 x! = ((50 * COS(4 * 3.141593 / 200 * I%)) * (COS(A!) * COS(A!)) + (50 * SIN(8 * 3.141593 / 200 * I%)) * (SIN(A!) * SIN(A!) * COS(A!) - COS(A!) * SIN(A!)) + (I% - (200 / 2)) * (COS(A!) * SIN(A!) * COS(A!) + SIN(A!) * SIN(A!)))
5 y! = ((50 * COS(8 * 3.141593 / 200 * I%)) * (COS(A!) * SIN(A!)) + (50 * SIN(8 * 3.141593 / 200 * I%)) * (COS(A!) * COS(A!) + SIN(A!) * SIN(A!) * SIN(A!)) + (I% - (200 / 2)) * (-SIN(A!) * COS(A!) + COS(A!) * SIN(A!) * SIN(A!)))
6 z! = ((50 * COS(8 * 3.141593 / 200 * I%)) * (-SIN(A!)) + (50 * SIN(8 * 3.141593 / 200 * I%)) * (SIN(A!) * COS(A!)) + (I% - (200 / 2)) * COS(A!) * COS(A!))
7 IF I% > 1 THEN CIRCLE ((160 + (256 * x! \ (256 - z!))), (100 - (256 * y! \ (256 - z!)))), 512 \ (256 - z!), (A! * 57.29577 + I%) AND 15 ELSE LINE (0, 0)-(319, 199), 0, BF
8 NEXT I%
9 IF INKEY$ = "" THEN 1



Code:


'Translucency is me! Redux...
'by Jelly

1 IF i& = 0 THEN SCREEN 13 ELSE IF i& <= 256 THEN PALETTE i& - 1, 65536 * INT(32 - 31 * SIN(i& * 3.14151693# / 128)) + 256 * INT(32 - 31 * SIN(i& * 3.14151693# / 64)) + INT(32 - 31 * SIN(i& * 3.14151693# / 32)) ELSE z% = 64 * (((i& AND 1) = 1) OR 1)
2 IF xa% = 0 THEN DIM Lsin%(1024) ELSE i& = (i& + 1) AND &H7FFFFFFF
3 FOR ya% = 0 TO 127
4 IF i& < 385 THEN Lsin%(i&) = SIN((i&) / 25) * 64 ELSE xsin% = SIN((ya% + i&) / 20) * 32
5 FOR xa% = 0 TO 254
6 z% = -z%
7 IF i& > 384 THEN PSET (32 + xa%, 36 + ya%), (xa% + xsin%) + Lsin%(ya% + 64 + z%) + Lsin%(xa% + ya%)
8 NEXT xa%, ya%
9 IF INKEY$ = "" THEN 1




Code:

'Lovelier, Wobblier and Bigger!!!!
'by Jelly

1 IF i& = 0 THEN SCREEN 13 ELSE IF i& <= 256 THEN PALETTE i& - 1, 65536 * INT(32 - 31 * SIN(i& * 3.14151693# / 128)) + 256 * INT(32 - 31 * SIN(i& * 3.14151693# / 64)) + INT(32 - 31 * SIN(i& * 3.14151693# / 32))
2 IF xa% = 0 THEN DIM Lsin%(256, 3) ELSE i& = (i& + 1) AND &H7FFFFFFF
3 FOR ya% = 0 TO 127
4 IF i& < 257 THEN Lsin%(i&, 0) = SIN((i&) / 30) * 60 ELSE xsin% = SIN((ya% + i&) / 20) * 50
5 FOR xa% = 0 TO 255
6 PSET (32 + xa%, 36 + ya%), (xa% + xsin%) XOR (ya% + (Lsin%((xa%), 0)))
7 NEXT xa%, ya%
8 IF INKEY$ = "" THEN 1



Note that I had to strain my brain just to get it to work fast enough and there is no colon joined line. ;*)


Title: raycaster in 6 lines
Post by: Zack on May 05, 2004, 10:38:08 AM
Waitasec...Relsoft, YOU'RE Jelly?


Title: raycaster in 6 lines
Post by: wildcard on May 05, 2004, 03:51:11 PM
Great work.

Using the colon has it limitis, e.g. you can't do that much in terms of if statements/etc. Remeber pasco's climber that was using colons


Title: raycaster in 6 lines
Post by: relsoft on May 07, 2004, 08:17:34 AM
Quote from: "Zack"
Waitasec...Relsoft, YOU'RE Jelly?


 :oops:  :oops:


Title: raycaster in 6 lines
Post by: oracle on May 07, 2004, 08:54:57 PM
Eh????

I suspected you two were "related" after the 9-line compo at QBNZ, but you're actually the same person??

What, did you forget your password or something? ;)


Title: raycaster in 6 lines
Post by: relsoft on May 08, 2004, 03:34:39 AM
LOL. Nahh. I was making my first entry, the "circle interference" while teaching my daughter how to read the ABC's.  And my daughter kept on going back to "J" 'cause she likes the picture.  Guess what? The pic on the letter J is Jelly. :*)

So I guess it stuck. :*)


Title: raycaster in 6 lines
Post by: oracle on May 09, 2004, 06:41:32 PM
Hahaha, the wierd ways nicks come about, eh?


Title: raycaster in 6 lines
Post by: relsoft on May 12, 2004, 08:15:07 AM
Yeah, I wouldn't have used "Zebra" or "Xylophone" though. :*)


Title: raycaster in 6 lines
Post by: Radical Raccoon on May 29, 2004, 06:52:00 AM
Hey! Jelly is like, plasma! So you are Plasma too? ;)


Title: raycaster in 6 lines
Post by: Plasma on May 29, 2004, 02:46:44 PM
pfffffft :P


Title: raycaster in 6 lines
Post by: Dr_Davenstein on May 29, 2004, 03:04:42 PM
Well, that would realy suck. He would be the only smart  person in here... might as well call it  relsoftnews.com. :lol:


Title: raycaster in 6 lines
Post by: KiZ on May 29, 2004, 05:05:51 PM
Well, they both are ASM geniuses, and how come we have never seen them in the same room together?

 :shifty:


Title: raycaster in 6 lines
Post by: relsoft on May 31, 2004, 05:16:21 AM
Quote from: "Dr_Davenstein"
Well, that would realy suck. He would be the only smart  person in here... might as well call it  relsoftnews.com. :lol:


Errr.

Plasma = USA ( Coolest salaries abound there)

Rel = Philippines (Hell on Earth)

* Beam me up Jon. :*) j/k


Title: here's a way to cheat
Post by: wallace on October 11, 2004, 05:54:15 PM
raycast$ = 'machine code for raycaster
CALL Absolute(raycast,...)


2 lines :-)

Cheap isn't it?


Title: raycaster in 6 lines
Post by: whitetiger0990 on October 11, 2004, 10:05:06 PM
Will be if you actually do it =P


Title: raycaster in 6 lines
Post by: Z!re on October 12, 2004, 07:27:57 AM
Not that hard, just make a raycaster, and compile it to a com file (that is, no exe header)

And then just load that up into your program.



Wonder if it could be done in one line, with the data directly on the call abs statement, instead of a variable.. as long as it doesent return anything, it should be fine... hmm...


Title: raycaster in 6 lines
Post by: VonGodric on October 12, 2004, 08:12:24 AM
Really cool, never done anything of that kind though :oops: So just for better understandability(for myself) I rewrote it to n+1 lines, but gives a better overview.

Code:
1 DIM L(7, 7)
FOR Y = 0 TO 7
   FOR X = 0 TO 7
      READ L(X, Y)
   NEXT X
NEXT Y
X = 24
Y = 24
F = 45
SCREEN 13

2  FOR s = -160 TO 149 STEP 10
      R = F + (s * .1875)
      R = R + 360 * ((R > 360) - (R < 0))
      XI = COS(R / 57)
      YI = SIN(R / 57)
      X1 = X
      Y1 = Y
3     X1 = X1 + XI
      Y1 = Y1 + YI
      IF L(X1 / 16, Y1 / 16) = 0 THEN GOTO 3
4     D = ABS((X - X1) / COS(R / 57))
      H = (1816 / D)
      LINE (s + 160, 100 - H)-(s + 169, 100 + H), 1, BF
      LINE (s + 160, 0)-(s + 169, 99 - H), 0, BF
      LINE (s + 160, 99 - H)-(s + 169, 99 - H), 4 'this line is also my creation
      LINE (s + 160, 101 + H)-(s + 169, 320), 0, BF
      LINE (s + 160, 101 + H)-(s + 169, 101 + H), 2 'and added this line
5  NEXT s

   a$ = INKEY$
   F = F + 5 * (a$ = ",") - 5 * (a$ = ".")
   F = F - 355 * (F = -5) + 360 * (F = 365)
   IF a$ = " " AND (L((X + COS(F / 57)) / 16, (Y + SIN(F / 57)) / 16) = 0) THEN
      X = X + COS(F / 57)
      Y = Y + SIN(F / 57)
   ELSEIF a$ = CHR$(27) THEN END
   END IF
6  GOTO 2

DATA 1, 1, 1, 1, 1, 1, 1 ,1
DATA 1, 0, 0, 1, 0, 0, 0, 1
DATA 1, 1, 0, 1, 0, 1, 0, 1
DATA 1, 0, 0, 0, 0, 1, 0, 1
DATA 0, 1, 1, 1, 0, 1, 0, 1
DATA 1, 0, 1, 1, 0, 1, 1, 1
DATA 1, 0, 0, 0, 0, 0, 0, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1


Title: raycaster in 6 lines
Post by: Neo on October 29, 2004, 09:48:10 AM
Sorry for reviving this topic, but I really have to say something :P

Quote from: "Zack"
Waitasec...Relsoft, YOU'RE Jelly?

HA! I already suspected that! ;) That's why you won 1st prize on the 9-line gfx demo contest, and I got 2nd prize! :D (Btw, I also had a translucent plasma entry ;))

Quote from: "relsoft"
Yeah, I wouldn't have used "Zebra" or "Xylophone" though. :*)

Jelly is cool ;) lol

Quote from: "Radical Raccoon"
Hey! Jelly is like, plasma! So you are Plasma too?

Yeah right... then everyone is everyone. So I'm oracle because Neo has something to do with The Oracle in the Matrix... ;)

Quote from: "Dr_D"
Well, that would realy suck. He would be the only smart person in here... might as well call it relsoftnews.com.

Because he is everyone here? Or is it just because because we aren't smart? ;)

Quote from: "dark"
Well, they both are ASM geniuses, and how come we have never seen them in the same room together?

Hmn, good question ;). #1: Plasma is always busy. #2: Relsoft probably can't go to America for no reason ;)

Quote from: "Rel"
Hell on Earth

Since when are the Phillipines hell on earth? And since when is the USA the country with the coolest salaries? ;)

Quote from: "wallace"
raycast$ = 'machine code for raycaster
CALL Absolute(raycast,...)

You are allowed to do this, unless you have to make it in QB. That code technically isn't QB ;)


Title: raycaster in 6 lines
Post by: relsoft on October 30, 2004, 12:46:59 AM
Neo: The place itself is pretty good. But bad governance is ruining everything. Err... A guy who operates a xerox copy machine in the sates for 6 hours makes a lot more than a surgeon here. :*)

Sigh, this "relsoft is smart thingy" is so lame.  Heh, I could never make a half decent gui even if I try to.

;*)


Title: raycaster in 6 lines
Post by: TheBigBasicQ on October 30, 2004, 10:54:35 AM
Rel, stop comparing Phillipines to US. The cost of living is proportional to their salaries ;). The government eats away ~40-50% of their salaries but they get facilities in return. But that really leaves you only half of you're salary to spend =P. Also, converting USD to Pesos(did u know the acronym for pesos is PHP =P?) isnt very wise either. The conversion rate is very high ;).


Title: raycaster in 6 lines
Post by: adosorken on October 30, 2004, 10:58:50 AM
Quote from: "Neo"
Because he is everyone here? Or is it just because because we aren't smart? ;)

Nah, everyone (with a few exceptions) here is smart in their own little ways. You gotta be a cut above the rest of humanity to be able to withstand the suffrage and outright masochistic lifestyle of a computer programmer. :D


Title: raycaster in 6 lines
Post by: Z!re on October 30, 2004, 02:25:48 PM
:lol:  Hear hear...


Title: Re: raycaster in 6 lines
Post by: kinem on April 14, 2010, 02:19:39 AM
Hi. Sorry to revive this years-dead thread, but I thought it was a fun challenge to make the shortest 1-line RC!  You can make it into 1 line in QB with a bit of editing.  All fixed up, note the changes :)  Press , . to turn, space forward, esc.

Code:
FOR X = 0 TO 63:
L(X AND 7, X\8)=VAL(MID$("1111111110010001100409011000010120110701101101011000000112345671",X+1,1)):
NEXT: X = 1.5:Y = X: F = ATN(1): u = F / 9: SCREEN 7: DO: FOR S = -160 TO 159: t = ATN(S / 304): R = F + t:
I = COS(R) / 80:J = SIN(R) / 80: o = X: p = Y: n = 0: DO: o = o + I: p = p + J: n = n + 1: c = L(o, p): LOOP UNTIL c:
H = 9000 / n / COS(t): v = S + 160: LINE (v, 0)-(v, 99 - H), 0: LINE -(v, 99 + H), c: LINE -(v, 319), 8: NEXT:
a = INP(96): I = COS(F) / 9: J  = SIN(F) / 9: m = a = 57 AND L(X + I, Y + J) = 0: X = X - I * m: Y = Y - J * m:
F = F + u * ((a = 51) - (a = 52)): LOOP UNTIL a = 1


Title: Re: raycaster in 6 lines
Post by: ravenxau on September 25, 2016, 07:24:23 AM
Thought I'd bump this thread, as I did start it 12 years ago....I have just started programming in qbasic again...using version 1.1 under dosbox....will be interesting to revisit some of my old stuff and see if it goes anywhere new........


Title: Re: raycaster in 6 lines
Post by: Dav on October 01, 2016, 02:05:18 PM
Hi ravenau.  I keep coming back to QB programming too.  Have you tried QB64?  These raycaster codes will run in that too, compile to EXE and doesn't need DosBox. 

Anyway, glad to see you (and anyone!) around here. :D

- Dav


Title: Re: raycaster in 6 lines
Post by: Dr_Davenstein on October 01, 2016, 08:43:26 PM
Yes sir. Studying stuff like this is what made me who I am today... As far as programming goes. :)