Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using color in Draw string
#1
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.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#2
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
Reply
#3
Ah, got it!
You nailed it again. Thanks Steve!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#4
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   Huh
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#5
AARRGGBB, in hex.

Alpha Red Green Blue.

2 hex values represented for 0 to 255 in each.
Reply
#6
Completely forgot about Alpha!
And I messed up your codes, sorry
Ok, try again!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#7
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
Reply
#8
(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
Reply
#9
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.
Reply
#10
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 Big Grin
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 3 Guest(s)