Author Topic: Faux 3d Rotation!  (Read 3653 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Faux 3d Rotation!
« on: November 26, 2020, 12:58:11 pm »
Don't ask me I just blindfolded myself and typed this monstrosity up. Wacha think?

Code: QB64: [Select]
  1. 'Faux 3d rotation thingy with (almost)no math
  2. 'Cobalt 11/25/2020
  3.  
  4. '--------Obligitory Start Up stuff-----------
  5. Layer1& = _NEWIMAGE(640, 480, 12)
  6. layer2& = _NEWIMAGE(120, 64, 12)
  7. _DEST layer2&
  8. PRINT "ESC to Quit"
  9. PRINT "Up - Faster"
  10. PRINT "Down - Slower"
  11. _DEST Layer1&
  12. Limit%% = 24
  13. ExitFlag%% = 0
  14. '---------------------------------------------
  15.  
  16. '------------------Main Loop-------------------
  17.  _PUTIMAGE (0, 0), layer2&, Layer1& 'Place options on plate
  18.  FOR n = 0 TO 75 'draw the thingy
  19.   PSET (150 + n + n, 200)
  20.   DRAW "TA" + STR$(C)
  21.   DRAW "F" + STR$(n)
  22.   DRAW "G" + STR$(n)
  23.   DRAW "L" + STR$(n)
  24.   DRAW "H" + STR$(n)
  25.   DRAW "U" + STR$(n)
  26.   DRAW "E" + STR$(n)
  27.   DRAW "R" + STR$(n)
  28.   DRAW "D" + STR$(n)
  29.  _LIMIT Limit%% 'control our speed
  30.  IF Limit%% = 120 THEN LOCATE 2, 16: COLOR 14: PRINT "Max Speed": COLOR 15 'you can stop pressing up now
  31.  IF Limit%% = 12 THEN LOCATE 3, 16: COLOR 12: PRINT "Min Speed": COLOR 15 'you can stop pressing down now
  32.  _PUTIMAGE , Layer1&, _DISPLAY 'move our buffoonery to the screen
  33.  CLS 'clear the plate
  34.  C = C + 1: IF C = 360 THEN C = 0 'rotation... its all about rotation!
  35.  '--------------Controls---------------
  36.  KBD& = _KEYHIT
  37.  SELECT CASE KBD&
  38.   CASE 27 'ESC key
  39.    ExitFlag%% = -1
  40.   CASE 18432 'Up Arrow
  41.    Limit%% = Limit%% + 1
  42.    IF Limit%% = 121 THEN Limit%% = 120
  43.   CASE 20480 'Down Arrow
  44.    Limit%% = Limit%% - 1
  45.    IF Limit%% = 11 THEN Limit%% = 12
  46.   CASE ELSE 'tricky little sod ain't he?
  47.    IF KBD& > 0 THEN
  48.     IF KBD& < 32736 THEN SOUND 32 + KBD&, 1 ELSE BEEP
  49.    END IF
  50.  '-------------------------------------
  51. LOOP UNTIL ExitFlag%% 'they just want it to be over!
  52. '----------------------------------------------
  53. 'All Done, Have a Nice Day
Granted after becoming radioactive I only have a half-life!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Faux 3d Rotation!
« Reply #1 on: November 26, 2020, 07:00:02 pm »
Because midgets are cool, I shortened your code to under 30 lines.
Also, the brown color is absolutely essential.
Code: QB64: [Select]
  1. ' faux 3D by Cobalt, modified by a Fuzzy Squirrel
  2.  
  3. Limit = 24
  4. COLOR 6, 0 '                                        brown to fool cat
  5.  
  6. DO: _LIMIT Limit
  7.     CLS
  8.     PRINT "ESC to Quit": PRINT "Up - Faster": PRINT "Down - Slower"
  9.     FOR n = 0 TO 75
  10.         PSET (150 + n + n, 200)
  11.         DRAW "TA" + STR$(c)
  12.         FOR i = 1 TO 8
  13.             DRAW MID$("FGLHUERD", i, 1) + STR$(n)
  14.         NEXT i
  15.     NEXT
  16.     IF Limit = 120 THEN LOCATE 2, 16: PRINT "Max Speed"
  17.     IF Limit = 12 THEN LOCATE 3, 16: PRINT "Min Speed"
  18.     _DISPLAY
  19.     c = (c + 1) MOD 360
  20.     KBD& = _KEYHIT
  21.     SELECT CASE KBD&
  22.         CASE 27: END
  23.         CASE 18432: Limit = Limit + 1 + (Limit = 120)
  24.         CASE 20480: Limit = Limit - 1 - (Limit = 12)
  25.         CASE ELSE
  26.             IF KBD& > 0 THEN
  27.                 IF KBD& < 32736 THEN SOUND 32 + KBD&, 1 ELSE BEEP
  28.             END IF
  29.     END SELECT
« Last Edit: November 26, 2020, 07:02:12 pm by Richard Frost »
It works better if you plug it in.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Faux 3d Rotation!
« Reply #2 on: November 26, 2020, 07:57:08 pm »
Code: [Select]
         CASE 18432: Limit = Limit + 1 + (Limit = 120)
        CASE 20480: Limit = Limit - 1 - (Limit = 12)

I like this code.  I'm going to shamelessly steal this logic for my own programs from now on.  👍
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Faux 3d Rotation!
« Reply #3 on: November 26, 2020, 08:28:40 pm »
You weren't already doing that method of bounds checking/correcting?  I was doing it for brevity
even before I learned of branchless coding, which helps modern CPUs go faster.

Someday I'll need to look at the keyboard in a time critical section of code, and will use _KEYHIT. 
We dinosaurs use INKEY$, which is slow, but a mite friendlier (no arcane keycode values).
It works better if you plug it in.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Faux 3d Rotation!
« Reply #4 on: November 26, 2020, 09:29:02 pm »
You weren't already doing that method of bounds checking/correcting?  I was doing it for brevity
even before I learned of branchless coding, which helps modern CPUs go faster.

Someday I'll need to look at the keyboard in a time critical section of code, and will use _KEYHIT. 
We dinosaurs use INKEY$, which is slow, but a mite friendlier (no arcane keycode values).

INKEY$ uses the exact same codes as _KEYHIT.  The only difference is one is ASC and the other is CHR$.

INKEY$ "A" = _KEYHIT 65.
ASC("A") = 65
"A" = CHR$(65)

Even arrow keys and such map out equally.  In INKEY$, up is CHR$(0) + "I"  (if my memory is correct.)  Convert that string value to an integer, and it'll perfectly match _KEYHIT's value.

It won't be hard for an old dinosaur to swap over, if they ever decide they want to.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Faux 3d Rotation!
« Reply #5 on: January 24, 2021, 10:55:48 am »
Quote
vidmate arrays and List<T>

There's something I don't hear about every day. :-))

Internet says vidmate is APK is Android video streaming array?, List<t> C# and other, just a list strongly typed and ordered were some adjs for the structure.

Ha, ha! doesn't sound very Basic to me.


Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Faux 3d Rotation!
« Reply #6 on: January 24, 2021, 12:15:04 pm »
Awesome guys! I was wondering if this was possible with DRAW, I should have tested it. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Faux 3d Rotation!
« Reply #7 on: January 24, 2021, 12:27:00 pm »
Awesome guys! I was wondering if this was possible with DRAW, I should have tested it. :)

?? Originally done with DRAW  ;-))

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Faux 3d Rotation!
« Reply #8 on: January 24, 2021, 03:41:07 pm »
B+, I think you misunderstood me. I meant I thought of the same thing around a week ago, to use DRAW to make a 3D looking rotation. But I never experimented with it. Am glad they did.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Faux 3d Rotation!
« Reply #9 on: January 24, 2021, 06:43:57 pm »
Looks like someone ran over, knocked down, and dented a once perfectly good line drawn hexagonic road cone then left it rolling around on the pavement.

Other than that, all I can say is yippie kai yay...

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/