Eight or Sixteen Colors in Java

Paint QR in Java Eight or Sixteen Colors
Eight or Sixteen Colors
Decoding QR Code In Java
Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications.
While NCurses may report only eight colors available, on most terminals there are twice as many colors to choose from. The secret is to apply the bold text attribute (A_BOLD) with a color pair. The bold text attribute affects only the foreground text color. It gives you access to the eight brighter versions of the standard eight (or however many) text colors available.
QR Code Creation In Java
Using Barcode creation for Java Control to generate, create QR Code image in Java applications.
3
Recognizing Denso QR Bar Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
Formatting Text
Paint Bar Code In Java
Using Barcode creation for Java Control to generate, create barcode image in Java applications.
For example, if color pair 1 is defined as Magenta on Black, applying bold to the text attribute yields pink on black text:
Recognize Bar Code In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
attrset(COLOR_PAIR(1) | A_BOLD);
Creating Denso QR Bar Code In C#
Using Barcode generator for .NET Control to generate, create QR Code image in .NET applications.
The other foreground text colors become brighter versions of their original colors when logically OR d with the A_BOLD attribute. Brown actually becomes yellow, and black becomes a midtone gray.
Quick Response Code Printer In .NET
Using Barcode generator for ASP.NET Control to generate, create QR-Code image in ASP.NET applications.
Spruce Up Some Text!
Creating QR-Code In .NET
Using Barcode printer for VS .NET Control to generate, create QR Code image in .NET framework applications.
The color-pair stuff is only confusing when you re reading about it. The best way to understand the way NCurses applies color is, naturally, with a test program such as Listing 3-4.
QR Code Printer In VB.NET
Using Barcode printer for Visual Studio .NET Control to generate, create QR Code JIS X 0510 image in .NET applications.
Listing 3-4: colorme.c
Code 3 Of 9 Drawer In Java
Using Barcode generation for Java Control to generate, create Code39 image in Java applications.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include <ncurses.h> #include <stdlib.h> void bomb(int r); int main(void) { initscr(); start_color(); init_pair(1,COLOR_BLACK,COLOR_RED); init_pair(2,COLOR_BLUE,COLOR_BLACK); attrset(COLOR_PAIR(1)); addstr( My name is Mr. Black!\n ); attrset(COLOR_PAIR(2)); addstr( My name is Mr. Blue!\n ); attrset(COLOR_PAIR(1)); addstr( How do you do \n ); attrset(COLOR_PAIR(2)); addstr( How do I do ); attron(A_BOLD); addstr( what ); attroff(A_BOLD); addch( ); refresh(); getch(); endwin(); return 0; }
Creating Bar Code In Java
Using Barcode drawer for Java Control to generate, create barcode image in Java applications.
3
Bar Code Creation In Java
Using Barcode creation for Java Control to generate, create bar code image in Java applications.
Formatting Text
Generating MSI Plessey In Java
Using Barcode encoder for Java Control to generate, create MSI Plessey image in Java applications.
Note that I m not using any error-checking with start_color() in line 10. In this code, I m assuming that you know whether or not your terminal can do color. In the code you plan on releasing, it s wise to check for color and have your programs behave accordingly. This basic program contains a simple back-and-forth conversation between two color pairs, shown in Figure 3-2. Be mindful of the parenthesis in the attrset(COLOR_PAIR(n)) statements. Notice how the color attributes affect only the text put to the screen. The red background doesn t splash out the rest of the line, and the foreground color, like other text attributes, affects only characters, not the blanks or white space between text.
ANSI/AIM Code 128 Generation In C#
Using Barcode printer for Visual Studio .NET Control to generate, create Code128 image in VS .NET applications.
A Color Thing Your Terminal Probably Cannot Do
Create Code 128 Code Set A In .NET
Using Barcode creation for ASP.NET Control to generate, create Code128 image in ASP.NET applications.
NCurses has a treat for you when you re lucky enough to have a terminal that can define its own text colors. For example, you can define pink text and use it if you like. This is done via the init_color() function. The problem is that this function doesn t appear to be supported on many terminals. That can be confirmed with another function, can_change_color(), which returns a logical TRUE or FALSE depending on whether the terminal has the colorchanging ability:
Code 3 Of 9 Generator In .NET Framework
Using Barcode maker for VS .NET Control to generate, create ANSI/AIM Code 39 image in Visual Studio .NET applications.
if(!can_change_color()) bomb( Unable to do color change.\n );
UPC-A Supplement 2 Scanner In VS .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
Now if you can get it to work, the init_color() function comes into play, wherein you can create your own unique text colors. That function looks something like this:
UCC - 12 Maker In Visual Basic .NET
Using Barcode generator for VS .NET Control to generate, create EAN / UCC - 13 image in Visual Studio .NET applications.
init_color(color,r,g,b);
Making Code128 In .NET Framework
Using Barcode drawer for Visual Studio .NET Control to generate, create Code 128C image in .NET framework applications.
Figure 3-2: Sample output for colorme.c code
Drawing Bar Code In VB.NET
Using Barcode generator for .NET framework Control to generate, create barcode image in VS .NET applications.
3
Formatting Text
The values passed to init_color() are all short integers. The first color represents the new color number. It must be in the range of zero to COLOR minus 1. Then come values for the red (r), green (g), and blue (b) arguments, each of which ranges from 0 to 1000, representing the intensity of that particular color. So, for example, the following call to init_color() defines (or redefines) color number 2 as a dark gray:
init_color(2,250,250,250);
The following source code in Listing 3-5 demonstrates how init_color is used to define the color pink for color code 1.
Listing 3-5: color_me.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #include <ncurses.h> #define #define #define #define NEW_COLOR 1 RED 1000 GREEN 750 BLUE 750
int main(void) { initscr(); start_color(); if(!can_change_color()) addstr( This probably won t work, but anyway:\n ); init_color(NEW_COLOR,RED,GREEN,BLUE); init_pair(1,NEW_COLOR,COLOR_BLACK); attrset(COLOR_PAIR(1)); printw( This is the new color %d.\n ,NEW_COLOR); refresh(); getch(); endwin(); return 0; }
The init_color() function is used in line 15 to create the new color pink by mixing 1000 points of red with 750 points each of blue and green, which works out to be pink. Then that color is put to use by the init_pair() function, and the printw() function should display its text in the new color. On my terminal, which cannot change text color values, the new color shows up as red, which is the default for color 1 anyway. I would call that a failure.