home *** CD-ROM | disk | FTP | other *** search
- // This program is almost classic in demonstrating the
- // idea in objects, methods and virtual methods.
- //
- // Geometric figures have some common properties such as
- // position, color and some operations that can be done
- // are common (all figures can have its position changed).
- //
- // Common properties are inherited from base figures.
- // Note that the Draw method in the basic figure Point
- // is made virtual.
-
- USE Graphics
- USE Figure
-
- graphicscreen(0)
-
- DIM Circle1 OF Circle
- DIM Circle2 OF Circle
- DIM Square OF Rectangle
-
- Circle1.Init(100,160,1,35)
- Circle2.Init(100,95,2,15)
- Square.Init(80,40,3,20,40)
- t$:=INKEY$(2)
- LOOP 50 TIMES
- Circle1.Move(400/50,0)
- Circle2.Move(400/50,0)
- Square.Move(400/50,0)
- ENDLOOP
- t$:=INKEY$(5)
- clear
- textscreen
-
- STRUC Circle
- INHERIT Point
-
- USE Graphics
-
- DIM Radius OF FLOAT
-
- PROC Init(x,y,Color OF BYTE,R)
- Point.Init(x,y,Color)
- Radius:=R
- Draw
- ENDPROC Init
-
- PROC Draw
- circle(PosX,PosY,Radius)
- ENDPROC Draw
-
- ENDSTRUC Circle
-
- STRUC Rectangle
- INHERIT Point
-
- USE Graphics
-
- DIM Height OF FLOAT, Width OF FLOAT
-
- PROC Init(x,y,Color OF BYTE,h,w)
- Point.Init(x,y,Color)
- Height:=h
- Width:=w
- Draw
- ENDPROC Init
-
- PROC Draw
- draw(Width,0)
- draw(0,Height)
- draw(-Width,0)
- draw(0,-Height)
- ENDPROC Draw
-
- ENDSTRUC Rectangle
-
- MODULE Figure
-
- STRUC Point
- USE Graphics
-
- DIM PosX OF FLOAT, PosY OF FLOAT
- DIM FigureColor OF BYTE
-
- PROC Init(x,y,Color OF BYTE)
- PosX:=x
- PosY:=y
- FigureColor:=Color
- pencolor(FigureColor)
- moveto(x,y)
- ENDPROC Init
-
- PROC Move(dx,dy)
- pencolor(0)
- moveto(PosX,PosY)
- Draw
- pencolor(FigureColor)
- PosX:+dx
- PosY:+dy
- moveto(PosX,PosY)
- Draw
- ENDPROC Move
-
- PROC Draw VIRTUAL // Virtual method
- plot(PosX,PosY) // Defines the form of the figure
- ENDPROC Draw
-
- ENDSTRUC Point
-
- ENDMODULE Figure
-