Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
How do I (or can I) nominate a colour for the string in this code?
Code: (Select All) WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")
PSet (500, 200): Draw "r100d100l100u100"
Sleep
I've tried adding C3 etc to the front, which is accepted but ignored, and C_rgb(...) which errors out.
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
You're in 32-bit screen mode; you have to use 32-bit color values as below:
Code: (Select All)
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")
Print &HFFFF0000& 'Red
Print &HFF00FF00& 'Green
Print &HFF0000FF& 'blue
PSet (500, 200): Draw "r100 c-65536 d100 c-16711936 l100 c-16776961 u100"
Sleep
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
Ah, got it!
You nailed it again. Thanks Steve!
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
I get how to place the colours in the string, but what I don't get is how the hex codes are interpreted. Which "digits" set which colour?
&HFFFF0000& 'Red
Seemed pretty obvious at first- full slab of red, and nothing else (but where are the third group of colour digits?)
&HFF00FF00& 'Green
Here I get even more confused: 255 portions of red, and ... ???
&HFF000000& 'blue
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
AARRGGBB, in hex.
Alpha Red Green Blue.
2 hex values represented for 0 to 255 in each.
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
04-04-2024, 09:19 AM
(This post was last modified: 04-04-2024, 09:24 AM by PhilOfPerth.)
Completely forgot about Alpha!
And I messed up your codes, sorry
Ok, try again!
Posts: 2,171
Threads: 222
Joined: Apr 2022
Reputation:
103
Did someone say DRAW, varmints!
Code: (Select All)
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")
Dim As _Unsigned Long red, green, blue
red = _RGB(102, 0, 0, 255)
green = _RGB(0, 102, 0, 255)
blue = _RGB(0, 0, 102, 255)
Print "r100 c" + Str$(red) + " d100 c" + Str$(green) + " l100 c" + Str$(blue) + " u100"
PSet (500, 200): Draw "r100 c" + Str$(red) + " d100 c" + Str$(green) + " l100 c" + Str$(blue) + " u100"
Sleep
Errr better still...
Code: (Select All)
$Color:32
WWidth = 1120: WHeight = 820: Mode = 32: Size = 24
Screen _NewImage(WWidth, WHeight, Mode)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", Size, "monospace"): _Font f&
lhs = (_DesktopWidth - WWidth) / 2
_ScreenMove lhs, 86 ' centre display on screen
CPL = WWidth / _PrintWidth("X")
Print "r100 c" + Str$(Red) + " d100 c" + Str$(Green) + " l100 c" + Str$(Blue) + " u100"
PSet (500, 200): Draw "r100 c" + Str$(Red) + " d100 c" + Str$(Green) + " l100 c" + Str$(Blue) + " u100"
Sleep
Pete
Posts: 1,272
Threads: 119
Joined: Apr 2022
Reputation:
100
(04-04-2024, 09:19 AM)PhilOfPerth Wrote: Completely forgot about Alpha!
And I messed up your codes, sorry
Ok, try again!
The first sections in lesson 14 of the tutorial explains how the color codes work if you would like a refresher.
https://www.qb64tutorial.com/lesson14
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 382
Threads: 56
Joined: Apr 2022
Reputation:
13
Terry - I do find your tutorials very very helpful and your suggestion here to Phil sure does help me understand better exactly what the problem is that Phil is running into and the potential solution. The little annoying thing that I'm running into however is leaving my coding and accessing the digital version of reference material,(in which I place your tutorial) or doing a search on this forum for more insight. I'd much prefer (likely I'd be in the minority here) to have a hard copy manual/binder of reference material beside me to lookup stuff while I'm starring at my code.
Wouldn't it be nice if you and Steve could get together a produce a hard copy of your tutorial and Steve's (almost completed) bible. Place that as one of the items we can buy on this forum site along with the coffee mugs. Just saying.
Posts: 2,171
Threads: 222
Joined: Apr 2022
Reputation:
103
Hell, you could place everything Steve knows about QB64 on the COFFEE MUG and still have room for a full size image of Yosemite Sam on the back! (He's really that short!) J/K
Steve's response: Pete is absolutely right, you'd just have to print it in a .0001 pixel font.
Pete
Shoot first and shoot people who ask questions, later.
|