APL Graphics from First Principles
Vector 7:4, page 83
The text of this article is not yet online. No complete scan of this issue has been found. The only copy found, on vector.org.uk, is damaged: its page images are lost, but the text machine-read from them survives, shown below (help find a scan).
Unedited OCR text, machine-read from a scan now lost: it contains errors, and its APL is wrong. Shown for searching.
VECTOR Vol.7 No.4
APL Graphics - First Principles
by Graham Parkhouse (Dept. of Mechanical Engineering, University of Surrey)
a Phis is a demonstration and computer graphics, written dateractively with my computer. Text following a six space indentation is mine: all other my computer's response to my instructions, Some of my prefaced by the lamp symbol, a, This is to indicate that the text following it is commentary and is to be ignored by my computer. a The function PRINT displays a boolean matrix as a small-scale bitmap. Ail the functions used are listed at the end of the article. BACKGROUND+10=?120 160p10 PRINT BACKGROUND
@ BACKGROUND is a 120 by 160 boolean matrix with @ sparsity of 10: of the 19200 numbers, 1920 are likely to be 1s, the rest zeros. +/, BACKGROUND a Count the 1s 1888 a Only 32 short: normai for a random process! Had I printed BACKGROUND and would have filled ten pages, This iilustrates the efficiency of displaying information as a bitmap. Next I am going to explore the bottom right hand corner in more detail. BRACORNER+~ 24 ~32+BACKGROUND PRINT 10 MAGNIFY BRHCORNER
7 o"F
"hak orl, oe am am "a
a These big dots, each of 100 black pixels, much smaller than the space occupied by the character 1. Phe wedge of
83
VECTOR Vol.7 No.4
pointing up from the bottom of this pattern is visible i the bottom right hand corner of BACKGROUND. a If I think of BRHCORNER as my picture, then I BACKGROUND background by combining both matrices suitably magnified using v, PRINT BACKGROUNDVS MAGNIFY BRHCORNER
a I am going to choose PICTURE as the array I shall draw on, and with the help of the function BLOCK I can write on it 8 assigning values to appropriate blocks of p i x e l s ! I can draw a set of axes onto PICTURE with the following instructions: PICTURE*+120 160p0 a Take a clean sheet PICTURE(60 64;]+1 a Draw the x-axis PICTUREL; 80 sij+i a Draw the y-axis PICTURE(56+28;,4 202,420K0, 17) +1 a Draw ticks on the x-axis PICTURE(,1 205,+20*0,15;76+181+4 a Draw ticks on the y-axis eTEN+BLOCK '410' a Block of pixels showing 1 16 16 pMINUSTEN+BLOCK '-10! a Block of pixels showing - i6 24 BIGTEN+i0 MAGNIFY TEN a Magnify TEN BIGPEN[10x%116;1}+1 0 BIGTEN(:10%116}+4 PRINT BIGTEN a 16 x 16 pixel array
ZAR EEE EEE Tt
PICTURE (U0+116; 2841 24)+MINUSTEN a Numbering x-axis PICTURE(U0+116;112+146]+7EN PICTURE(92+116;85+124]+MINUSTEN a Numbering y-axis PICTURE (12+116;85+116]+TEN PRINT 2 MAGNIFY PICTURE a Labeled axes
10
~10 1o
-10
VECTOR Vol.7 No.4
AXES*PICTURE a Copy PICTURE for future use PICTURE+120 16090 a Take a clean sheet a Indexing pixels is low level APL graphics: very useful sometimes, but rather fiddly. I now wish to draw some lines and circles onto which I wish to describe with reference to axis system. I have written some functions that will enable me to do this quite simply. They need information about my axis system, and I have chosen the variable WINDOW to hold it. WINDOW is a 2x2 matcix holding: 3 43p' XMIN | XMAX ------ teeccnn YMIN | YMAX XMIN | XMAX aaneae feerene YMIN | YMAX a fhe axes I have drawn correspond to: WINDOW~2 20720 20 1 5 15 a fo register this information I call the function SETTINGS which echoes the values in the size of PICTURE. SETTINGS WINDOW = ~20 20 pPICTURE = 1 5 15 a I am going to draw a solid circle centred on the origin (the point 0 0) which has diameter 28 and is black (intensity 1). ADDCIRCLE 0 0 28 1 PRINT 2 MAGNIFY AXES*#PICTURE
ADDCIRCLE ~5 § 8 O a White circle, intensity 0 PRINT 2 MAGNIFY AXES#PICTURE
a ADDLINE 1s a companion to ADDCIRCLE, having six components in its argument: x1 y1 x2 y2 thickness and intensity. ADDLINE 1 5 10 15 1 0 2 0.5 ADDLINE 0 20 0 ~20 3 0.25
85
VECTOR Vol.7 No.4
PRINT 2 a 2 circles overwritten by 2 lines i
a fhe last line was clipped by the window, Both ADDCIRCLE and ADDLINE clip automatically. a I am now going to look at the middle of PICTURE magnified so I can see the pixels clearly. PRIN® 10 MAGNIFY PICTURE(US+130;60+140]
a Phe intensities of the two lines are 0.5 and 0.25, corresponding to a half and a quarter of the pixels being black, I have 65 intensities available to me. The pattern for each ts described by the way the numbers 1 to 64 are distributed in the 8x8 array MASK: MASK 1339 9 44 3 35 44 43 49 17 87 25 51 19 59 27 13°45 5 37 15 47 7 39 61 29 53 24 63 31 55 293 4 36 42 4H 2 3h 40 42 52 20 60 28 50 18 58 26 16 48 6 40 145 46 6 38 64 32 56 28 62 30 54 22 a I am going to see what I can achieve by draving a strip across the page increasing uniformly in intensity from 0 to i. First I shall create a string of 901 intensities. INTENSITIES+(0,1900)+900 (S*tINTENSITIES) ,~5+INTENSITIES 0 0.001111 0.002222 0.003333 0.008444 0.9956 0.9967 0.9978 0.9989 1 a Convert them to integers ranging from 0 to 6h, INTENSITIES+|0.5+64xINTENSITIES
86
VECTOR Vol.7 No.4
(LOFINTENSTTIES) , 10+ INTENSITIES 9000000011 63 63 64 64 a My strip is going to be made up of 72x901 pixels. BIGMASK is going to be this size as well, got by repeating MASK both across and down, BIGMASK+72 90194901 8pQMASK PRINT 1,BIGMASKs72 S019 INTENSITIES
a Notice the loss of contrast at the dark end. Two problems are being demonstrated: isolated white pixels on a black ground are less extensive than isolated black pixels on a white ground, @ weakness of the printing process, but even if this were not so there remains the problem, or rather the fact, that eyes judge contrast to a different scale. The printer problem disappears with magnification, The penalty of magnification is sparsity of information: the same information takes up more space, Alternatively, intensities can be kept below 0.5 black pixels never run other. INTENSITIES*O.25%(0,1900}+900 (S#INTENSITIES) , StINTENSITIES 0 0,0002778 0.0005556 0.0008933 0.001111 0.2489 0.2497 0,25 INTENSITIES+|O.5+64xINTENSITIES (AO* INTENSITIES) ,~ 10+ INTENSITIES 000000000 0 16 16 PRINT 1,BIGMASKs72 901p INTENSITIES
a The pattern within MASK is rather beautiful and leads to a family of pixel patterns that blend other very harmoniously. A random array of integers between 1 and 64 in BIGMASK provides a less orderly but equally versatile pattern. BIGHMASK+?72 901p64 PRINT 1,BIGMASKs72 901pINTENSITIES
a Now I shall move to a higher level, a level above ADDCIRCLE and ADDLINE, to consider graphical objects described not as arrangements of pixels but by their geometrical and material structures, I to describe each object by 3 items: an identifier, a co-ordinate array and a component array. HEXAGON example of a graphical object.
87
VECTOR Vol.7 No.4
HEXAGON HEXAGON o 1 0 . 8 3 1 0 . 8 3 i a 6.25 6 . 2 5 1 2 . 5 6.25 6.25 12.5 0 oO 0 9 o 0 2 2 0.5 0.5 O. 1 a 5
a unpack HEXAGON and explain what it contains, ID COOR COMP+HEXAGON p "ID COOR COMP 56 6 6 a a scalar enclosing the string 'HEXAGON'. COOR and COMP are numeric arrays of size 5x6 and 6x6. I shall label their rows and columns: (1) 'x-coor! 'y-coor’ 'zZ~coor' 'h-coor (should be 1)' ''),(16) 4 X-coor 40,83 10.83 o 4 0 . 8 3 710.83 © y-coor 6.25 6 , 2 5 512.5 6 . 2 5 zZ-coor 9 fA-coor (should be 1} 1 4 41 1 4 4 1 1 (\type' '' 'thickness/dia.' i n t e n s i t y e n d 1! e n d 2'),COMP type 14 9 a oO thickness/dia. 2 intensity 0.5 0.5 0.5 0.5 end 4 4 4 5 6 end a Iwo rows are redundant and the h-coor row must always be filled out with 1s. Pype is 0 for circles and 1 for lines. The numbers in the rows marked ends 1 and 2 refer to the columns of COOR HEXAGON appears to be a hexagon having each of its sides 2.0 thick and dark grey (intensity = 0.5). The hexagon should nearly fill the current window, do not need to change WINDOW. draw HEXAGO using my function DRAW. PICTURE+120 16090 DRAW HEXAGON PRINT 2 MAGNIFY AXESVPICTURE
a I have a set of functions that take graphical objects as their arguments and return transformed graphical objects as their results. An important one is AND, which collects the components in each of the objects of its arguments and presents them as a single
88
VECTOR Vol.7 No.4
object. First I shall create another object, NODES, which 4.0 dia, circles centred on each of the vertices of the hexagon. IDece N O D E S ' COMP[1;]+0 COMP[3;] +4 COMPC4;)+0.25 NODES*«ID COOR COMP OBJECT+HEXAGON AND NODES to circles Set diameters Set intensities a Aa a a COOR is not changed
OBJECT(4) a Identifier NODES OBJECT(2] a Co-ordinates 10.43 10.83 0 0 10.83 10.83 0 0 6.25 6 . 2 5 1 2 . 5 ~6.25 6.25 12.5 6,25 6 . 2 5 6.25 12.& 0 0 0 0 1 1 1 a 1 1 1 a OBJECT(3} a Components a o4 a4 4 0 0 0 Oo 9 oO 2 2 & 0.5 0.5 0.5 0.25 0.25 38 4 10 4 § g 10 at 412 7 PICTURE+120 160p0 DRAW OBJECT PRINT 2 MAGNIFY PICTURE
4 TRANSLATE and ROTATE operate on graphical objects, RINGS*+OBJECT AND 5.41 0 4 PRANSLATE OBJECT PICTURE+120 16090 DRAW RINGS PRIN? 2 MAGNIFY AXESvVPICTURE
89
VECTOR Vol.7 No.4
a Note that it is the object that has been translated, not the axis system nor the window. The z translation of 4 has affected the Zz co-ordinates of RINGS but has no effect on what DRAW does. DRAW the x and y co-ordinates: it draws an orthogonal projection of the object onto the x-y plane. a Perspective projection performed using the function PROJECT which projects the co-ordinates of its right hand argument through the point STN onto the x-y plane at the origin. PROJECT returns a graphical object possessing not just the correct x,y co-ordinates but also the z co-ordinate of the middle of each component in the redundant row 2 of its component array. DRAW uses ' this row to order the elements before drawing them so that, provided STN has positive z, elements are drawn from the back of the scene towards the front. This permits hidden line removal, a Before advancing into 3-D, I want to add realism to my lines and circles to make them look like cylindrical rods and spheres. Function HIGHLIT will do this by providing a white reflection roughly in the middle and slightly in front of each component. DRAW PROJECT HIGHLIT RINGS PRINT 2 MAGNIFY PICTURE
a I a function HALO that puts a thicker white component just behind each component to blot out some background to help components stand out. PRINT PLAN Object
Station Font 4
zZ
90
VECTOR Vol.7 No.4
a PLAN Is a projection onto the 2-x plane and shows a typical arrangement for a perspective drawing object, in this case a box. The picture plane is always the x-y plane through the origin: the system cannot entertain any other arrangement. The station point STN located anywhere, but in this instance ig on the z-axis, The corners of the box are projected onto the picture plane by the four faint lines, PRINT PERSPECTIVE
Y
a PERSPECTIVE is a perspective of the perspective projection fayed out in PLAN, viewed from the isolated point in the bottom right hand corner of PLAN, There are now construction lines, and the window is shown surrounding the drawing. a Much of what I illustrate either includes mathematical curiosity or demands engineering precision, My APL graphics functions are my sophisticated tools, while my simple tools APL, which can help me both at a lower and at a higher level. PERSPECTIVE was drawn with the help of a little lower level manipulation, I shall draw a latticed deck using the power of high level data definition. WINDOW+2 29°75 20 7 . 5 7.5 PICTURE+300 500p0 SPN+7.5 DRAW PROJECT XYZ AND BOX AND CELL AND HIGHLI? CELL PRINT PICTURE
91
VECTOR Vol.7 No.4
a CELL, which contains 8 lattice two nodes, is a convenient for a latticed deck. BOX marks the boundary of the unit cell shows the axes. The components be distinguished rrom the the highlighting. 8 Before I replicate CELL I shall practise the replication on BOX. a top and bottom which is 10 units square. To replicate need to TRANSLATE it by multiples of 10 units in the x and 2 directions. In Dyalog APL \ is vell suited to helping me do this: 123 4 tit t£f12 443 i486 221i i122 423 424 234492 433 134
2414 242 2143 244 224 232 234 pi2 3 4 234 a So ,(10x"i+16 16) will give me 36 translations appropriate to a 6*6 deck. Applying these to BOX: STIN+STNXE a Stand back 6 times further WINDOW+2 29°15 80 ~30 10 PICTURE+400 950p0 DRAW PROJECT XYZ AND >AND/,(10x71+16 1 6)PRANSLATE cBOX
& Repeating this replication on CELL and calling the result OB: OB+2AND/,(10x714+16 1 6) PRANSLATE cCELL a Translate the deck towards the origin, rotate it 0.25 radians about the y axis, and translate it back again: OB+35 0 35 TRANSLATE 0 0.25 0 ROTATE ~30 0 ~35 TRANSLATE OB STN+32 2 100 WINDOW+2 2p10 50 7 18 PICTURE+300 480p0 DRAW PROJECT (HIGHLIT OB) AND OB PRINT PICTURE
92
VECTOR Vol.7 No.4
a Phis is a close-up of the latticed deck. Much of the structure has been clipped by WINDOW. a Phe last facility to demonstrate is HAZE. HAZE 18 2 two row matrix containing z-values in its top row and intensity factors in its bottom row. Currently HAZE has just one column: HAZE ~100 1 a All intensities of components having z~values greater than 1 0 0 had their intensities multiplied by 1. If I HAZE as: HAZE+2 20p(720+4%120) ,0.8%$0,119 2 7 t H A Z E 36 4O ak 5é 60 0.2622 06.512 0.64 0.8 4 PICTURE+300 480p0 DRAW PROJECT (HIGHLIT OB) AND OB PRINT PICTURE
a Now components further back, with smailer z-values, have had their intensities reduced more, giving an attractive haziness to the picture. a All the funtions that have been used in this demonstration are listed below. They have been run under Dyalog APL Version 6.0 on @ 33 MHz 386 & Mb of memory, The original was printed on A paper by a Kyocera P-2000 PostScript laser printer, with graphics mode set £o 150 dots per inch. )OFF
93
VECTOR Vol.7 No.4
ADDCIRCLE CIRCLE; CENTRE; RADIUS; INTENSITY ; SIGN; QCT a ADDS A CIRCLE TO THE PICTURE CENTRE+CIRCLE{L1 2] © RADIUS INTENSITY+0.5 1xCIRCLE(3 4) aCALCULATE THE PANE FRAMING THE CIRCLE PANE+( CENTRE-~RADIUS) , [4.5] CENTRE+RADIUS SINTERSECT IT WITH APERTURE UcT+18 12 © PANE+((APERTURE[ PANE) ,APERTURE|PANE)(C:1 4) +(741 Tigx-/PANE)/0 aNO INTERSECTION PANE*SIGNX((SIGN+2 201 1 1 1)*PFX+.xi;PANE aAPIXEL LIMITS *(v/O>2 ~1*-/PANE) /0 aNO INTERSECTION a EIST OF PIXEL INDICES PANE*, (PANE(1;21+0,1-/PANE(1;]}°., PANE(2;1]+0,1--/PANEL2;] a LISP OF PIXELS WHOSE CENTRES ARE INSIDE THE CIRCLE PAWNE+(RADIUS2 (+4 ((XFP+. 178+ PANE) ~&( (pPANE) ,2)pCENTRE)*2)*0.5}/PANE >(O=pPANE)/0 a IF NONE, EXI? a IS INTENSITY 0 OR 1? +(~v/0 1=INTENSITY)/GREY © PICTURE(PANE]+INTENSITY © +0 GREY: a WHICH PIXELS BLACK+MASK[1+(cpMASK) | PANE] sl0.5+INTENSITY xx /QMASK PICTURE[BLACK/PANE]+1 9 PICTURE((~BLACK}/PANE] +0
ADDLINE LINE; OTRAP;A;AB;AP;AT;APTR;B;BLK;C;D;D1;EDGHES;I;IND;INTEN,.. | OPRAP+c3 'E' '+TRAP' M,N; PFT;S a ADDS A LINE [0 THE PICTURE AB+R2 2p4tLINE o D INTEN+”2+LINE © D++XFP(1;3] a D IN PIXEL UNITS a PRANSFORM TO P,Q HOMOGENEOUS COORDINATES AB+(PFX+.*1;AB)>1 6 APPR+(PFX+.*15APERTURE) +1 & CALCULATE TRANSFORMATION MATRICES PFT AND TFP AP+AB,(AB[1 2;1]+41 ~1x6-/ABL41 233),4 @P,Q@ COORDS OF A,B,C ATQ3 390 O41 6 ATC(L 2)(2 B)]+E+(+/(-/AB(1 2:3)*2)*0.5 a,N COORDS TFP+QPFI+AP+.xBAT a CALCULATE P COORDS OF I/SECN OF EACH LINE EDGE WITH EACH SIDE OF APTR APIR+APTR,GAPTR 9 APPR(2;]+APTR(2;1 1 2 2] © APTR+vRTFP+, xAPTR EDGES++&3 UpO O,E,L,(72 i x D e 2 ) , 1 244 P+(EDGES CROSS“1¢EDGES)(2 4J]°.CROSS APTR CROSS”1¢APTR PHC+P)Css4 3] © T03;23+02 TL;;2] AOPPSET ZEROS IN 2ND COL. P+y 2ps/P 9 T+TsCS To AB+(E£/0, L/P), L/L, 047 >(0s-/AB)/0 a NO INTERSECTION a SEP UP SATURATION BOMBING GRID SC+l2pPFT o Att4/SC 0 Di«(+A)-Axx/SC o N+1[1+[(D-D1)+A Be(D-Di}t1[W-1 © Le|+/AB 0 Meit[LtA 0 A+LeMn4 IND+(M,N,3)p1 © IND[;;1)+8(4,M)pAx0,1M-4 © INDO; ;2]+(M,¥)pBx0, W-4 INDC;;4]++1+AB © IND(;;2)-+0.5xBxN-41 0 IND+§( (MXN) ,3)oIND >(N>4)/GOON © IND+((D+D1)>0.001*MORND+MORND) /IND GOON: I++(4) 74 OFIND<L0.5+PFT+.xIND © +CONT FRAP: aREMOVE PHOSE OUTSIDE THE WINDOW C+(INDC1;]>0)A(IND[1;]s4+pPICPURE) A(IND(2;J>0)sIND(2:}s71+p PICTURE T+#¥01]74 O+G/IND CONT:>+(O=pI)/0 a NO PIXELS, EXIT a IS INTENSITY 0 OR 1? +(~v/0 1=INTEN)/GREY © PICTURE[I]*INTEN 0 +0
94
VECTOR Vol.7 No.4
GREY: a WHICH PIXELS ARE BLACK? BLK+MASK(1+(cpMASK) |I]sL0.5+INTENx*/pMASK PICTURE(BLK/I]+1 9 PICTURE((~BLX)/I]+0 R+A AND B; COMP aR IS AN OBJECT WHICH CONTAINS THE COMPONENTS OF BOTH A AND B ACi}]<c(+! ',424[2]),ctAND! © BEi]*cy! ', +2804) COMP+2BE3] © COMP[5 6;]+* itp>4[2] © BL3]+cCOMP R+A,"B
ReA AND B; COMP aR IS AN OBJECT WHICH CONTAINS THE COMPONENTS OF BOTH A AND B ACij+c(+? ',t2AC1]),¢'AND' © Bli}tet? ',+2BC1) COMP+>B[3] © COMP[S 6;]++ 1tp>A[2] 0 BL3]+cCOMP Rea, "B
R+BLOCK TEXT Re(1i6,8*%p,FEXT)p2 1 38IMAGECCHAR\, TEXT; 3]
R+A CROSS B a CALCULATES THE CROSS PRODUCT OF A AND B Re((1bA)*7 1B) - (716A) x18
Rees B a RETURNS R AS B EXCEPT FOR V, LARGE NOS, WHOSE SIGNS ARE REVERSED B+,R«B o B((1B12<|B)/ipB]x«<"1 © R+(pR)pB
DRAW OBJECT; ID; COOR; COMP; C;I:N;ORDER;P:Q a DRAWS AN X-Y PLANE PROJECTION ONTO THE BOOLEAN PICTURE MATRIX a If IS A COVER FUNCTION FOR ADDCIRCLE AND ADDLINE SETTINGS ID COOR COMP+OBJECT 6 [I+((pID),1)pID ORDER+ACOMP(2;] o I«4 LOOP: a PROCESS NEX? COMPONENT N+ORDER(I] 9 C+COMPE;N] 9 P++4COOR(2 2p1 4;CL5]] +CLLI$CIRCLE, LINE CIRCLE: ADDCIRCLE P,Cla 4%] © +CONT LIWE:Q++/COOR[2 291 4;¢[6]] ADDLINE P,@,¢[3 4] CONT: M+1tC[1]$'CL' 9 +((pORDER)2I+I+1)/LOOP a+:
R+HIGHLIT OBJECT; ID; F,1I;CCOOR; CCOMP; LCOOR; LCOMP a PRODUCES THE HIGHLIGHTS FOR OBJECT Fe3 a FACTOR DIA OF OBJECT + DIA OF HIGHLIGHT ID COOR COMP+OBJECT ID+ID,c'HIGHLIGHTED' a CIRCLES I+(0=COMP{[1;])/1~1+pCOMP CCOMP+COMP(;I] © CCOMP(3;]++F © CCOMP[4;]+0 © CCOMPE5;]+1ipl CCOOR+COOR[T; COMP(5; I) CCOORT13;J++(3,pF)p(+4x3*0.5)xCCOORL4; JxCOMP(3; I]
95
VECTOR Vol.7 No.4
a LINES I+(1=COMP[1:])/1.7 1+ COMP ECOMP+COMP(;I] © LCOMP[3;]++F 9 LCOMP[4;]+0 ECOMP(S 6;]+8( (pT), 2)p(~1tpCCOOR)+12xpI ECOOR+COORL; ,8COMP[S 6;I]] ECOORTA3;]+"(3,2™oT)p(+4%3«0.5)xLCOOR(4;]*, RCOMPLA 3;I) a PACKAGE THE RESULT RID(CCOOR,LCOOR) ( CCOMP, LCOMP)
R+F MAGNIFY A a MAGNIFIES THE BOOLEAN MATRIX A BY AN INTEGER FACTOR F R+(FxpA)p2 4 1 38(F,F,pA)pA
R+MOD A Re (+ /Ax2)#0.5
ROZ B a RETURNS R AS B EXCEPT FOR ITS ZEROS, WHICH GO BACK VERY SMALL B+, RB o BC(1E™12>|B)/ipB]+ik 12 0 R+(pR)pB
R«PROJECT OBJECT; ID; COOR; COMP; C;E:M;I a PROJECTS THROUGH A STATION POINT, STN,ONTO THE X-Y PLANE ID COOR COMP+OBJECT © ID+ID,c'PROJECTED THROUGH ',¥STN COORTS;]++#4COORLS 4;) a CALC, DISTANCES A CALCULATE TRANSFORMATION MATRIX M1290 o MCi 3.6 7 14 123+(S7NV,1)(3 13 2 u 3} Me3 GoM © M[;3]x+74 COORTL 2 4;]+M+.*COOR[14;] © PRANSFORM COOR a DISTANCES C+(0=COMP(1;])/I+1~14+pCOMP 0 L+(1=COMP[i:1)/I COMP(2;C]+COOR[S ; COMP[5;C]] a CIRCLES COMP(2;L]+0.5x+#COOR(S;COMP[S 6;L}]] a LINES a MODIFY PHICKNESSES COMP(3;]*+SFN(3]+S7N(3]-COMP[2;] a MODIFY INTENSITIES COMP(U;]x+(4,HAZE)(2;1+4+/COMP[2;]°.>HAZE(1;]] a PACKAGE THE RESULT R+ID COOR COMP
R«THETA ROTATE OBJECT; ID;COOR; COMP; S;T;MODT a ROTATES AN OBJECT THROUGH THE PSEUDOVEGTOR THETA S+3 3997 6 23974547 S+(PHETA, (-THETA),0)(S] a AUXILIARY MATRIX MODI*MOD THETA f+(3 3p41 0 0 0)+((10MODT)+MOD?) xs T++0.5*(( (100, 5xMODP)+0.5xMODT)*2)*S+.xS a PRANSFN MATRIX ID COOR COMP<+OBJECT ID+ID,c'ROPATED BY ',¥THETA COORT13;]++COOR[3p4;) COOR(. 3; J++. xCOOR[13;4 R+ID GOOR COMP
96
VECTOR Vol.7 No.4
Re SETTINGS ;M;N;X1;X2;Y1;¥2 a CHECK WINDOW: X2>X1 AND Y2>Y¥1 WINDOW+(L/WINDOW), (1.5) [/WINDOW a SHOW SETTINGS RetHINDOW ='(¥WINDOW) Rit! OPICTURE ='(¥pPICTURE) A CALCULATE TRANSFORMATION MATRICES XFP AND PFX X1 X2 Y1 ¥2+,WINDOW © M N+pPICTURE XFP+2 390 XPP(1;4 3)+70.5 1*(X2-X1)4N XFP(2;1 230.5 1 * ( Y 2 - Y 1 ) + M XFPC;1]++X1,¥2 PFX+"2 3tH1 0 0;XFP @ CALCULATE APERTURE APERTURE+HINDOW+(2 2p1 ~1)x&2 2p0.5%((X2-X1)+N), (Y2-Y1)4M
R+D TRANSLATE OBJECT; ID; COOR; COMP @ TRANSLATES THE OBJECT 3 COMPONENTS OF D ID COOR COMP+OBJECT ID+ID,c' TRANSLATED BY ',¥D COORE1 3; 1++GOORL3p4; J x&((“1+pCOOR),3)pD R+ID COOR COMP
Phe PRINT function files its output which may be flushed to the Printer by KYOFLUSH.
{F}PRIN? A;CMD;SIZE;X;¥;050 a FUNCTION TO PRINT TO KYOCERA P-2000 PRINTER a IF A IS A MATRIX, IT IS TREATED AS BOOLEAN, AND PRINTED AT 300+F DPI a 0 AND 1 REPRESENT WHITE AND BLACK O©FO IS LOCAL AND SET TO ZERO Qro+o 2(0=DNC'prt!)/'KYOINITt a INITIALISE PRINTER 2(Ae!')/'pre OFME'' PF! osEXIT! 8 FORM FEED IF A IS EMPTY +(2=ppA)/BOOM o A*+POST_esc"¢DFMT2A a ESCAPE SPECIAL CHARACTERS A(ctNL ('),"A,"c!') show! a WL FOLLOWED BY IN PARENTHESES pree“OFMT"A o +EXI? BOOM: #(0=QNC'F')}/'Fe2' a SEP DEFAULT VALUE OF F AS 2 AtI2H A A PRANSFORM BOOLEAN TO HEX GCHAR MATRIX prt(1,pCMD)pCMD+'/bitmap <',(,4),'> def! a DEFINE bitmap X Yeh 1xdpA a DIMS OF bitmap CMD+c'gsave! a BEGIN SCRIPT CMD,+c'/DEPTH ',(¥FxY),' 900 div INCH PITCH add def' CMD,+c'VPOS DEPTH sub BM it { FF } if? CMD,+<'/VPOS VPOS DEPTH sub def? CMD,+c'LM VPOS transiate' CMD, +c(¥X F),' mul 300 div INCH! CMD,«c(¥Y F),' mul 300 div INCH scale’ CHD,«c(*X Y),' 4 [',(¥X,0 0 4 0 1xY),'] {bitmap} image’ CMD,+c'grestore' CMD, +c'NL' SIZE+pCMD++CMD © CMD+,CMD CMD((CMD='~')/1pCMD]+'-'
97
VECTOR VolL7 No.4
pre SIZESCMD EXIT: +0
XYOINIT; X; 7M;LM; BM; PGHEIGH? ; PITCH; FONTSIZE 8 INITIALISES KYOCERA P-2000 PRINTER 'pre‘Qsé'prt! prtacgs'postscript' '' ' A P L P O S T . PRN: TM+1.4 a fop margin (in.) DM+L a Left margin (in.) BM+1i A Bottom margin Cin.) PGHEIGHT+11.65 a Page height (in) PIPCH+13 a Pitch in points (41/72 in.} PONTSIZE+14 Xec'/INCH {72 mul} der! X,+a'/TM +, (47M),' INCH det! X,+c'/EM ',(vLM),' INCH def! X,+c'/BM ',(¥BM),' INCH dert X,+e'/PGHEIGHT ',(¥PGHEIGHT),' INCH der! X,+e'/PITCH ',(vPITCA),' dert X,+e'/TOF { /VPOS PGHEIGH? TM sub der IM VPOS moveto} def X,+c' /PF { showpage TOF } deft X,+c'/NL { /VPOS VPOS PITCH sub def A 2 LINE DEFN X,+c'VPOS BM gt {LM VPOS moveto} { FF } ifelse } def! X,+c'/APL-2741 findfont ' (¥PONTSIZE),' scalefont setfontt X,+c' OP! prerx
KYOFLUSE 8 Flush information to printer prt i 2p'FF prtofft 0 OsDSH' copy o:\dyalog\ fonts\ap12741.fnt+aplpost .pra ipta
ReIi2H B; SHH; SHR A Return boolean as hex array, 1 bit per sample. 8 NB, <FF> is white in PostScript!! B+O=((1teB),8xfO.225%714pB)4B 0 SHR+(pB)+4 4 2(0=QNC'hex')/'**xutdist? OSH tris A Invoke xutils ap if no hex SHH+((1+pR+36+hex B)+9),9 © ReSHRp(SHH-0 1)+SHHOR
R+POST_esc R & Set each row of text for Printing (CREMCV\')/R) FS erye A Escape all of '(', ")t, "\t) witn "\ Rea, /R 4 Return simple vector
Lower-case functions such as pre and hex come with Dyalog APL, ADDLINE requires a global variable RND. Execute RND+?100p1000 before first calling ADDLINE,
Por the years I have been sponsored by the Venture Research Unit International Ltd, to whom I am most grateful. I to thank the authors of Dyalog APL and many friends within the APL community for their support and encouragement.
98
VECTOR Vol.7 No.4
This section of VECTOR is oriented towards readers who may neither know APL, nor be interested in learning it. However we hope you are curious about how, under the right conditions, such impressive results can emerge so quickly from APL programmers