Page 1 of 1

16 shades of gray

Posted: Thu Oct 03, 2019 10:09 am
by Jvi
Gray.zip
Gray.zip
(467 Bytes) Downloaded 165 times
The display of the DM42, nice as it is, is only capable of displaying 2 colors, black and white. When you are dealing with graphics, you often need more colors. On the DM42 offimg pictures, you can see how this problem has been solved by using patterns.
Can this be done with a program? Yes it can.
The program below, 'Gray' creates a 16*1 matrix 'PG' (short for Pixel gray), which contains 16 4x4 bitmaps patterned with increasing blackness. These bitmaps can be plotted with the AGRAPH function, effectively creating a 4x4 pixel with 16 shades of gray (no, not 50 ;) ).

Code: Select all

00 { 221-Byte Prgm }
01▸LBL "Gray"
02 16
03 1
04 DIM "PG"
05 INDEX "PG"
06 0
07 STO "A"
08 STO "B"
09 STO "C"
10 STO "D"
11 STO "E"
12 1
13 STO+ "A"
14 XEQ 00
15 4
16 STO+ "C"
17 XEQ 00
18 1
19 STO+ "C"
20 XEQ 00
21 4
22 STO+ "A"
23 XEQ 00
24 2
25 STO+ "B"
26 XEQ 00
27 8
28 STO+ "D"
29 XEQ 00
30 2
31 STO+ "D"
32 XEQ 00
33 8
34 STO+ "B"
35 XEQ 00
36 1
37 STO+ "B"
38 XEQ 00
39 4
40 STO+ "D"
41 XEQ 00
42 1
43 STO+ "D"
44 XEQ 00
45 4
46 STO+ "B"
47 XEQ 00
48 2
49 STO+ "A"
50 XEQ 00
51 8
52 STO+ "C"
53 XEQ 00
54 2
55 STO+ "C"
56 XEQ 00
57 8
58 STO+ "A"
59 XEQ 00
60 CLV "A"
61 CLV "B"
62 CLV "C"
63 CLV "D"
64 CLV "E"
65 RTN
66▸LBL 00
67 1
68 STO+ "E"
69 CLA
70 RCL "A"
71 XTOA
72 RCL "B"
73 XTOA
74 RCL "C"
75 XTOA
76 RCL "D"
77 XTOA
78 RCL "E"
79 1
80 STOIJ
81 ASTO ST X
82 STOEL
83 RTN
84 END
I have enclosed a small demonstration program, 'Ball', which XEQ's the 'Gray' program, and then draws a smoothly shaded ball on the screen.

Code: Select all

00 { 118-Byte Prgm }
01▸LBL "BALL"
02 XEQ "Gray"
03 -25.025
04 STO 00
05▸LBL 00
06 625
07 RCL 00
08 IP
09 X↑2
10 -
11 SQRT
12 IP
13 ENTER
14 ENTER
15 1ᴇ3
16 ÷
17 +
18 +/-
19 STO 01
20▸LBL 01
21 8
22 RCL 01
23 -
24 X↑2
25 -12
26 RCL 00
27 -
28 X↑2
29 +
30 SQRT
31 2.4
32 ÷
33 1
34 +
35 IP
36 16
37 X<>Y
38 X>Y?
39 X<>Y
40 1
41 STOIJ
42 CLA
43 RCLEL
44 XTOA
45 RCL 00
46 IP
47 4
48 ×
49 120
50 +
51 RCL 01
52 IP
53 4
54 ×
55 200
56 +
57 AGRAPH
58 ISG 01
59 GTO 01
60 ISG 00
61 GTO 00
62 CLST
63 CLV "PG"
64 END
The downside is of course, that the gray pixels are 4x4 times as big as the normal pixel, but they also cover 16 times what the normal pixel does, so the drawing is quite fast. The zip file 'Gray.zip' contains both programs

Re: 16 shades of gray

Posted: Wed May 27, 2020 3:55 am
by StatsDoctor
Hello Jvi,

Thanks for such a nice program (actually two nice programs)! The BALL program runs well and does what you said it would do. I like programs such as yours that demonstrate the graphical abilities of the DM42. Thanks for sharing.

Can one write their own graphics programs which XEQ the GRAY program to create other shapes with patterns of increasing or decreasing blackness?

Best,

Bob

Re: 16 shades of gray

Posted: Sun Jul 26, 2020 8:00 am
by Jvi
Hi Bob

Of course you can use the Gray program. It is for this very reason I post here.
If you make a nice program with it, please post it in this thread.

Cheers
Jan