Sharp logo

MZ-800 course Chapter 7 
7. Graphical applications


What exactly are graphical applications? Are they graphs, mathematical figures or drawings? As a matter of fact, all these things are present in this chapter. Graphical applications form a wide area of programs from mathematical figures to animations and of course the two- and three dimensional pie- and bar diagrams used for business applications. In the first part of this chapter we shall give a few programs that draw funny mathematical figures.

7.1 Funny mathematical figures


Spirograph

1 ’ SPIROGRAPH
2 INIT "CRT:M1":K=1.7:PAL 3,3
3 Z=3.2:M=50:N=31:P=600:PAL 0,15
4 READ T,A,B,F,C:IF A>0 THEN 6
5 BEEP:COLOR 1:END
6 S=(A+B)/2:E=A-S:H=T/60*p:D=H:IF K=3 THEN P=240
7 IF T=20 THEN P=240
8 IF T=30 THEN P=125
9 FOR I=T TO T+P:IF C=2 THEN X=M+SIN(H)*S+SIN(D)*E:Y=N+COS(H)*S+COs(D)*E
10 H=I/60*p:D=(T+F*(I-T))/60*p
11 IF C=0 THEN X=M:Y=N
12 IF C=1 THEN X=M+SIN(H)*S:Y=N+COs(H)*S
13 LINE [K]X*Z,Y*Z,(M+SIN(H)*S+SIN(D)*E)*Z,(N+COs(H)*S+COs(D)*E)*Z
14 NEXT I
15 K=K+.7
16 GOTO 4
17 DATA 0,25,15,4,4,2,10,15,9,-2.4,1,20,9,5,-2.5,0,30,30,20,1,0,0,0,0,0

If you own the VIDEO-RAM expansion, then you can make the effect even nicer by replacing line 2 and 14 with:

2 INIT "CRT:M2":K=1
14 K=K+1


Wave

10 INIT "CRT:M1":B=0
20 FOR A=1 TO 15 STEP .1
30 SET B*10,100+COs(A)*20
40 B=B+SIN(A)
50 IF SIN(A)<0 THEN B=B+1
60 IF SIN(A)>0 THEN B=B-.5
70 NEXT A
80 GET A$:IF A$="" THEN 80
90 CLS:END


Mosaic

10 INIT "CRT:M1":PAL 3,7 :B=.1
20 FOR A=0 TO 2*p STEP p/120
30 X=SIN(A+B*p)*70+160
40 Y=COs(A+B*p)*70+100
50 X2=SIN(A-B*p)*70+100
60 Y2=COs(AB*p)*70+100
70 LINE X2,Y2,X,Y
80 B=B+.1:NEXT A
 90 GET A$:IF A$="" THEN 90
100 CLS:END


Pillow

10 INIT "CRT:M1"
20 FOR A=0 TO 2*p STEP p/3
30 FOR X=0 TO 2*p STEP .1
40 LINE (SIN(X+A)+COS(X+A)*100+160,SIN(X)*80+100,
   (SIN(X+.1+A)+COS(X+.1+A))*100+160,SIN(X+.1)*80+100
50 NEXT X,A
60 GET A$:IF A$="" THEN 60
70 CLS:END

Hat

It takes a while before the drawing is finished, it only takes 28 minutes and 47 seconds.

10 INIT "CRT:M3":PAL 1,0:PAL 0,7
20 W=45:K=.3125:A=180:K1=45
30 U=320:V=80:H=.5:RD=4*ATN(1)/180
40 C=K*COs(W*RD):S=K*SIN(W*RD)
50 DX=3:DY=8:AF=A/210
60 DIM H(320)
70 FOR L=0 TO 320
80 H(L)=1000
90 NEXT L
100 FOR YY=-210 TO 210 STEP DY
110 Y=YY*AF
120 FOR XX=-210 TO 210 STEP DX
130 X=XX*AF:R=SQR(X*X+Y*Y)*RD
140 Z=K1*(COs(R)COs(3*R)/3+COs(5*R)/5-COS(7*R)/7)
150 XG=INT(U+XX+C*YY+H)
160 YG=INT(V-S*YY-Z+H
170 IF XX>-210 THEN 210
180 F1=0:L=INT(XG/DX)
190 IF YG<=H(L) THEN F1=1:H(L)=YG
200 X1=XG:Y1=YG:GOTO 260
210 F2=0:L=INT(XG/DX)
220 IF YG<=H(L) THEN F2=1:H(L)=YG
230 X2=XG:Y2=YG:IF F1*F2<>1 THEN 250
240 LINE X1,Y1,X2,Y2
250 X1=X2:Y1=Y2:F1=F2
260 NEXT XX,YY
270 GET I$:IF I$="" THEN 270 ELSE CLS:END


3-D computermountain

This program takes even more time than the last one, about twice the time. It draws a 3-D computermountain. The lines you normally do not see, you do see here.

10 INIT "CRT:M3":A=0:PAL 1,0:PAL 0,7
20 FOR Y=-2.5 TO 2.5 STEP .1:B=0
30 FOR X=-2 TO 2 STEP .025
40 Z=(3*X*X+Y*Y)*EXP(1-X*X-Y*Y)
50 SET X*120+250+A,195-Z*40-B
60 B=B+.5:A=A+.02:NEXT X,Y
70 B=0:FOR X=-2 TO 2 STEP .1:A=0
80 FOR Y=-2.5 TO 2.5 STEP .025
90 Z=(3*X*X+Y*Y)*EXP(1-X*X-Y*Y)
100 SET X*120+250+A,195-Z*40-B
110 A=A+.8:NEXT Y:B=B+2:NEXT X
120 GET A$:IF A$="" THEN 120
130 CLS:END


Nameless figures

Now we shall give a couple of nameless mathematical figures. They all look nice, but do not resemble anything; hence the name.

1 INIT "CRT:M1":PAL 0,7:PAL 3,0
2 A=160:B=100:H=1/2:RD=4*ATN(1)/180
3 FOR K=-40 TO 40 STEP 10:X1=A+60:Y1=B
4 FOR W=2 TO 360 STEP 2:P=W*RD:R=60+K*SIN(4*P):X2=INT(A+R*COs(P)+H)
5 Y2=INT(B-R*SIN(P)+H)
6 LINE X1,Y1,X2,Y2:X1=X2:Y1=Y2
7 NEXT W,K
10 INIT "CRT:M1":PAL 0,7:PAL 3,0
20 A=160:B=100:H=1/2:RD=4*ATN(1)/180
30 FOR K=20 TO 100 STEP 10
40 P=0:R=COs(4*SIN(2*P))
50 X1=A+K*R*COs(P)+H:Y1=B-K*R*SIN(P)+H
60 FOR W=2 TO 360 STEP 2
70 P=W*RD:R=COs(4*SIN(2*P))
80 X2=A+K*R*COs(P)+H
90 Y2=B-K*R*SIN(P)+H
100 LINE X1,Y1,X2,Y2
110 X1=X2:Y1=Y2
120 NEXT W,K


Flower

10 INIT "CRT:M1":PAL 0,7:PAL 3,0
20 A=160:B=100:H=1/2:RD=4*ATN(1)/180
30 N=4:C=.25
40 FOR K=30 TO 80 STEP 10
50 X1=A+K:Y1=B
60 FOR W=3 TO 360 STEP 3
70 P=W*RD:R=K*(1+C*ABS(SIN(N*P)))
80 X2=A+R*COs(P)+H
90 Y2=BR*SIN(P)+H
100 LINE X1,Y1,X2,Y2
110 X1=X2:Y1=Y2
120 NEXT W,K
130 R=30:P1=(180/N)*RD
140 FOR J=1 TO N
150 P=J*P1
160 X1=A+R*COs(P)+H
170 Y1=BR*SIN(P)+H
180 X2=A+R*COs(P+4*ATN(1))+H
190 Y2=BR*SIN(P+4*ATN(1))+H
200 LINE X1,Y1,X2,Y2
210 NEXT J
10 INIT "CRT:M1":PAL 0,7:PAL 3,0
20 U=160:V=100:H=1/2:RD=4*ATN(1)/180
30 KX=10:KY=10
40 FOR F=1 TO 7:READ A,B
50 FOR N=-3 TO 3
60 T=0:GOSUB 150
70 X1=U+KX*X+H:Y1=V-KY*Y+H
80 FOR W=2 TO 360 STEP 2
90 T=W*RD:GOSUB 150
100 X2=U+KX*X+H:Y2=V-KY*Y+H
110 LINE X1,Y1,X2,Y2
120 X1,X2:Y1=Y2
130 NEXT W,N
140 WAIT 5000:CLS:NEXT F:END
150 X=(A+B)*COs(T)-N*B*COs((A+B)/B*T)
160 X=(A+B)*SIN(T)-N*B*SIN((A+B)/B*T)
170 RETURN
180 DATA -6,1,-6,2,-8,2,4,1,4,2,6,1,4,5,1.5

Now two other small programs will follow that also draw figures from simple mathematical formulae. You will see that simplicity can also be nice.

Both programs also use colors. With a color monitor or T.V. you will have the best effect. There are also more then four colors in use, so you will need the expansion-ICs in your computer to get the full 100% effect.


Colored sphere

10 INIT "CRT:M2":PAL 0,7
20 R=50:N=6:P=p/n:W=3:V=1
30 FOR I=0 TO N-1
40 K=P*I:A=R*COs(K):B=R*SIN(K):J=30*I
50 CIRCLE [V]160+A,B+100,R
60 V=V+1:IF V=5 THEN V=1
70 CIRCLE [W]160-A,100-B,R
80 W=W+1:IF W=5 THEN W=1
90 NEXT I


4-Coloured ‘star’

10 INIT "CRT:M2":PAL 0,7
20 X=240:Y=200:N=10
30 XX=120:YY=100
40 LINE 0,100,X,100
50 LINE XX,YY+100,XX,-YY+100
60 FOR I=1 TO N
70 X1=XX+XX/N*I
80 Y2=YY-(YY/N*(I-1))
90 X3=XX-XX/N*I
100 LINE [1]X1,100,XX,Y2+100
110 LINE [2]XX,Y2+100,X3,100
120 LINE [3]X3,100,XX,-Y2+100
130 LINE [4]XX,-Y2+100,X1,100
140 NEXT I

These were a number of examples of mathematical figures. Some of them were very simple, others were quite difficult. For someone who is not educated in mathematics it is difficult to understand how the figures are made. Even for people who are good in mathematics, it can be hard to understand how the formulae work exactly.

The figures you see here are either made by us, or from a number of books. The programs that are from those books, which are actually written for the P.C., have been examined thoroughly and rewritten for the SHARP MZ-800. The books in question are:

GRAPHICS VOOR MICROCOMPUTERS from KLUWER.
and
40 GRAFISCHE PROGRAMMA’S IN IBM- EN GW-BASIC van ACADEMIC SERVICE.

In these books there is also an explanation on how everything works. If you want to know more, you can find it in these books.

Previous page
Next page
Contents


Go to the top of this page Home

last updated March 22, 2006
Arjan Habing, Mark de Rover, Jeroen F. J. Laros, sharpmz@sharpmz.org