Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 a shape class so you dont have to keep typing in the shape
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kit-kat-kid




PostPosted: Wed May 05, 2004 5:36 pm   Post subject: a shape class so you dont have to keep typing in the shape

code:
%File "ShapeCl"the Shape Class
unit
class ShapeCl
    export Circle, Ball, Square, Block, TiltSquare, Moon, Star,
        MapleLeaf
    proc Circle (xc, yc, radius, clr : int)
        Draw.Oval (xc, yc, radius, radius, clr)
    end Circle
    proc Ball (xc, yc, radius, clr : int)
        Draw.FillOval (xc, yc, radius, radius, clr)
    end Ball
    proc Square (x, y, size, clr : int)
        Draw.Box (x, y, size, size, clr)
    end Square
    proc Block (x,y, size, clr: int)
    Draw.FillBox (x, y, size,size,  clr)
    end Block
    proc TiltSquare (x1, y1, size, angle, clr : int)

        %compute 4 constants for the corners:
        const a := round (size * cosd (angle))
        const b := round (size * sind (angle))
        const c := round (size * sqrt (2) * cosd (45 + angle))
        const d := round (size * sqrt (2) * sind (45 + angle))
        %compute corners
        const x2 := x1 + a
        const y2 := y1 + b
        const x3 := x1 + c
        const y3 := y1 + d
        const x4 := x1 - b
        const y4 := y1 + a
        %draw the square
        Draw.Line (x1, y1, x2, y2, clr)
        Draw.Line (x2, y2, x3, y3, clr)
        Draw.Line (x3, y3, x4, y4, clr)
        Draw.Line (x4, y4, x1, y1, clr)
    end TiltSquare
    proc Moon (xc, yc, size, clr : int)
        for angle : 0 .. 360 by 10
            TiltSquare (xc, yc, size, angle, clr)
        end for
    end Moon
    proc Star (x1, y1, x2, y2, clr : int)
        Draw.FillStar (x1, y1, x2, y2, clr)
    end Star
    proc MapleLeaf (x1, y1, x2, y2, clr : int)
        Draw.FillMapleLeaf (x1, y1, x2, y2, clr)
    end MapleLeaf
end ShapeCl


Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: