Draw lines with bitmap patterns

Contributions to this software library are always welcome. Please ensure that you post program listings rather than .raw files. They give a reasonable idea of what your program does without having to load them into a DM42 and you can also include comments in your code. Check out the following link for a decoder/encoder: https://technical.swissmicros.com/decoders/dm42/

You can then copy/paste the listing and post it in "code" tags.
Post Reply
Jvi
Posts: 9
Joined: Fri Aug 09, 2019 6:03 am

Draw lines with bitmap patterns

Post by Jvi »

This program, Fline (Fatline) draw a line with the current bitmap pattern, between 2 points defined by the variables R1,C1 And R2,C2.

Code: Select all

00 { 115-Byte Prgm }
01▸LBL "Fline"
02 "↓•••↓"
03 RCL "R1"
04 RCL "C1"
05 AGRAPH
06 RCL "R2"
07 RCL "R1"
08 -
09 STO "RS"
10 ABS
11 RCL "C2"
12 RCL "C1"
13 -
14 STO "CS"
15 ABS
16 X<Y?
17 X<>Y
18 X=0?
19 RTN
20 STO÷ "RS"
21 STO÷ "CS"
22 IP
23 STO "ST"
24 RCL "RS"
25 RCL "CS"
26 RCL "R1"
27 RCL "C1"
28▸LBL 00
29 RCL+ ST Z
30 X<>Y
31 RCL+ ST T
32 X<>Y
33 AGRAPH
34 DSE "ST"
35 GTO 00
36 CLV "RS"
37 CLV "CS"
38 CLV "ST"
39 END
The program is meant to be XEQ'ed from another program, after the start and end coordinates of the line you wish to draw, have been entered into the variables C1,R1 and C2,R2.
At the start of the program, in Line 02, a bitmap pattern is defined, which is a 5x5 square without the corners, but you can enter any bitmap pattern you wish. You could even remove it completely, and have the calling program defining the bitmap.
The program draws the pattern starting from C1,R1 to C2,R2 by plotting the bitmap pattern in pixel sized increments.
The actual code drawing the line, beginning at LBL 00, is only 8 instructions long, and mostly uses the stack. I dont think this can be much improved.
You can also make it draw pixel thin lines by replacing the AGRAPH instructions in line 5 and 33 with PIXEL.
It does not check if it is outside the screen.

I have also enclosed a demo program, FDEMO, which draws a polygon with the number of corners defined by the number in stack register X.
It draws all lines possible between the corners.

Here is the code for the demo:

Code: Select all

00 { 117-Byte Prgm }
01▸LBL "FDEMO"
02 STO 00
03 360
04 X<>Y
05 ÷
06 STO 02
07 1ᴇ-3
08 STO+ 00
09▸LBL 00
10 RCL 00
11 IP
12 1
13 -
14 STO 01
15 RCL 00
16 RCL 02
17 ×
18 STO 03
19 SIN
20 100
21 ×
22 200
23 +
24 STO "C1"
25 RCL 03
26 COS
27 100
28 ×
29 120
30 +
31 STO "R1"
32▸LBL 01
33 RCL 01
34 RCL 02
35 ×
36 STO 03
37 SIN
38 100
39 ×
40 200
41 +
42 STO "C2"
43 RCL 03
44 COS
45 100
46 ×
47 120
48 +
49 STO "R2"
50 XEQ "Fline"
51 DSE 01
52 GTO 01
53 DSE 00
54 GTO 00
55 END
With 7 in stack register X, the program draws this:
20210422-06170974.bmp
20210422-06170974.bmp (12.31 KiB) Viewed 331 times


Here are the programs if you wish to download them:
Fline.raw
(118 Bytes) Downloaded 9 times
FDEMO.raw
(120 Bytes) Downloaded 8 times
Post Reply