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

Username:   Password: 
 RegisterRegister   
 Useful module for drawing shapes (and a canada flag!)
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hendo




PostPosted: Thu Jun 21, 2007 9:24 am   Post subject: Useful module for drawing shapes (and a canada flag!)

Was bored, so I decided to write this. Allows fill and non fill versions of perfect square,perfect circle, isoceles triangle, equilateral triangle, right angle triangle, scalene triangle and canada flag. I hope no one has already posted on of these...anyway hope it's useful for someone! Tell me what you think!

code:
%Collin Henderson
%Shape Module
unit
module Shape
    %list of all the procedures
    export circle, fillcircle, square, fillsquare, isotriangle, fillisotriangle, eqtriangle, filleqtriangle, ratriangle, fillratriangle, triangle, canadaflag
    %circle procedure
    procedure circle (x, y, radius, col : int)
        Draw.Oval (x, y, radius, radius, col)
    end circle
    procedure fillcircle (x, y, radius, col : int)
        Draw.FillOval (x, y, radius, radius, col)
    end fillcircle
    %square procedure
    procedure square (x, y, size, col : int)
        % creating variables for the opposite corners
        var x2, y2 : int
        % Calculating the value of the opposite corner
        x2 := x + size
        y2 := y + size
        %Drawing the square
        Draw.Box (x, y, x2, y2, col)
    end square
    procedure fillsquare (x, y, size, col : int)
        % creating variables for the opposite corners
        var x2, y2 : int
        % Calculating the value of the opposite corner
        x2 := x + size
        y2 := y + size
        %Drawing the square
        Draw.FillBox (x, y, x2, y2, col)
    end fillsquare
    % Equilateral Triangle procedure
    procedure eqtriangle (x, y, size, col : int)
        %co-rds
        var x2, y2, x3, y3 : int
        %makes the second point
        x2 := x + size
        %middle of the base
        x3 := x + (size div 2)
        %these will be the same
        y2 := y
        %set the top point
        y3 := round (sqrt (size ** 2 - (size / 2) ** 2) + y)
        %draw the lines
        Draw.Line (x, y, x2, y2, col)
        Draw.Line (x2, y2, x3, y3, col)
        Draw.Line (x, y, x3, y3, col)
    end eqtriangle
    %filled eq triangle
    procedure filleqtriangle (x, y, size, col : int)
        var x2, y2, x3, y3 : int
        x2 := x + size
        x3 := x + (size div 2)
        y2 := y
        y3 := round (sqrt (size ** 2 - (size / 2) ** 2) + y)
        Draw.Line (x, y, x2, y2, col)
        Draw.Line (x2, y2, x3, y3, col)
        Draw.Line (x, y, x3, y3, col)
        %centroids
        var cx, cy : int
        cx := (x + x2 + x3) div 3
        cy := (y + y2 + y3) div 3
        %fill it
        Draw.Fill (cx, cy, col, col)
    end filleqtriangle


    % procedure for isoceles triangle
    procedure isotriangle (x, y, base, height, col : int)
        var x2, y2, x3, y3 : int
        %get the other x coordinate
        x2 := x + base
        %y2 and y will be the same because they are both at the same level as the base
        y2 := y
        %finds the middle of the triangle
        x3 := (x + x2) div 2
        %the top of the triangle
        y3 := x3 + height
        %draw line 1
        Draw.Line (x, y, x2, y2, col)
        %draw line 2
        Draw.Line (x, y, x3, y3, col)
        %draw line 3
        Draw.Line (x2, y2, x3, y3, col)
    end isotriangle
    %filled iso triangle
    procedure fillisotriangle (x, y, base, height, col : int)
        var x2, y2, x3, y3 : int
        %get the other x coordinate
        x2 := x + base
        %y2 and y will be the same because they are both at the same level as the base
        y2 := y
        %finds the middle of the triangle
        x3 := (x + x2) div 2
        %the top of the triangle
        y3 := x3 + height
        %draw line 1
        Draw.Line (x, y, x2, y2, col)
        %draw line 2
        Draw.Line (x, y, x3, y3, col)
        %draw line 3
        Draw.Line (x2, y2, x3, y3, col)
        %fill it
        var cx, cy : int
        %variables that get the centroid
        cx := (x + x2 + x3) div 3
        cy := (y + y2 + y3) div 3
        %fill it
        Draw.Fill (cx, cy, col, col)
    end fillisotriangle
    %right angle triangle
    procedure ratriangle (x, y, base, height, col : int)
        var x2, y2, x3, y3 : int
        x2 := x + base
        x3 := x + height
        y2 := y
        y3 := y + height
        Draw.Line (x, y, x2, y2, col)
        Draw.Line (x2, y2, x3, y3, col)
        Draw.Line (x, y, x3, y3, col)
    end ratriangle
    %fill version of ratriangle
    procedure fillratriangle (x, y, base, height, col : int)
        var x2, y2, x3, y3 : int
        x2 := x + base
        x3 := x + height
        y2 := y
        y3 := y + height
        Draw.Line (x, y, x2, y2, col)
        Draw.Line (x2, y2, x3, y3, col)
        Draw.Line (x, y, x3, y3, col)
        var cx, cy : int
        %variables that get the centroid
        cx := (x + x2 + x3) div 3
        cy := (y + y2 + y3) div 3
        %fill it
        Draw.Fill (cx, cy, col, col)
    end fillratriangle
    %custom triangle
    procedure triangle (x, y, x2, y2, x3, y3, col : int)
        Draw.Line (x, y, x2, y2, col)
        Draw.Line (x2, y2, x3, y3, col)
        Draw.Line (x, y, x3, y3, col)
    end triangle
    %fill version of custom triangle
    procedure filltriangle (x, y, x2, y2, x3, y3, col : int)
        Draw.Line (x, y, x2, y2, col)
        Draw.Line (x2, y2, x3, y3, col)
        Draw.Line (x, y, x3, y3, col)
        var cx, cy : int
        %variables that get the centroid
        cx := (x + x2 + x3) div 3
        cy := (y + y2 + y3) div 3
        %fill it
        Draw.Fill (cx, cy, col, col)
    end filltriangle
    procedure canadaflag (x, y, thewidth : int)
    %set up the full sized flag
        var x2, y2, thelength : int
        x2 := x + thewidth
        thelength := thewidth div 2
        y2 := y + thelength
        Draw.FillBox (x, y, x2, y2, white)
        %now lets do the red boxes which are a quarter the size of the flag each.
        var red1x, red1y, red1y2, red1x2, red2x2, red2x, red2y, red2y2 : int
        red1x := x
        red1x2 := x+thewidth div 4
        red1y := y
        red1y2 :=y2
        %draw box 1
        Draw.FillBox (red1x, red1y, red1x2, red1y2, brightred)
        %now lets draw the second red box
        red2x := x2-thewidth div 4
        red2x2 := x2
        red2y := y
        red2y2 :=y2
        %draw box 1
        Draw.FillBox (red2x, red2y, red2x2, red2y2, brightred)
        var whiteboxwidth, whiteboxlength, mlsize, centrex, centrey, coord1, coord2, coord3, coord4 : int
        %get the size of the white part in the flag.
        whiteboxwidth := abs(red1x2 - red2x)
        whiteboxlength := abs (red1y2 - red2y)
        mlsize := (whiteboxwidth*2) div 3
        centrex := (red1x2 + red2x) div 2
        centrey := (red1y2 + red2y) div 2
        coord1 := centrex - (mlsize div 2)
        coord2 := centrey - (mlsize div 2)
        coord3 := centrex + (mlsize div 2)
        coord4 := centrey + (mlsize div 2)
Draw.FillMapleLeaf (coord1, coord2, coord3, coord4, brightred)
end canadaflag
end Shape
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: Tue Jul 03, 2007 3:30 pm   Post subject: Re: Useful module for drawing shapes (and a canada flag!)

LOL, I made one of these before (no I didn't post it)! Except mine was more of an alternative GUI with different styles (I always use to get pissed about the built-in turing GUI styles and useability). I is really cool, I have buttons, frames, messageboxes (I got that idea from VB), textboxes, scrollbars, optionboxes, etc. To be honest I got alot of these ideas from VB. Maybe sometime I will post it...
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  [ 2 Posts ]
Jump to:   


Style:  
Search: