Author Topic: QB64 REPORT S01E02: "SCREEN modes"  (Read 8793 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
QB64 REPORT S01E02: "SCREEN modes"
« on: June 15, 2020, 08:31:47 pm »
Here's the second episode of QB64 Report, our podcast on all things QB64. In this episode, "SCREEN modes".

Catch it on all major podcast providers or listen straight from https://www.buzzsprout.com/1147208/4174160
« Last Edit: June 15, 2020, 08:41:36 pm by FellippeHeitor »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #1 on: June 15, 2020, 11:11:41 pm »
Ah so Alt+ something gets us 4 different screen modes without a single line of additional code.

That's pretty good tip, thanks!

FellippeHeitor

  • Guest
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #2 on: June 15, 2020, 11:15:49 pm »
That's alt+enter. The behavior of the key combo can also be customized (and even disabled) with:

Code: QB64: [Select]

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #3 on: June 15, 2020, 11:40:44 pm »
Thanks again

Like the idea of layering when I was thinking how difficult to update screen over and over again for mouse over on buttons, it's on redo whole screen, no it's off, redo whole screen... yikes! But draw an overlapping layer, and you only have to make the image once! Layer on, layer off, layer on, layer off... that should work well!
« Last Edit: June 16, 2020, 07:15:22 pm by bplus »

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #4 on: June 16, 2020, 01:31:04 am »
Squirrels for sale, fried on sticks. - @Richard Frost
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #5 on: June 16, 2020, 05:14:33 pm »
Another great episode!  Ya'll sure do a podcast good together.  Everyone puts in their valuable input, and nobody gets in the way of each other.  It's to the point stuff, and you keep it interesting too.  The episode flows good.  Maybe add some intro + outro music!

- Dav
« Last Edit: June 16, 2020, 07:26:46 pm by Dav »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #6 on: June 16, 2020, 11:39:26 pm »
There is the WINDOW statement, QB original, that fixes the coordinate system to whatever you want but no one ever uses it and rightfully so, it's too confusing, but why not?

Code: QB64: [Select]
  1.  
  2. window (-_pi,1)-(_pi,-1)
  3.  
  4. pset (-_pi,0)
  5.  
  6. for x= -_pi to _pi step 0.1
  7.  
  8. 'wow is this mathematica?
  9.  
  10.         y = sin (x)
  11.  
  12.         line -(x, y)
  13.  
  14.  
  15.  
« Last Edit: June 17, 2020, 09:08:53 am by _vince »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #7 on: June 17, 2020, 12:54:20 am »
There is the WINDOW statement, QB original, that fixes the coordinate system to whatever you want but no one ever uses it and rightfully so, it's too confusing, but why not?

Code: QB64: [Select]
  1.  
  2. window screen (-_pi,-1)-(_pi,1)
  3.  
  4. pset (-_pi,0)
  5.  
  6. for x= -_pi to _pi step 0.1
  7.  
  8. 'wow is this mathematica?
  9.  
  10.         y = sin (x)
  11.  
  12.         line -(x, y)
  13.  
  14.  
  15.  

Hey _vince I was showing STx this, since he is always wanting a central origin and y-axis pointed up. Be careful with graphics commands they don't all work and there is a special command to get correct mouse location, probably can find it in Wiki under Window or related keywords.

Maybe I can dig up the demo I made.
Code: QB64: [Select]
  1. _TITLE "Test Using Window for Cartesian Coordinate System x = -100 to 100, y = -100 to 100"
  2. 'It seems all graphics commands convert x, y to window system BUT...
  3. 'Mouse and _PrintString do not convert! BUT...
  4. 'Somebody setup a PMAP system that will do these conversions both to grapghics coordinate system and back
  5. ' convert mouse qbx, qby to graphics x, y use
  6. ' PMAP(qbx, 2), PMAP(qby, 3)
  7. ' And to print something at the graphics location use
  8. ' PMAP(graphicsX, 0), PMAP(graphicsY, 1) to _PRINTSTRING to a graphics location
  9.  
  10. CONST xmax = 700, ymax = 700, red = &HFFFF0000, grn = &HFF009900, blu = &HFF0000AA
  11. CONST tlx = -100, tly = 100, brx = 100, bry = -100 ' Cartesian Coordinate System corners for WINDOW command
  12. SCREEN _NEWIMAGE(xmax, ymax, 32)
  13. _SCREENMOVE 300, 40
  14.  
  15. DIM mx, my, a, r, s$
  16.  
  17. WINDOW (tlx, tly)-(brx, bry) ' converts QB csreen to Cartesian Coodianate System
  18. WHILE _KEYDOWN(27) = 0
  19.     CLS
  20.     mx = INT(PMAP(_MOUSEX, 2)): my = INT(PMAP(_MOUSEY, 3)) 'covert mouse to Cart Cood using PMAP
  21.     a = atan360(my, mx) 'mouse angle to origin
  22.     r = INT((mx * mx + my * my) ^ .5)
  23.     LINE (0, 0)-(mx, my), grn 'hypotenuse = radius
  24.     LINE (0, 0)-(mx, 0), blu ' r*cos
  25.     LINE (mx, 0)-(mx, my), red ' r*sin
  26.     arc 0, 0, 10, 0, _R2D(a), &HFFFFFF00 'yellow arc
  27.     s$ = "Mouse (" + _TRIM$(STR$(mx)) + ", " + _TRIM$(STR$(my)) + "), Radius: "
  28.     s$ = s$ + _TRIM$(STR$(r)) + ", Degrees: " + _TRIM$(STR$(_R2D(a) \ 1))
  29.     _PRINTSTRING (PMAP(0, 0), PMAP(-1, 1)), s$
  30.     _PRINTSTRING (PMAP(-95, 0), PMAP(95, 1)), "COS = x/r = " + _TRIM$(STR$(mx / r))
  31.     _PRINTSTRING (PMAP(-95, 0), PMAP(89, 1)), "SIN = y/r = " + _TRIM$(STR$(my / r))
  32.     IF mx <> 0 THEN _PRINTSTRING (PMAP(-95, 0), PMAP(83, 1)), "TAN = y/x = " + _TRIM$(STR$(my / mx)) 'EDIT
  33.     _DISPLAY
  34.     _LIMIT 60
  35.  
  36. ' A regular graphic draw still works correctly in a Cartesian Window System!
  37. 'note: degrees start due East = 0 and go clockwise: South = 90, West = 180, North = 270
  38. SUB arc (x, y, r, degStart, degStop, c~&)
  39.  
  40.     DIM rs, re, a, ax, ay, lastx, lasty
  41.     'x, y origin, r = radius, c = color
  42.  
  43.     'degStart is first angle clockwise from due East = 0 degrees
  44.     ' arc will start drawing there and clockwise until degStop angle reached, unless in Cartesain Window
  45.  
  46.     IF degStop < degStart THEN
  47.         arc x, y, r, degStart, 360, c~&
  48.         arc x, y, r, 0, degStop, c~&
  49.     ELSE
  50.         rs = _D2R(degStart): re = _D2R(degStop)
  51.         FOR a = rs TO re STEP 1 / (7 * r)
  52.             ax = x + r * COS(a)
  53.             ay = y + r * SIN(a)
  54.             IF a <> rs THEN LINE (lastx, lasty)-(ax, ay), c~&
  55.             lastx = ax: lasty = ay
  56.         NEXT
  57.     END IF
  58.  
  59. 'need to match degrees going around clockwise up to full circle
  60. FUNCTION atan360 (y, x)
  61.     DIM test
  62.     test = _ATAN2(y, x)
  63.     IF test < 0 THEN atan360 = _PI(2) + test ELSE atan360 = test
  64.  
  65.  

See the PMAP for the mouse?
« Last Edit: June 17, 2020, 12:56:47 am by bplus »

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #8 on: June 17, 2020, 08:43:55 am »
I frequently use the WINDOW statement to redefine the coordinate system. I just prefer not having to flip the mathematics around. I've sometimes wondered if it had any particular effect on execution speeds, but QB64 hasn't let me down in that respect yet.

Example is a quickie graphing routine that I wrote to help me with my math function studies. It redefines the screen for x left to right ascending and y bottom to top ascending. That's how I remember it from school. I just comment in or out what I need to look at.

Code: QB64: [Select]
  1. A& = _NEWIMAGE(650, 650, 32)
  2. _TITLE "Graph"
  3.  
  4. WINDOW (-15, 15)-(15, -15)
  5. g = -16
  6.     g = g + 1
  7.     LINE (-15, g)-(15, g), &H7F7F7F7F '                         horizontal grid lines
  8.     LINE (g, -15)-(g, 15), &H7F7F7F7F '
  9. LOOP UNTIL g = 15
  10. LINE (0, -15)-(0, 15), &HFF0000FF, BF
  11. LINE (-15, 0)-(15, 0), &HFF0000FF, BF
  12. FOR x = -15 TO 15 STEP .01
  13.  
  14.     'FORMULAS
  15.     'y = ABS(x) ^ .5
  16.     'y = ABS(x)
  17.     'y = -1 * (x * x)
  18.     'y = -3 * x ^ 2 + 6 * x + 72
  19.     'y = x ^ 2 + 7 * x + 6
  20.     'y = 4 * x ^ 2 - (12 * x) + 9
  21.     'y = (x + 2) / 6 ^ 2
  22.     'y = 2 * (x * x) + 2
  23.     'y = 2 * x - 4
  24.     'y = (x * x) - 2 * x
  25.     'y = 7 * x ^ 3 - 63 * x
  26.     'y = -.05 * x * x + 6 'parabola
  27.     'y = (.5 * x) ^ 3
  28.     y = SIN(x) 'sine wave
  29.     'y = COS(x)
  30.     'y = TAN(x)
  31.     'y = TAN(x) ^ 2
  32.     'y = _ATAN2(x, 1)
  33.     'y = _CSC(x)
  34.     'y = 3 / (x - 2) + 1
  35.     'y = (x ^ 2 * -_PI) / 6
  36.     'y = -.33333 * (x + 1) ^ 3 - 1
  37.     'y = (x + 2) / (x - 6)
  38.     'y = (x - 6) ^ 2
  39.     'y = 2 * (x * x)
  40.     'y = x / (x * x) - 4
  41.     'y = (x * x) / 2 * (x * x)
  42.     'IF x < 0 THEN
  43.     '    y = 3 * x + 4
  44.     'ELSE
  45.     '    y = -x + 2
  46.     'END IF
  47.  
  48.     'y = (x + 2) ^ 2 - 1
  49.     'y1 = x * x
  50.     'y2 = -(x - 3) ^ 2 + 2
  51.  
  52.     'DISPLAY CODE
  53.     PSET (x, y)
  54.     'PSET (x, y1), &HFFFF0000
  55.     'PSET (x, y2), &HFF00FF00
  56.     'LINE (x, y)-(x, -15), &HFF0000FF
  57.     'LINE (x, y)-(x, 15), &HFF000000
  58.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #9 on: June 17, 2020, 09:16:18 am »
I just noticed that WINDOW SCREEN doesn't seem to allow you to have y go up from bottom to top but WINDOW does.  I corrected my code above accordingly - the sine wave is now the correct phase with the origin being the center of the screen.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #10 on: June 17, 2020, 12:50:28 pm »
I just noticed that WINDOW SCREEN doesn't seem to allow you to have y go up from bottom to top but WINDOW does.  I corrected my code above accordingly - the sine wave is now the correct phase with the origin being the center of the screen.

Oops sorry I missed WINDOW SCREEN in your code _vince.

WINDOW does seem to me to maintain consistent and correct trig function for the angle going counter-clockwise as it increases. There is trouble (as I recall) trying to draw arcs with CIRCLE using the start and stop angles which is why I use a separate arc routine that works fine without any change to the trig functions, eg using - sign with SIN. The demo is supposed to demo that, the trig math remains consistently correct, using the WINDOW command that sends increasing radian angles counter-clockwise which is all the math enthusiasts want ie for the graphics to remain consistent with their schooling.

This is why I showed it to STx as he is jumping through hoops to correct BASIC graphic direction of y increasing as you go down the screen. WINDOW does it with some caveats I mentioned (probably more). Well STx confuses the issue with 3D before getting the WINDOW under his belt, of course I don't know ship about GL which might be goofed 3D wise when coding 3D WITH _GL commands, I don't know, but STx does not use that either I am pretty sure.

Oh I notice another discovery I made, use PMAP to correct mouse locations in WINDOW and also _PRINTSCREEN locations are fixed with PMAP :) Ha! but it is a challenge to think in text locations with a Cartesian Coordinate System.

I suppose more WINDOW examples and practice would help clear things up.
« Last Edit: June 17, 2020, 12:56:41 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #11 on: June 17, 2020, 01:10:00 pm »
The behavior of the y coordinate is still backwards by default. Whether you use WINDOW or custom LINE and PSET is a matter of taste.

And what's this shit about me being confused about 3D? Spell that out for me, cause these sounds like the ramblings of someone who learned trig upside down...

Window is cute but redundant, and so are you bplus :) just kidding
« Last Edit: June 17, 2020, 01:14:33 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #12 on: June 17, 2020, 02:41:24 pm »
The behavior of the y coordinate is still backwards by default. Whether you use WINDOW or custom LINE and PSET is a matter of taste.

And what's this shit about me being confused about 3D? Spell that out for me, cause these sounds like the ramblings of someone who learned trig upside down...

Window is cute but redundant, and so are you bplus :) just kidding


Quote
The behavior of the y coordinate is still backwards by default. Whether you use WINDOW or custom LINE and PSET is a matter of taste.

Nope! add something to a y coordinate and it goes up the screen not down with proper WINDOW setup.

Code: QB64: [Select]
  1.  
  2. _TITLE "Test Using Window for Cartesian Coordinate System x = -100 to 100, y = -100 to 100"
  3. 'It seems all graphics commands convert x, y to window system BUT...
  4. 'Mouse and _PrintString do not convert! BUT...
  5. 'Somebody setup a PMAP system that will do these conversions both to grapghics coordinate system and back
  6. ' convert mouse qbx, qby to graphics x, y use
  7. ' PMAP(qbx, 2), PMAP(qby, 3)
  8. ' And to print something at the graphics location use
  9. ' PMAP(graphicsX, 0), PMAP(graphicsY, 1) to _PRINTSTRING to a graphics location
  10.  
  11. CONST xmax = 700, ymax = 700, red = &HFFFF0000, grn = &HFF009900, blu = &HFF0000AA
  12. CONST tlx = -100, tly = 100, brx = 100, bry = -100 ' Cartesian Coordinate System corners for WINDOW command
  13. SCREEN _NEWIMAGE(xmax, ymax, 32)
  14. _SCREENMOVE 300, 40
  15.  
  16. DIM mx, my, a, r, s$
  17.  
  18. WINDOW (tlx, tly)-(brx, bry) ' converts QB csreen to Cartesian Coodianate System
  19.  
  20. x = -100: y = -100
  21. PRINT "From bottom left to top right increasing x and y by 1"
  22. FOR i = 1 TO 201
  23.     x = x + 1
  24.     y = y + 1
  25.     PSET (x, y)
  26.     _LIMIT 10
  27.  
  28.  
  29.  

and if you don't get this there is no point in arguing and name calling.

And I am saying you, STx, confuse the issue when bringing 3D into the discussion about y going up or down.
ie How the right hand rule is there or not depends on how you set up the z axis with or without WINDOW.

If _GL commands for 3D preserve right hand rule is beyond my scope of experience to comment.
« Last Edit: June 17, 2020, 03:06:12 pm by bplus »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #13 on: June 17, 2020, 03:59:53 pm »
You are respondng to the wrong concern bplus, did you notice the lack of resistance whilst making your windmill slam dunks against no opponent?

If you think the WINDOW statement occurs in a program by default, as I was saying it does not, then I think you don't have qb64 v 1.4 installed. When I go to file new, the default behavior is as if window is not called. I just got a blank blue screen with a backwards y direction.

Or is window just jumping through hoops? Anyway it's a redundant statement if you've solved this another way and who cares. And wth are you saying about me and 3d again? I missed it twice. People might actually believe you, which is why I need to call you out each time you mention it.
You're not done when it works, you're done when it's right.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: QB64 REPORT S01E02: "SCREEN modes"
« Reply #14 on: June 17, 2020, 04:05:53 pm »
Oh wait I get what you're saying

No, the right hand rule has a 3d implication even when all coordinates are in 2d strictly, it does not confuse the issue to need the right hand rule to be correct in a strictly 2d system. I see what you want to mean though, honest.

« Last Edit: June 17, 2020, 04:07:20 pm by STxAxTIC »
You're not done when it works, you're done when it's right.