QB64 Phoenix Edition
Setting Line _RGB colours - 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: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Setting Line _RGB colours (/showthread.php?tid=3192)

Pages: 1 2


Setting Line _RGB colours - PhilOfPerth - 11-03-2024

How can I convert this line:

Line (H, V)-(H+ 37, V+ 38), _RGB(200, 200, 200), BF

to set the _RGB colour to a colour in a sub, instead of this fixed colour?  (I'm using a _NewImage 32-bit screen)
Sub Red might contain Color: _RGB(255,0,0)


RE: Setting Line _RGB colours - bplus - 11-03-2024

Code: (Select All)
Sub myBox (H, V, K As _Unsigned Long)
    Line (H, V)-(H + 37, V + 38), K, BF
End Sub

demo
Code: (Select All)
Screen _NewImage(800, 600, 32)
For y = 0 To 600 Step 38
    For x = 0 To 800 Step 37
        myBox x, y, _RGB32(Rnd * 255, Rnd * 255, Rnd * 255)
Next x, y

Sub myBox (H, V, K As _Unsigned Long)
    Line (H, V)-(H + 37, V + 38), K, BF
End Sub



RE: Setting Line _RGB colours - ahenry3068 - 11-03-2024

(11-03-2024, 12:46 AM)PhilOfPerth Wrote: How can I convert this line:
Line (H, V)-(H+ 37, V+ 38), _RGB(200, 200, 200), BF
to set the _RGB colour to a colour in a sub, instead of this fixed colour?  (I'm using a _NewImage 32-bit screen)
Sub Red might contain Color: _RGB(255,0,0)

   The _RGB(r,g,b) function returns a long.    You can pass that in as a parameter to the function


SUB Myline(MyColor&)

    Line (H, V)-(H+ 37, V+ 38), MyColor&, BF

END SUB


RE: Setting Line _RGB colours - PhilOfPerth - 11-03-2024

(11-03-2024, 12:53 AM)bplus Wrote:
Code: (Select All)
Sub myBox (H, V, K As _Unsigned Long)
    Line (H, V)-(H + 37, V + 38), K, BF
End Sub
Thanks bplus; I knew you'd come through!  Big Grin


RE: Setting Line _RGB colours - bplus - 11-03-2024

Henry is right for _RGB() you may only need long because you don't have transparent colors.

_Unsigned Long covers all color bases _RGB() and _RGB32(). I recommend _RGB32() because it is very versatile.


RE: Setting Line _RGB colours - PhilOfPerth - 11-03-2024

(11-03-2024, 12:54 AM)ahenry3068 Wrote:
(11-03-2024, 12:46 AM)PhilOfPerth Wrote: How can I convert this line:
Line (H, V)-(H+ 37, V+ 38), _RGB(200, 200, 200), BF
to set the _RGB colour to a colour in a sub, instead of this fixed colour?  (I'm using a _NewImage 32-bit screen)
Sub Red might contain Color: _RGB(255,0,0)

   The _RGB(r,g,b) function returns a long.    You can pass that in as a parameter to the function


SUB Myline(MyColor&)

    Line (H, V)-(H+ 37, V+ 38), MyColor&, BF

END SUB

Thank you. That looks pretty straightforward. I'll try that.


RE: Setting Line _RGB colours - bplus - 11-03-2024

You will have to DIM Shared V and H in main because they are not passed as arguments to the sub.


RE: Setting Line _RGB colours - bplus - 11-03-2024

Demo 2:
Code: (Select All)
Screen _NewImage(800, 600, 32)
For y = 0 To 600 Step 38
    For x = 0 To 800 Step 37
        myBox x, y, _RGB32(x * 255 / 800, Abs(x - y) * 255 / 800, y * 255 / 800)
        Line (x, y)-(x + 37, y + 38), &HFFFFFFFF, B
Next x, y
Sleep
Sub myBox (H, V, K As _Unsigned Long)
    Line (H, V)-(H + 37, V + 38), K, BF
End Sub



RE: Setting Line _RGB colours - PhilOfPerth - 11-03-2024

(11-03-2024, 01:08 AM)bplus Wrote: You will have to DIM Shared V and H in main because they are not passed as arguments to the sub.

Yes, got that; thanks.

(11-03-2024, 01:29 AM)bplus Wrote: Demo 2:
Code: (Select All)
Screen _NewImage(800, 600, 32)
For y = 0 To 600 Step 38
    For x = 0 To 800 Step 37
        myBox x, y, _RGB32(x * 255 / 800, Abs(x - y) * 255 / 800, y * 255 / 800)
        Line (x, y)-(x + 37, y + 38), &HFFFFFFFF, B
Next x, y
Sleep
Sub myBox (H, V, K As _Unsigned Long)
    Line (H, V)-(H + 37, V + 38), K, BF
End Sub

You never cease to amaze me!  Big Grin


RE: Setting Line _RGB colours - SMcNeill - 11-03-2024

(11-03-2024, 01:02 AM)bplus Wrote: Henry is right for _RGB() you may only need long because you don't have transparent colors.

_Unsigned Long covers all color bases _RGB() and _RGB32(). I recommend _RGB32() because it is very versatile.

LONG and _UNSIGNED LONG both cover all your color valules.

That said, you should *ALWAYS* use _UNSIGNED LONG, as several of the QB64 Functions return _UNSIGNED LONG values and your LONG colors won't match them.  Let me give the simplest of demos here:

Code: (Select All)
Screen _NewImage(640, 480, 32)
Dim l As Long, ul As _Unsigned Long

l = _RGB(200, 200, 200)
ul = l

Print "As you can see, the hex values of these numbers are the same,"
Print "but their decimal values are quite different."
Print l, Hex$(l)
Print ul, Hex$(ul)

Line (200, 200)-(300, 300), l, BF
Line (400, 200)-(500, 300), ul, BF
Print
Print "As you can tell from our boxes, the colors are EXACTLY the same."
Print Point(250, 250), Point(450, 250)
Print "But the problem is, POINT returns FLOAT values (to match UNSIGNED LONG)."
Print "So when you try TRUE/FALSE comparisons, you get:"
Print "IF POINT(250,250) = "; l; "THEN.... ";
If Point(250, 250) = l Then Print "TRUE" Else Print "FALSE"
Print "IF POINT(450,250) = "; ul; "THEN.... ";
If Point(450, 250) = ul Then Print "TRUE" Else Print "FALSE"


Now, in your SUB here, it doesn't matter as you're not making use of POINT or other color functions that return an unsigned long value to you. Still, I wouldn't recommend to use a LONG value for colors. *ALWAYS* use an _UNSIGNED LONG. Get in the habit of *always* using an unsigned long. *ALWAYS*, when using 32-bit colors.

Otherwise, it will eventually come to bite you in the butt, and I will end up laughing at you and pointing to the 5217 posts like this one that I've repeated over and over and over, over the years. Big Grin

There's no reason to use LONG values. They save no memory. Don't process any faster. They have no bonus to efficiency or anything else. AND, they can break your code as QB64PE functions return UNSIGNED LONG values back to you, and not LONGs.