Custom Colors

Developer(s): George Gilder
Date: 1988
Type: Program
Platform(s): TS 2068
Tags: Demo

This program demonstrates custom color combinations on a resistor color code chart, using user-defined graphics (UDGs) to create colored block symbols for each resistor band color. It defines UDGs “O” through “U” by POKEing bit patterns via RESTORE/READ/DATA loops, creating checkerboard and solid block patterns in memory. The chart maps resistor color codes (BLACK through SILVER) to single-letter mnemonics, and uses PLOT/DRAW to render a symbolic resistor outline on screen. A second section (lines 500–630, labeled “C2”) cycles through all 56 foreground/background color combinations using a string of UDG block characters to display color bars across the full screen.


Program Structure

The listing is split into two conceptual sections sharing a single program file. Lines 404–466 form “Custom Colors C1,” which renders a resistor color code reference chart using UDGs and PLOT/DRAW graphics. Lines 500–630 form “Custom Colors C2,” which is a standalone color bar cycling demo. Line 605 explicitly notes that both sections should be typed and run together.

Line rangePurpose
404–412Main chart display: border/paper/ink setup, PRINT color labels with UDG symbols
457–461Subroutine: prints UDG blocks and draws a PLOT/DRAW resistor outline
462–466Subroutine: defines UDGs Q–U and O–P via POKE USR and DATA
490REM separator
500–550C2 color block demo: nested loops print random-paper colored UDG characters
600–630C2 systematic color bar cycle: all 56 INK/PAPER combinations

UDG Definition Technique

The subroutine at line 462 uses RESTORE followed by a FOR loop from x (0) to 39 (40 bytes total), READing from the DATA statement at line 463 and POKEing into USR "Q"+F. This defines five UDGs (Q through U, each 8 bytes) in one pass. A second pass at line 464 similarly defines UDGs O and P (16 bytes) from DATA at line 465, using pre-assigned variables h=255 and g=170 inside the DATA statement itself — an unusual technique where variable names appear directly in DATA, which are evaluated as numeric expressions when READ.

The resulting UDG patterns include:

  • Alternating bytes 85, 170 (01010101 / 10101010): checkerboard pattern
  • Bytes 255, 129, 129 ... 255: hollow rectangle
  • All 128: left-edge vertical bar
  • All 1: right-edge vertical bar
  • All 170: alternating-column vertical stripes
  • Alternating 255, 0: horizontal stripes

Resistor Chart Display

Lines 406–411 print each resistor color band label alongside a UDG character rendered in the appropriate INK/PAPER color to give a visual swatch. The color-to-letter mapping used is: BLACK=0, BROWN=N, RED=R, ORANGE=O, YELLOW=Y, GREEN=G, BLUE=B, VIOLET=V, GRAY=E, WHITE=W, GOLD=L, SILVER=S. The variable X (initialized to 0) serves double duty as both the INK 0 color index and a zero-value used in DRAW statements for horizontal/vertical-only segments.

PLOT/DRAW Resistor Outline

Lines 458–460 draw a simplified resistor body graphic. Line 458 draws a closed rectangle starting at pixel coordinate (96, 64): right 80, down 9, left 80, up 9. Line 460 draws two lead lines: left 30 from (96,60) and right 30 from (176,60), representing the resistor’s wire leads. The variable x (value 0) is used as the zero argument in DRAW to avoid typing the literal digit, a minor code-size optimization.

Key BASIC Idioms

  • VAL "number" is used extensively in the subroutines (lines 457–461) as a memory-saving technique; the tokenizer stores numeric literals directly, so VAL of a string can sometimes save bytes in specific contexts.
  • The variable x=0 is reused throughout as a zero literal stand-in in DRAW, FOR, INK, and TAB statements.
  • RESTORE 465 at line 464 targets a specific line so that the second READ loop picks up data for UDGs O and P without consuming the C1 UDG data again.

C2 Color Bar Demo (Lines 500–630)

The section at lines 500–550 prints UDG characters (CHR$ 157 through 160, i.e., UDGs O through R) at positions computed from loop variables, with random PAPER and sequential INK values, producing a colorful grid. After a keypress (PAUSE 0), it loops back to line 500 indefinitely.

Lines 620–630 provide a more systematic demo: a 32-character string b$ of UDG \q characters is printed in every combination of PAPER (0–6) and INK (0–7), producing 56 lines of solid color bars cycling through the full palette.

Anomalies and Notes

  • The STOP at line 413 halts execution after the chart is displayed, preventing the interpreter from falling through into the C2 section unintentionally.
  • Line 463’s DATA uses the literal INT 85, which evaluates to 85 (INT of a non-fractional number is a no-op), likely a typographical artifact.

Source Code

  404 LET X=0: GO SUB 462: REM COLORS C1 1987 G. GILDER
  405 CLS : BORDER VAL "7": PAPER VAL "7": INK X: LET F=1
  406 PRINT INK 2;"RESISTOR COLOR CODE CHART"; INK 0';"Enter color bars on resistor"''
  407 PRINT INK X;TAB X;"\o BLACK=0";TAB X; INK 2; PAPER 0;"\q"; PAPER 7; INK 2;" BROWN=N"; INK 2;TAB X;"\o RED  =R";
  408 PRINT TAB X; PAPER 2; INK 6;"\q"; PAPER 7; INK 2;" ORANG=O"
  409 PRINT TAB X; INK 6;"\o YELLW=Y";TAB X; INK 4;"\o GREEN=G";TAB X; INK 1;"\o BLUE =B";
  410 PRINT TAB X; PAPER 3; INK 1;"\q"; PAPER 7;" VIOLT=V";TAB X; INK X;"\q GRAY =E";TAB X;"\r WHITE=W";
  411 PRINT ''''TAB X;; PAPER 6; INK 0;"\q"; PAPER 7; INK 6;" GOLD =L";TAB X; INK X;"\q"; INK 0;" SILVER=S";
  412 GO SUB 457
  413 PRINT AT 20,0;"UDG \o \p \q \r \s \t \u "'"    O P Q R S T U": STOP 
  457 PRINT AT VAL "14",VAL "12";"\q\q\q\q\q\q\q\q\q\q"
  458 PLOT VAL "96",VAL "64": DRAW VAL "80",x: DRAW x,VAL "-9": DRAW VAL "-80",x: DRAW x,VAL "9"
  460 PLOT 96,60: DRAW -30,0: PLOT 176,60: DRAW 30,0
  461 RETURN 
  462 RESTORE : FOR f=x TO VAL "39": READ y: POKE USR "Q"+F,y: NEXT f
  463 DATA INT 85,170,85,170,85,170,85,170,255,129,129,129,129,129,129,255,128,128,128,128,128,128,128,128,1,1,1,1,1,1,1,1,170,170,170,170,170,170,170,170
  464 LET h=255: LET g=170: RESTORE 465: FOR f=x TO VAL "15": READ y: POKE USR "O"+f,y: NEXT f
  465 DATA g,h,g,h,g,h,g,h,255,0,255,0,255,0,255,0
  466 RETURN 
  490 REM 
  500 REM ** COLOR BLOCKS **
  505 LET a=5: FOR p=157 TO 160: FOR i=0 TO 6
  510 LET k=INT (RND*7): PRINT AT a,i*2+6; PAPER k; INK i;CHR$ p;CHR$ p
  515 NEXT i: LET a=a+1: NEXT p
  550 PRINT AT 20,6;"PRESS ANY KEY"';TAB 7;"TO CONTINUE": PAUSE 0: GO TO 500
  590 REM 
  600 REM ************************** Custom Colors C2 **************************
  605 REM Try this program & see dozens of color bars using only one screen and the standard 2068 colors. Note: type and run these programs together.
  610 LET b$="\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q\q"
  620 FOR i=0 TO 7: FOR f=0 TO 6: PRINT PAPER f; INK i;b$
  630 NEXT f: NEXT i

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.