Friday, November 3, 2017

Chapter 15 - COLOR


Tired of all this black and white? Then the COLOR statement is for you. Try this program for size:
    CLS
    COLOR 2, 0
    PRINT "That's ";
    COLOR 3, 0
    PRINT "more ";
    COLOR 5, 0
    PRINT "like it!"
Color takes two numbers. The first number is the foreground color. The second number is the background color. For example, if you want to print black on white instead of white on black, use "COLOR 0,7". The colors each have their own number:
  • 0 - Black
  • 1 - Blue
  • 2 - Green
  • 3 - Cyan
  • 4 - Red
  • 5 - Magenta
  • 6 - Yellow
  • 7 - White
There are plenty of other colors too. Try the numbers from 8 through 15 to see what colors you get. Basically, if you add 8 to any of the above colors, you get brighter versions of the same color. Take blue which is 1 and add 8 and you get 9 which is bright blue.

Blinking

Adding 16 to a color number gives you a blinking version. This doesn't work in a DOS window, though. Press <ALT><ENTER> to switch to full-screen mode which will show the blinking. Try this program:
    CLS
    COLOR 28, 0
    PRINT "*** WARNING ***"
    COLOR 15, 0
    PRINT "Programming can be too much fun!"

Color can be used in many ways to make your programs more interesting.

No comments:

Post a Comment