Author Topic: background color shenanigans  (Read 2214 times)

0 Members and 1 Guest are viewing this topic.

Offline thelowerrhythm

  • Newbie
  • Posts: 10
    • View Profile
background color shenanigans
« on: August 27, 2018, 12:45:35 am »
I've been playing around with a simple program that randomly prints user generated strings of text with foreground and background colors that can be both randomly generated and user generated. Thanks to a handful of personal heroes the other day (yesterday even? it all blurs together) I've now worked out most of the bugs.

Something I found a fix for that I'd like to understand more about is this, though: These text strings print line by line as you can see in the attached image, and all is well until the last line on the screen. For some reason whenever that happens, suddenly the background color is bled out beyond the string of text, all the way to the end of the screen, and then one or so spaces down on the next line. In QB64 the resolution raises (annoyingly) when the printed text tries to move beyond the screen and it stops doing it after one or two lines.

On my 486, in Qbasic, every new line bleeds the background color like that.

The fix was to add a COLOR 0, 0 after the PRINT statement for the random string, so that's, cool. But yeah. Anyone know why it does that suddenly when the screen scrolls?

Also, is there any way to stop the resolution from changing in QB64 when my printed lines pass the bottom? I'd like it to just scroll rather than zoom out, like it does in Qbasic. It's just a couple of dumb little programs I'm working on to aid in my art practice (I'm a studio practice grad student), but I was hoping to have them behave similarly on the older and newer machines if possible. The resolution funny-business is actually kind of a big deal, as I rely on the visual output and need to keep it clear.

Thanks again!

Offline thelowerrhythm

  • Newbie
  • Posts: 10
    • View Profile
Re: background color shenanigans
« Reply #1 on: August 27, 2018, 12:50:40 am »
I take back what I said... that COLOR statement wasn't a fix. Just had a few fluke runs where the BG color was set to black as it scrolled. /facepalm

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: background color shenanigans
« Reply #2 on: August 27, 2018, 09:45:32 am »
You can create a scrolling screen effect by maintaining a virtual screen array and keeping track, say the top left corner of area to display, where that is in the array, such that you are displaying on screen a little window of the giant array. It would be like making a picture editor.
« Last Edit: August 27, 2018, 09:51:06 am by bplus »

FellippeHeitor

  • Guest
Re: background color shenanigans
« Reply #3 on: August 27, 2018, 10:24:07 am »
If you try to use LOCATE to print to a coordinate beyond the current total lines available, QB64 will automatically adjust the window height in order to avoid throwing an error. If you want to have the screen scroll its contents up, use just PRINT sequentially, without LOCATE.

If a background color exists it will definitely paint the last line from start to end in order to imitate the behavior of Qbasic/QuickBASIC 4.5. To avoid that you can use a semicolon after your print statement - although that is used exactly to avoid your first goal that is to scroll the contents up when reaching the last line.

A workaround would be printing with a semicolon, changing the color, then printing without a semicolon to trigger the scroll:

Code: QB64: [Select]
  1.     i = i + 1
  2.     COLOR _CEIL(RND * 15), _CEIL(RND * 8)
  3.     PRINT i; 'the semicolon prevents scrolling
  4.     COLOR , 0 'restore black background
  5.     PRINT 'without the semicolon the screen scrolls up
  6.     '      when the last line is reached
  7.     _LIMIT 5
  8.  
« Last Edit: August 27, 2018, 10:28:59 am by FellippeHeitor »

Offline thelowerrhythm

  • Newbie
  • Posts: 10
    • View Profile
Re: background color shenanigans
« Reply #4 on: August 27, 2018, 01:51:30 pm »
Thanks everyone. I think I've learned more from this forum in a week than a few months reading BASIC books back in the day. Knowing why it is doing what it is doing really helps.

I solved the scrolling issue this morning using the WIDTH command. Set it to 80, 25, which I think is the original default for Screen 0. That seems to maintain it. The semi-colon thing works in its own right... I still want to be able to get it to go vertically, but this is an interesting way of printing the information as well.

I'll work on implementing that last suggestion sometime today or tomorrow! :D

Offline thelowerrhythm

  • Newbie
  • Posts: 10
    • View Profile
Re: background color shenanigans
« Reply #5 on: August 27, 2018, 02:01:52 pm »
Actually it worked nearly immediately, so that's cool. I bow before your wisdom. A simple thing, but I'll take it a long way.