Christmas Tree

Developer(s): Joey Latimer
Date: 1983
Type: Program
Platform(s): TS 1000

This program draws a static Christmas tree scene using block graphics characters and then animates a set of decorative lights blinking on the tree. The tree is built from arrays of CHR$ 128 (a solid block) and CHR$ 136 (a half-block), printed with decreasing TAB values to form a triangular silhouette, with additional elements for trunk and branch details. After drawing the tree, the program uses PLOT and UNPLOT commands to toggle individual pixels on and off in a repeating loop from line 440 to 750, producing a twinkling-lights animation.


Program Structure

The program divides into three clear phases:

  1. Initialisation (lines 10–120): Three string arrays are prepared — A$ as a 25-character string of solid blocks, B$ as a 2×5 array for trunk segments, and C$ as a 2×3 array for smaller branch details.
  2. Tree drawing (lines 130–390): The triangular tree body is printed with progressively smaller TAB values and increasing substring lengths of A$, then trunk and branch overlays are positioned with AT.
  3. Light animation loop (lines 400–750): Pairs of UNPLOT and PLOT statements toggle individual pixels, with a character printed at AT 0,15 between groups to pace or indicate phase; GOTO 440 creates an infinite loop.

Block Graphics Usage

A$ is filled entirely with CHR$ 128 (the full-block character ▘▘ — actually the space-with-all-pixels-set block graphic). CHR$ 136 is used in B$ and C$ for a different block pattern, giving the trunk and inner branch regions a visually distinct shade. Substring slicing of the form A$( TO N) avoids the need for separate variables of different lengths and saves memory.

Tree Shape Algorithm

Lines 130–290 print the triangular canopy. Each row reduces the TAB value by 1 and increases the printed substring length by 2, producing a symmetric widening effect. Some rows are repeated (e.g. lines 160/170 and 240/250) to give the tree a slightly stepped or layered silhouette rather than a smooth cone. The loop at lines 300–320 adds five identical rows of a three-character width at TAB 14, forming a narrow trunk or central stem below the canopy.

Line rangeTABWidth (chars)
130151
140143
150–160135
170127
180119
190–2001011
210913
220815
230–250717
260619
270521
280423
290325

Animation Technique

The twinkling effect is achieved by grouping pixels into two alternating sets. Lines 400–630 UNPLOT (erase) one set of pixel coordinates and PLOT the other, then lines 640–750 reverse the operation. The infinite loop is closed by GOTO 440 at line 750, so the two sets of lights alternate indefinitely.

Between each group of pixel operations a character is printed at AT 0,15 — alternating CHR$ 138 and CHR$ 131. This acts as a visible phase indicator in the top area of the screen, likely unintentional decoration or a debugging remnant rather than a meaningful display element, since it sits above the tree.

Notable Techniques and Idioms

  • Array substring initialisation: LET B$(1)=CHR$ 128+CHR$ 128+CHR$ 136+CHR$ 128+CHR$ 128 assigns all five characters of a 2D string array row in one statement by concatenation.
  • Slice assignment: LET C$(2)=B$(2, TO 3) copies a substring slice from one array into another, a compact way to reuse a pattern.
  • TO-slice printing: A$( TO N) avoids needing multiple string variables of different lengths; only A$ is required for all canopy widths.
  • Multiple AT clauses in one PRINT: Lines 330–390 chain two AT positions in a single PRINT statement, reducing line count and slightly improving speed.

Content

Appears On

Related Products

Related Articles

As the snow falls outside, your family can gather round the computer with glasses of eggnog and fall under the...

Related Content

Image Gallery

Christmas Tree

Source Code

 10 DIM A$(25)
 20 DIM B$(2,5)
 30 DIM C$(2,3)
 40 FOR N=1 TO 25
 50 LET A$(N)=CHR$ 128
 60 NEXT N
 70 LET B$(1)=CHR$ 128+CHR$ 128+CHR$ 136+CHR$ 128+CHR$ 128
 80 FOR N=1 TO 5
 90 LET B$(2,N)=CHR$ 136
 100 NEXT N
 110 LET C$(1)=CHR$ 128+CHR$ 136+CHR$ 128
 120 LET C$(2)=B$(2, TO 3)
 130 PRINT TAB 15;A$( TO 1)
 140 PRINT TAB 14;A$( TO 3)
 150 PRINT TAB 13;A$( TO 5)
 160 PRINT TAB 13;A$( TO 5)
 170 PRINT TAB 12;A$( TO 7)
 180 PRINT TAB 11;A$( TO 9)
 190 PRINT TAB 10;A$( TO 11)
 200 PRINT TAB 10;A$( TO 11)
 210 PRINT TAB 9;A$( TO 13)
 220 PRINT TAB 8;A$( TO 15)
 230 PRINT TAB 7;A$( TO 17)
 240 PRINT TAB 7;A$( TO 17)
 250 PRINT TAB 7;A$( TO 17)
 260 PRINT TAB 6;A$( TO 19)
 270 PRINT TAB 5;A$( TO 21)
 280 PRINT TAB 4;A$( TO 23)
 290 PRINT TAB 3;A$
 300 FOR N=1 TO 5
 310 PRINT TAB 14;A$( TO 3)
 320 NEXT N
 330 PRINT AT 18,4;B$(1);AT 19,4;B$(2)
 340 PRINT AT 20,4;B$(1);AT 21,4;B$(1)
 350 PRINT AT 18,10;C$(1);AT 19,10;C$(1)
 360 PRINT AT 20,10;C$(2);AT 21,10;C$(1)
 370 PRINT AT 19,18;C$(1);AT 20,18;C$(2)
 380 PRINT AT 21,18;C$(1);AT 19,22;A$( TO 5)
 390 PRINT AT 20,22;B$(2);AT 21,22;A$( TO 5)
 400 UNPLOT 35,33
 410 UNPLOT 27,30
 420 UNPLOT 24,23
 430 UNPLOT 16,17
 440 PRINT AT 0,15;CHR$ 138
 450 UNPLOT 38,29
 460 UNPLOT 22,28
 470 UNPLOT 25,28
 480 PRINT AT 0,15;CHR$ 131
 490 UNPLOT 31,28
 500 UNPLOT 37,26
 510 UNPLOT 19,23
 520 PRINT AT 0,15;CHR$ 138
 530 UNPLOT 29,22
 540 UNPLOT 39,22
 550 UNPLOT 20,16
 560 PRINT AT 0,15;CHR$ 131
 570 UNPLOT 28,16
 580 UNPLOT 34,17
 590 UNPLOT 42,16
 600 PRINT AT 0,15;CHR$ 138
 610 UNPLOT 21,13
 620 UNPLOT 29,36
 630 PLOT 25,28
 640 PRINT AT 0,15;CHR$ 131
 650 PLOT 38,29
 660 PLOT 19,23
 670 PLOT 29,22
 680 PRINT AT 0,15;CHR$ 138
 690 PLOT 39,22
 700 PLOT 31,28
 710 PLOT 22,28
 720 PRINT AT 0,15;CHR$ 131
 730 PLOT 37,26
 740 PLOT 29,36
 750 GOTO 440

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

Scroll to Top