Thread: Makeing colors

  1. #1
    Unregistered
    Guest

    Makeing colors

    How do i change the font color in my C++ programs??? For linux? For Windows??

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Do a search on the board for something like 'changing color'. Someone posted a really handy color changer function a while back. I can't remember who it was, but you could do a search for their name if someone else remembers who...
    Blue

  3. #3
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Try running this. It shows all of the colors and the code is easy to understand.
    Code:
    #include <windows.h>
    #include <iostream.h>
    #include <stdio.h>
    
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    
    
    void color(int color) 
    { 
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color); 
    } 
    
    
    
    
    
    
    void main ()
    {
       int i = 0;
       for (int x = 0; x <= 79; x+=3)
       {
          for (int y = 0; y <= 49; y+=3)
          {
             color(i);
             gotoxy(x,y);
             printf("%1d",i);
             i++;
             if (i > 255)
             break;
          }
       if (i > 255)
       break;
       }
    
    }

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >void main ()
    tim, I know you didn't use void main. My eyes must be playing tricks on me due to sleep deprivation

    -Prelude
    My best code is written with the delete key.

  5. #5
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    I made that program late at night. I didn't feel like spending the extra 3 seconds writing return 0. I'm sorry. Here's the real version:
    Code:
    #include <windows.h>
    #include <iostream.h>
    #include <stdio.h>
    
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_H
    ANDLE), coord);
    }
    
    
    
    void color(int color) 
    { 
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA
    NDLE),color); 
    } 
    
    
    
    
    
    
    int main (void)
    {
       int i = 0;
       for (int x = 0; x <= 79; x+=3)
       {
          for (int y = 0; y <= 49; y+=3)
          {
             color(i);
             gotoxy(x,y);
             printf("%1d",i);
             i++;
             if (i > 255)
             break;
          }
       if (i > 255)
       break;
       }
    
       return (0);
    }

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897

    Maybe I should change my name to "Goddess of Nitpicking".

    -Prelude
    My best code is written with the delete key.

  7. #7
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Or maybe perfectionist prick!!!!!
    Hehe just kidding.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why I only get 8 colors out of ncurses?
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 05-08-2007, 06:06 PM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. different colors
    By Paveltc in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-19-2002, 10:21 AM
  5. Text Colors
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 07-11-2002, 06:57 AM