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

Username:   Password: 
 RegisterRegister   
 circleClass
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Amarylis




PostPosted: Thu Mar 08, 2012 1:26 pm   Post subject: circleClass

No one in my programming class had any interest whatsoever to learn class systems, and I dont want my work to go to waste, here's what I made in my free time to try to help people.

Turing:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%===== Turing Code ==========================================%%
%%= circleClass.t                                             %%
%%===== By: ==================================================%%
%%= A. Prado                                                  %%
%%===== Current Version: =====================================%%
%%= 1.0                                                       %%
%%===== Description: =========================================%%
%%= Program for introduction of class systems. It draws two   %%
%%= circles using pointers to a class where they are all      %%
%%= stored. No variables exported, so new procedures are made %%
%%= for any change in values that variables require. Not      %%
%%= overly necessary for this program, but serves as good     %%
%%= programming etiquette, since then variables will remain   %%
%%= safe.                                                     %%
%%===== Version Changelog: ===================================%%
%%= 1.0     - First stable release. Fully documented. [Bruno] %%
%%============================================================%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Sets screen to graphics, 600x600 px dimensions, takes out buttonbar, utilizes offscreen bitmap to update screen
View.Set ("graphics:600;600,nobuttonbar, offscreenonly")

class Circle % Class declaration
    export drawCircle, xP, yP, xR, yR, colNum, Ty, tyCheck % Export list. Note, no variables are exported
    var xPos, yPos, xRad, yRad, Col, Type : int % Variable declaration


    % Default variable values
    xPos := 300
    yPos := 300
    xRad := 5
    yRad := 5
    Col := 16
    Type := 1


    % Procedures used to alter variable values.
    % Needed, since class variables aren't exported in this program
    procedure xP (x : int) % Changes xPos
        xPos += x
    end xP

    procedure yP (y : int) % Changes yPos
        yPos += y
    end yP

    procedure xR (x : int) % Changes xRad
        xRad += x
    end xR

    procedure yR (y : int) % Changes yRad
        yRad += y
    end yR

    procedure colNum (c : int) % Changes Col
        Col := c
    end colNum

    procedure Ty (t : int) % Changes Type
        Type := t
    end Ty


    procedure tyCheck (var t : int) % Returns value of Type
        t := Type
    end tyCheck

    % Procedure that draws stuff
    procedure drawCircle
        if Type = 1 then
            Draw.FillOval (xPos, yPos, xRad, yRad, Col)
        else
            Draw.Oval (xPos, yPos, xRad, yRad, Col)
        end if
    end drawCircle
end Circle



var keys : array char of boolean  % Array that catches user input
var winCol : int % Variable that keeps track of the colour number window
var circleC : int := 1 % Variables used to flip between instances
var temp : int % Temporary variable, used to change Circle . Col and Circle . Type
var circle, circle2 : ^Circle % Pointer variables, full form "var circle, circle2 : pointer of Circle"
new circle % Assigns value to pointer "circle". Short form for "new Circle, circle"
new circle2 % Assigns value to pointer "circle2". Short form for "new Circle, circle2"




loop % Main program loop
    Input.KeyDown (keys) % Cleans out key values
    exit when keys ('e')
    if circleC = 1 then % Activates "circle" pointer
        cls
        % Calls the procedure drawCircle found under properties of pointer "circle"
        circle -> drawCircle % Short form for "Circle (circle) . drawCircle"
        if keys (KEY_UP_ARROW) = true then
            cls
            % Calls procedure required to change the variable yPos under the properties of "circle".
            % Causes circle -> yPos to increase by 1
            circle -> yP (1) % Short form for "Circle (circle) . yP (1)"
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys (KEY_DOWN_ARROW) then
            cls
            % Calls procedure required to change the variable yPos under the properties of "circle".
            % Causes circle -> yPos to decrease by 1
            circle -> yP (-1)
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys (KEY_LEFT_ARROW) then
            cls
            % Calls procedure to change the variable xPos under the properties of "circle".
            % Causes circle -> xPos to decrese by 1
            circle -> xP (-1) % Short form for "Circle (circle) . xP (-1)"
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys (KEY_RIGHT_ARROW) then
            cls
            % Calls procedure to change the variable xPos under the properties of "circle".
            % Causes circle -> xPos to increse by 1
            circle -> xP (1)
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys (KEY_SHIFT) then
            cls
            % Calls necessary procedures to increase the radius of the circle (both x and y)
            % by a uniform amount (1).
            circle -> xR (1) % Short form for "Circle (circle) . xR (1)"
            circle -> yR (1) % Short form for "Circle (circle) . yP (1)"
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys (KEY_CTRL) then
            cls
            % Calls necessary procedures to decrease the radius of the circle (both x and y)
            % by a uniform amount (1).
            circle -> xR (-1)
            circle -> yR (-1)
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys ('c') then
            % Opens a new window
            winCol := Window.Open ("position:top;center,graphics:200;200")
            % Selects said window
            Window.Select (winCol)
            % Grabs an integer variable
            get temp
            % Uses temporary int variable to change value of "circle -> Col"
            circle -> colNum (temp) % Short form for "Circle (circle) . colNum (temp)"
            % Closes colour window
            Window.Close (winCol)
            cls
            % Redraws the circle with new parameters
            circle -> drawCircle
        end if
        if keys ('t') then
            % Calls procedure to assign the value of "circle -> Type" to the variable "temp"
            circle -> tyCheck (temp) % Short form for "Circle (circle) . tyCheck (temp)"
            if temp = 1 then
                circle -> Ty (0) % Draws circle borders. Short form for "Circle (circle) . Ty (0)"
            else
                circle -> Ty (1) % Draws full circle
            end if
            cls
            % Redraws the circle with new parameters
            circle -> drawCircle
            delay (75)
        end if
        if keys ('2') then
            circleC := 2 % Flips through to "circle2"
        end if
    elsif circleC = 2 then
        cls
        % Calls the procedure drawCircle found under properties of pointer "circle2"
        circle2 -> drawCircle % Short form for "Circle (circle2) . drawCircle"
        if keys (KEY_UP_ARROW) then
            cls
            % Calls procedure required to change the variable yPos under the properties of "circle2".
            % Causes circle -> yPos to increase by 1
            circle2 -> yP (1) % Short form for "Circle (circle2) . yP (1)"
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys (KEY_DOWN_ARROW) then
            cls
            % Calls procedure required to change the variable yPos under the properties of "circle2".
            % Causes circle -> yPos to decrease by 1
            circle2 -> yP (-1)
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys (KEY_LEFT_ARROW) then
            cls
            % Calls procedure to change the variable xPos under the properties of "circle2".
            % Causes circle -> xPos to decrese by 1
            circle2 -> xP (-1) % Short form for "Circle (circle2) . xP (-1)"
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys (KEY_RIGHT_ARROW) then
            cls
            % Calls procedure to change the variable xPos under the properties of "circle2".
            % Causes circle -> xPos to increse by 1
            circle2 -> xP (1)
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys (KEY_SHIFT) then
            cls
            % Calls necessary procedures to increase the radius of the circle (both x and y)
            % by a uniform amount (1).
            circle2 -> xR (1) % Short form for "Circle (circle2) . xR (1)"
            circle2 -> yR (1) % Short form for "Circle (circle2) . yR (1)"
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys (KEY_CTRL) then
            cls
            % Calls necessary procedures to decrease the radius of the circle (both x and y)
            % by a uniform amount (1).
            circle2 -> xR (-1)
            circle2 -> yR (-1)
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys ('c') then
            % Opens new window
            winCol := Window.Open ("position:top;center,graphics:200;200")
            % Selects said window
            Window.Select (winCol)
            % Grabs an integer variable
            get temp
            % Uses temporary int variable to change value of circle2 -> Col
            circle2 -> colNum (temp) % Short form for "Circle (circle2) . colNum (temp)"
            % Closes colour window
            Window.Close (winCol)
            cls
            % Redraws the circle with new parameters
            circle2 -> drawCircle
        end if
        if keys ('t') then
            % Calls procedure to assign the value of "circle2 -> Type" to the variable "temp"
            circle2 -> tyCheck (temp) % Short form for "Circle (circle2) . tyCheck (temp)"
            if temp = 1 then
                circle2 -> Ty (0) % Draws circle border. Short form for "Circle (circle2) . Ty (0)"
            else
                circle2 -> Ty (1) % Draws full circle
            end if
            cls
            % Redraws the circle with new parameters
            circle2 -> drawCircle
            delay (200)
        end if
        if keys ('1') then
            circleC := 1 % Flips through to "circle"
        end if
    end if
    View.Update
end loop



circleClass.t
 Description:

Download
 Filename:  circleClass.t
 Filesize:  9.49 KB
 Downloaded:  136 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Thu Mar 08, 2012 9:14 pm   Post subject: RE:circleClass

That's pretty cool. I'm glad you went off and learned how to use them yourself (or at least I'm guessing).

Out of curiosity, whats the grade level of this class?
Amarylis




PostPosted: Thu Mar 08, 2012 9:52 pm   Post subject: RE:circleClass

I'm used to using classes and such in other languages (namely C#). Turing, not as much, since I try not to spend too much time on it outside of class Razz

It's a Grade 11 class (ICS3U)
Amarylis




PostPosted: Thu Mar 08, 2012 10:47 pm   Post subject: RE:circleClass

Pardon the double post, after an hour or so I seldom see why it should still apply-

To put in perspective with the rest of my class, they're learning how to use arrays now, haven't even dabbled in file processing, GUI, majority still use "brightred", "grey", etc for colors, just recently learnt how to do graphics.......
mirhagk




PostPosted: Thu Mar 08, 2012 11:00 pm   Post subject: RE:circleClass

schools never teach enough for programming. They need to accompany those students who aren't interested in programming at all, and they need to do all the dumb environment, career and other stuff the board wants them to do.
Amarylis




PostPosted: Thu Mar 08, 2012 11:06 pm   Post subject: RE:circleClass

Meh, true say. I'm aiming to do the AP exam for CompSci, so hopefully I'll be able to PLAR the ICS4U course and spend the time I'd have spent being bored in that class into actually making something useful-


Hopefully that'll also improve my odds of getting into Waterloo SE
crossley7




PostPosted: Thu Mar 08, 2012 11:08 pm   Post subject: RE:circleClass

The school curriculum for programming is nearly non existent. A strong programmer could do the entire course work for grade 12 by the end of their grade 10 comp sci class if they felt like it.

Someone in my grade 12 class just learned 2D arrays in turing and I was taken aback since I've been using them since near the end of grade 10 (when I finally was introduced to the idea) and other than the Java class which isn't really explained (and I ignored) there isn't class structures in the course material so I had to teach myself that and I just recently started using friendship in c++
Amarylis




PostPosted: Thu Mar 08, 2012 11:12 pm   Post subject: RE:circleClass

Seeing how the job market for CS should be seriously expanding, I fail to see why high schools have such a pathetic curriculum for their CS classes... I mean, come on, does it really take 3 1:15 lessons just to understand put/get statements? It's just some basic I/O stuff Razz


On that topic, it's the 3rd or 4th day of my class learning arrays... They've been going at the same 5 problems for all those classes, and they're STILL not done, whilst the two students who're actually interested in the subject (myself and another one of my peers) finished the entire assignment in 15 minutes
Sponsor
Sponsor
Sponsor
sponsor
crossley7




PostPosted: Thu Mar 08, 2012 11:14 pm   Post subject: RE:circleClass

That is where you find yourself a large project to do in your spare time that forces you to learn new aspects of either functions or syntax so you can keep learning. Contest problems are also a good way to waste time
Amarylis




PostPosted: Thu Mar 08, 2012 11:16 pm   Post subject: RE:circleClass

Fair enough....

Grr, I need to assemble myself a DWITE team....
crossley7




PostPosted: Thu Mar 08, 2012 11:23 pm   Post subject: RE:circleClass

Well, actually you need an ECOO team since DWITE is done for the year. Unless it is for next year. Either way good luck
Amarylis




PostPosted: Thu Mar 08, 2012 11:25 pm   Post subject: RE:circleClass

Thanks, I'll definitely need it
Raknarg




PostPosted: Fri Mar 09, 2012 9:31 pm   Post subject: RE:circleClass

That's unfortunate. Luckily for my school, we have a pretty strong class with a very good teacher.
Amarylis




PostPosted: Fri Mar 09, 2012 9:38 pm   Post subject: RE:circleClass

Would love to be in your school then Razz Mine focuses more on classes such as the sciences and arts. Computer science and social sciences end up being forgotten, pretty much
Raknarg




PostPosted: Fri Mar 09, 2012 10:46 pm   Post subject: RE:circleClass

Haha it is forgotten. Our teacher just happens to be a master of math, teaching and compsci Razz
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  [ 15 Posts ]
Jump to:   


Style:  
Search: