home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / COMAL3-1.DMS / in.adf / Demos / Figures < prev    next >
Encoding:
Text File  |  1993-03-30  |  1.9 KB  |  110 lines

  1. // This program is almost classic in demonstrating the
  2. // idea in objects, methods and virtual methods.
  3. //
  4. // Geometric figures have some common properties such as
  5. // position, color and some operations that can be done
  6. // are common (all figures can have its position changed).
  7. //
  8. // Common properties are inherited from base figures.
  9. // Note that the Draw method in the basic figure Point
  10. // is made virtual.
  11.  
  12. USE Graphics
  13. USE Figure
  14.  
  15. graphicscreen(0)
  16.  
  17. DIM Circle1 OF Circle
  18. DIM Circle2 OF Circle
  19. DIM Square OF Rectangle
  20.  
  21. Circle1.Init(100,160,1,35)
  22. Circle2.Init(100,95,2,15)
  23. Square.Init(80,40,3,20,40)
  24. t$:=INKEY$(2)
  25. LOOP 50 TIMES
  26.   Circle1.Move(400/50,0)
  27.   Circle2.Move(400/50,0)
  28.   Square.Move(400/50,0)
  29. ENDLOOP
  30. t$:=INKEY$(5)
  31. clear
  32. textscreen
  33.  
  34. STRUC Circle
  35.   INHERIT Point
  36.  
  37.   USE Graphics
  38.  
  39.   DIM Radius OF FLOAT
  40.  
  41.   PROC Init(x,y,Color OF BYTE,R)
  42.     Point.Init(x,y,Color)
  43.     Radius:=R
  44.     Draw
  45.   ENDPROC Init
  46.  
  47.   PROC Draw
  48.     circle(PosX,PosY,Radius)
  49.   ENDPROC Draw
  50.  
  51. ENDSTRUC Circle
  52.  
  53. STRUC Rectangle
  54.   INHERIT Point
  55.  
  56.   USE Graphics
  57.  
  58.   DIM Height OF FLOAT, Width OF FLOAT
  59.  
  60.   PROC Init(x,y,Color OF BYTE,h,w)
  61.     Point.Init(x,y,Color)
  62.     Height:=h
  63.     Width:=w
  64.     Draw
  65.   ENDPROC Init
  66.  
  67.   PROC Draw
  68.     draw(Width,0)
  69.     draw(0,Height)
  70.     draw(-Width,0)
  71.     draw(0,-Height)
  72.   ENDPROC Draw
  73.  
  74. ENDSTRUC Rectangle
  75.  
  76. MODULE Figure
  77.  
  78.   STRUC Point
  79.     USE Graphics
  80.  
  81.     DIM PosX OF FLOAT, PosY OF FLOAT
  82.     DIM FigureColor OF BYTE
  83.  
  84.     PROC Init(x,y,Color OF BYTE)
  85.       PosX:=x
  86.       PosY:=y
  87.       FigureColor:=Color
  88.       pencolor(FigureColor)
  89.       moveto(x,y)
  90.     ENDPROC Init
  91.  
  92.     PROC Move(dx,dy)
  93.       pencolor(0)
  94.       moveto(PosX,PosY)
  95.       Draw
  96.       pencolor(FigureColor)
  97.       PosX:+dx
  98.       PosY:+dy
  99.       moveto(PosX,PosY)
  100.       Draw
  101.     ENDPROC Move
  102.  
  103.     PROC Draw VIRTUAL   // Virtual method
  104.       plot(PosX,PosY)   // Defines the form of the figure
  105.     ENDPROC Draw
  106.  
  107.   ENDSTRUC Point
  108.  
  109. ENDMODULE Figure
  110.