QB64 Phoenix Edition
Sending Color to Specific Location - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Works in Progress (https://qb64phoenix.com/forum/forumdisplay.php?fid=9)
+---- Thread: Sending Color to Specific Location (/showthread.php?tid=1287)



Sending Color to Specific Location - Dimster - 12-16-2022

I was just wondering if there is way to change the color of a value which is displaying on a screen. For example, something like this


Screen _NewImage(1900, 900, 32)
$Color:32

A$ = "5"
Color White
_PrintString (100, 100), A$
Color Green
_printstring (100,100), color green



So the value 5 is displaying on the screen in white however, later on in the program I want that value to pop out if certain conditions apply. Present coding requires a complete repeat of the value plus the new color but if I just want to change the color only at that same location doesn't appear color only can be changed? or might there be a way???


RE: Sending Color to Specific Location - SMcNeill - 12-16-2022

Something simple like this?

Code: (Select All)
Screen _NewImage(640, 480, 32)
$Color:32
Color White
_PrintString (100, 100), "Hello World"

For i = 0 To 10 Step 2
    ChangeColor 100 + i * _FontWidth, 100, 1, White, Red
Next


Sub ChangeColor (WhereX, WhereY, HowManyCharacters, OriginalColor As _Unsigned Long, NewColor As _Unsigned Long)
    Static m As _MEM
    Dim o As _Offset
    m = _MemImage(0)
    x1 = WhereX
    y1 = WhereY
    x2 = x1 + HowManyCharacters * _FontWidth
    y2 = y1 + HowManyCharacters * _FontHeight
    $Checking:Off
    For y = y1 * _Width * 4 To y2 * _Width * 4 Step _Width
        For x = x1 * 4 To x2 * 4 Step 4
            o = m.OFFSET + y + x
            If _MemGet(m, o, _Unsigned Long) = OriginalColor Then _MemPut m, o, NewColor
        Next
    Next
    $Checking:On
End Sub



RE: Sending Color to Specific Location - mnrvovrfc - 12-16-2022

That's in the spirit of the holiday season!

I was going to change it so it drew a candy cane of text and changed from white to red and green.

I was going to propose "POINT()" but that's unreliable. This program should be studied carefully by beginners before they have anything to do with the "_MEM" functions.


RE: Sending Color to Specific Location - Dimster - 12-16-2022

Thank you


RE: Sending Color to Specific Location - Pete - 12-16-2022

Stay in SCREEN 0 from now on. It has PALETTE, which makes doing these types of color alterations much more... PALETTEable.

Pete


RE: Sending Color to Specific Location - SMcNeill - 12-16-2022

(12-16-2022, 04:44 PM)mnrvovrfc Wrote: That's in the spirit of the holiday season!

I was going to change it so it drew a candy cane of text and changed from white to red and green.

I was going to propose "POINT()" but that's unreliable. This program should be studied carefully by beginners before they have anything to do with the "_MEM" functions.

Here's the main thing people need to learn to do with _MEM:

Code: (Select All)
    For y = y1 * _Width * 4 To y2 * _Width * 4 Step _Width
        For x = x1 * 4 To x2 * 4 Step 4

Take the math OUT of the processing loop!!  Most of the time, you see people with something such as:

FOR y = y1 TO y2
    FOR x = x1 TO x2
        IF _MEMGET(m, m.offset + y * 4 * _WIDTH + x * 4, _UNSIGNED LONG) = OldColor THEN _MEMPUT m, m.offst + 4 * _WIDTH + x * 4, NewColor

...

And that's a LOT of math to process inside that loop, which ends up making the mem routines get to the point where they're barely better than POINT and PSET with a plain x/y value. 

If you notice, my whole math formula is a simple: o = m.OFFSET + y + x

That's a LOT less calculations than my previous example up there -- and it's going to be done over and over and over inside that loop!  Wink


RE: Sending Color to Specific Location - SMcNeill - 12-16-2022

(12-16-2022, 05:12 PM)Pete Wrote: Stay in SCREEN 0 from now on. It has PALETTE, which makes doing these types of color alterations much more... PALETTEable.

Pete

Problem with that is it changes *ALL* instances of that color on your screen, and not just a select few which you might want to "pop out" to highlight for others, for whatever reason.  Wink


RE: Sending Color to Specific Location - Pete - 12-16-2022

That's why I reserve certain ugly ASCII colors like 5 for this purpose.

Code: (Select All)
PALETTE 5, 63
COLOR 15
PRINT "Hello ";
COLOR 5
PRINT "World!"
SLEEP
PALETTE 5, 62
END

Pete

I'm not only a genius on the Internet, I also play one in real life!