Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
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)
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
11-03-2024, 12:53 AM
(This post was last modified: 11-03-2024, 12:59 AM by bplus.)
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
b = b + ...
Posts: 34
Threads: 6
Joined: Apr 2024
Reputation:
5
(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
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
(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!
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
11-03-2024, 01:02 AM
(This post was last modified: 11-03-2024, 01:04 AM by bplus.)
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.
b = b + ...
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
(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.
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
11-03-2024, 01:08 AM
(This post was last modified: 11-03-2024, 01:09 AM by bplus.)
You will have to DIM Shared V and H in main because they are not passed as arguments to the sub.
b = b + ...
Posts: 3,973
Threads: 177
Joined: Apr 2022
Reputation:
219
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
b = b + ...
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
11-03-2024, 01:32 AM
(This post was last modified: 11-03-2024, 01:35 AM by PhilOfPerth.)
(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!
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
(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.
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.
|