Results 1 to 5 of 5

Thread: colors and console_printat

  1. #1

    colors and console_printat

    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.

    [code=thinbasic]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

    [/code]

    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

  2. #2

    Re: colors and console_printat

    Change the colors within one command:

    [code=thinbasic]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

    [/code]

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10

    Re: colors and console_printat

    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:
    [code=thinbasic] 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
    [/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4

    Re: colors and console_printat

    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

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,781
    Rep Power
    10

    Re: colors and console_printat

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •