PDA

View Full Version : colors and console_printat



sandyrepope
22-02-2007, 03:56
I've been experimenting with console_printat to see what I can do with color. So far, I haven't had much luck. Here is what I'm trying work with.


uses "Console"
dim txt_red as long
dim bkgn as long

bkgn = console_settextattribute (%console_background_green)
console_cls

txt_red = Console_SetTextAttribute (%Console_foreGROUND_RED)

console_printat("This is a test " , 0 , 0 , txt_red )

console_waitkey



there Just doesn't seem to be any way to print red text on a green background.

Maybe there's something wrong with my code! Can someone look at it and let me know?

Thanks
Sandy

Michael Hartlef
22-02-2007, 06:55
Change the colors within one command:


uses "Console"
dim txt_red as long


txt_red = Console_SetTextAttribute (%Console_foreGROUND_RED+%console_background_green)
console_cls

console_printat("This is a test " , 0 , 0 , txt_red )

console_waitkey

ErosOlmi
22-02-2007, 08:26
Sandy,

have you checked the console color output souce code example? It shows all the colors you can use and how they are combined.
In general CONSOLE_PRINTAT does it all: position cursor, print text at the desired color.

Anyhow, here a simplified example taken from source code examples. Hope it will be more clear:

uses "Console"

'-------------------------------------------------------------------------
'Initial SetUp
'-------------------------------------------------------------------------
'---Prepare the sceen
Console_SetScreenBufferSize(80, 30)
Console_ShowWindow(%Console_SW_SHOWMAXIMIZED)

'---A box around. Not needed but some candy are always nice
CONSOLE_box(1, 1, 50, 22, 24, 17, "[Color sample]", 15 ,%Console_BOX_FLAG_3DON)

'---Define needed variables
DIM X AS LONG
DIM Y AS LONG
DIM OutColor AS LONG
DIM Head AS STRING

'---Loops for all possible colors backgound and foreground
FOR Y = 0 TO 15
FOR X = 0 TO 15
'---Write header if we are at first line
IF Y = 0 THEN
Head = format$(x, "00")
'---Write heade number in vertical direction
Console_Printat(LEFT$ (Head, 1), 10 + x * 2, 3, 15)
Console_Printat(RIGHT$(Head, 1), 10 + x * 2, 4, 15)
END IF

'---Write left heading
Console_Printat(FORMAT$(y * 16, "000"), 5, 6 + y, 15)

'---Write char with next color
'---Color is composed multiply current line by 16 plus current X.
'---So it will be a number from 0 (0 * 16 + 0) to 255 (15 * 16 + 15)
OutColor = Y * 16 + x
Console_Printat("O", 10 + x * 2, 6 + y, OutColor)

NEXT
NEXT

Console_Printat("Press any key to exit", 1, 25, 7)
console_waitkey

Console_Cls

sandyrepope
22-02-2007, 17:35
Thank you for the two posts. I think they will clear up some things I wasn't getting.

Yes, I did check out the example you pointed out. I really had a hard time trying to understand what it was doing. I've found that some of the examples are just too complex for a beginner to understand right away. I plan to keep trying until I get better.

Thanks
Sandy

ErosOlmi
22-02-2007, 17:59
Sandy,

as for all other programming languages, remember this is only the way thinBasic does it.
Other languages can do the same things but in a very different way.
Many times is just a matter of feeling and programming styles.

Ciao
Eros