home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / e / amiga_e / src / pd / lines.e < prev    next >
Text File  |  1992-09-02  |  3KB  |  151 lines

  1. /* Lines demo in E by EA van Breemen */
  2. /* v1.0 ©1994                        */
  3.  
  4. /* This is a small example of the graphics in E               */
  5. /* Sorry for the low standard of commenting                   */
  6. /* So little time and so much to program (in E of course 8-)) */
  7.  
  8.  
  9. CONST MAX_X=600
  10. CONST MAX_Y=225
  11. CONST MIN_X=25
  12. CONST MIN_Y=25
  13.  
  14. CONST MAX=15
  15. CONST MAXCOL=16
  16. CONST BITPLANES=4
  17.  
  18. ENUM NO_ERROR,NO_SCREEN,NO_WINDOW
  19.  
  20. PROC main() HANDLE
  21.  DEF window=NIL,screen=NIL
  22.  DEF x1,y1,x2,y2
  23.  DEF vx1,vy1,vx2,vy2
  24.  DEF col,i
  25.  DEF cx1[MAX]:ARRAY OF LONG
  26.  DEF cx2[MAX]:ARRAY OF LONG
  27.  DEF cy1[MAX]:ARRAY OF LONG
  28.  DEF cy2[MAX]:ARRAY OF LONG
  29.  DEF collist[MAX]:ARRAY OF LONG
  30.  
  31.  DEF r=0, g=0, b=0
  32.  DEF sr=1,sg=1,sb=1
  33.  
  34.  DEF q,switch
  35.  DEF viewport
  36.  
  37.  screen  :=  OpenS(640,256,BITPLANES,$8000,'Lines demo in E')
  38.  IF screen=NIL THEN Raise(NO_SCREEN)
  39.  window:=OpenW(0,0,640,256,0,$1800,0, screen,15,0)
  40.  IF window=NIL THEN Raise(NO_WINDOW)
  41.  viewport := ViewPortAddress(window)
  42.  col:=0
  43.  FOR i:=1 TO MAXCOL-1 STEP 1
  44.   col:=col+1
  45.   IF col=MAXCOL THEN col:=0
  46.   SetRGB4(viewport,i,col,15,15-col)
  47.  ENDFOR
  48.  SetDrMd(stdrast,2)
  49.  x1:=30; y1:=30; x2:=100; y2:=100
  50.  
  51.  vx1:=2; vy1:=3; vx2:=-3; vy2:=-1
  52.  col:=1; q:=1; switch:=1
  53.  
  54.  FOR i:=0 TO MAX-1 STEP 1
  55.   cx1[i]:=0
  56.  ENDFOR
  57.  
  58.  WHILE Mouse()<>1
  59.  IF cx1[q]<>0
  60.     Colour(collist[q],0)
  61.     PutChar(stdrast+24,collist[q])
  62.  
  63.     Move (stdrast,cx1[q],cy1[q])
  64.     Draw (stdrast,cx2[q],cy2[q])
  65.  
  66.     Move (stdrast,MAX_X-cx1[q],MAX_Y-cy1[q])
  67.     Draw (stdrast,MAX_X-cx2[q],MAX_Y-cy2[q])
  68.  
  69.     Move (stdrast,cx1[q],MAX_Y-cy1[q])
  70.     Draw (stdrast,cx2[q],MAX_Y-cy2[q])
  71.  
  72.     Move (stdrast,MAX_X-cx1[q],cy1[q])
  73.     Draw (stdrast,MAX_X-cx2[q],cy2[q])
  74.  ENDIF
  75.  
  76.  x1:=x1+vx1
  77.  y1:=y1+vy1
  78.  y2:=y2+vy2
  79.  x2:=x2+vx2
  80.  
  81.  IF ((x1<MIN_X) OR (x1>MAX_X)) THEN vx1:=-vx1
  82.  IF ((y1<MIN_Y) OR (y1>MAX_Y)) THEN vy1:=-vy1
  83.  IF ((x2<MIN_X) OR (x2>MAX_X)) THEN vx2:=-vx2
  84.  IF ((y2<MIN_Y) OR (y2>MAX_Y)) THEN vy2:=-vy2
  85.  
  86.  Colour(col,0)
  87.  PutChar(stdrast+24,col)
  88.  SetRGB4(viewport,col,r,g,b)
  89.  IF q AND $8
  90.   r:=r+sr
  91.   IF r>14 THEN sr:=-1
  92.   IF r<1  THEN sr:=1
  93.   IF r AND 8
  94.     g:=g+sg
  95.     IF g>14 THEN sg:=-1
  96.     IF g<1  THEN sg:=1
  97.   ENDIF
  98.   IF r AND 10
  99.     b:=b+sb
  100.     IF b>14 THEN sb:=-1
  101.     IF b<1  THEN sb:=1
  102.   ENDIF
  103.   IF Rnd(100) > 95
  104.     r:=(r+Rnd(3)) AND $f
  105.     g:=(g+Rnd(3)) AND $f
  106.     b:=(b+Rnd(3)) AND $f
  107.   ENDIF 
  108.  ENDIF
  109.  
  110.  Move (stdrast,x1,y1)
  111.  Draw (stdrast,x2,y2) 
  112.  
  113.  Move (stdrast,MAX_X-x1,MAX_Y-y1)
  114.  Draw (stdrast,MAX_X-x2,MAX_Y-y2)
  115.  
  116.  Move (stdrast,x1,MAX_Y-y1)
  117.  Draw (stdrast,x2,MAX_Y-y2)
  118.  
  119.  Move (stdrast,MAX_X-x1,y1)
  120.  Draw (stdrast,MAX_X-x2,y2)
  121.  
  122.  cx1[q]:=x1
  123.  cy1[q]:=y1
  124.  cx2[q]:=x2
  125.  cy2[q]:=y2
  126.  collist[q]:=col
  127.  q:=q+1
  128.  IF q=MAX 
  129.   q:=0
  130.   switch:=-switch
  131.  ENDIF
  132.  col:=col+1
  133.  IF col=MAXCOL THEN col:=1
  134.  ENDWHILE
  135.  Raise(NO_ERROR)
  136.  
  137. EXCEPT
  138.  IF window THEN CloseW(window)
  139.  IF screen THEN CloseS(screen)
  140. SELECT exception
  141.  CASE NO_ERROR
  142.   /* Do nothing */
  143.  CASE NO_SCREEN
  144.   WriteF('Cannot open screen\n')
  145.  CASE NO_WINDOW
  146.   WriteF('Cannot open window\n')
  147.  DEFAULT
  148.   WriteF('Unknown exception:\d\n',exception)
  149. ENDSELECT  
  150. ENDPROC
  151.