
-----------------------------------
flamemaster89
Sat Nov 12, 2005 2:33 pm

cool design maker
-----------------------------------
This is is an program that i found on this website and the person who created it should get credit for it but i edited a little to some thing different each time you run it.



View.Set ("graphics:max;max, nobuttonbar,title:Mult-Ball Stream,  offscreenonly") 

%Editable Constants% 
const BALLCOUNT := 1 
const BALLRADIUS := 5 
const BALLSPEED := 0

class RandomCircles 
    import BALLRADIUS, BALLSPEED 
    export StartValues, BallDirection, BallCreate 

    var cx, cy, cdirectionx, cdirectiony, iColour : int := 0 
    var chars : string (1) 
    
    
    procedure StartValues 
        randint (cx, 0+BALLRADIUS*2, maxx-BALLRADIUS*2) 
        randint (cy, 0+BALLRADIUS*2, maxy-BALLRADIUS*2) 
        loop 
            randint (iColour, 1, 103) 
            randint (cdirectionx, -20, 20) 
            randint (cdirectiony, -20, 20) 
            exit when cdirectionx not = 0 
            exit when cdirectiony not = 0 
        end loop 
    end StartValues 

    %Wall collision 
    procedure BallDirection 
        cx := cx + cdirectionx 
        cy := cy + cdirectiony 
        if cx < BALLRADIUS or cx > maxx - BALLRADIUS then 
            cdirectionx := -cdirectionx 
        end if 
        if cy < BALLRADIUS or cy > maxy - BALLRADIUS then 
            cdirectiony := -cdirectiony 
        end if 
    end BallDirection 

    %Ball Creation Procedure% 
    procedure BallCreate 
        Draw.FillOval (cx, cy, BALLRADIUS, BALLRADIUS, iColour) 
        BallDirection 
        delay (BALLSPEED) 
    end BallCreate 
        

end RandomCircles 


procedure DrawBall 
    
    var p : array 1 .. BALLCOUNT of pointer to RandomCircles 
    for i : 1 .. BALLCOUNT 
        new RandomCircles, p (i) 
    end for 

    
    loop 
        for i : 1 .. BALLCOUNT 
            p (i) -> StartValues 
        end for 
        loop 
            for i : 1 .. BALLCOUNT 
                p (i) -> BallCreate 
          
            end for 
            View.Update 
            
        end loop 
    end loop 
end DrawBall 

%Executes% 
DrawBall

-----------------------------------
Cervantes
Sat Nov 12, 2005 3:21 pm


-----------------------------------
the person who created it should get credit for it
Then you should give that person credit.  Who?  Also, you should state exactly what you altered.

Second, please use [code ] [/code ] tags to surround your code.  Even better, you could use [syntax="turing" ] [/syntax ] tags.

Last, this falls under the category of [url=http://www.compsci.ca/v2/viewtopic.php?t=7734]"omfg sooo trippy cool flashes!".

Capiche?

-----------------------------------
flamemaster89
Sat Nov 12, 2005 5:55 pm


-----------------------------------
thanks for the feedback :roll:

-----------------------------------
Cervantes
Sat Nov 12, 2005 6:12 pm


-----------------------------------
thanks for the feedback :roll:
I'd love to comment, but I don't know what you've done.  I could comment on the whole thing, but most (probably all) of it wouldn't pertain to what you've done.

-----------------------------------
[Gandalf]
Sat Nov 12, 2005 10:24 pm


-----------------------------------
Two things I can say:
1. Use [code][/code] and [syntax="turing"][/syntax] tags when posting code.
2. Indent your program please.  Check out wtd's latest post in his Programming Tip of the Day topic:
http://www.compsci.ca/v2/viewtopic.php?t=10119

-----------------------------------
Flikerator
Sun Nov 13, 2005 12:35 am


-----------------------------------
I didn't know turing had pointers...lolz.

Seems like an over complexed way to have a bouncing ball.

EDIT - Very simple, 2 minute made (without the randomness)


View.Set ("offscreenonly")

var ballx : real := 50
var bally : real := 50
var ballxspd, ballyspd : real := 1.3

loop
    Draw.FillOval (round (ballx), round (bally), 5, 5, red)
    ballx += ballxspd
    bally += ballyspd
    if bally + 5 > maxy then
        ballyspd := -ballyspd
    elsif bally - 5 < 0 then
        ballyspd := -ballyspd
    end if
    if ballx + 5 > maxx then
        ballxspd := -ballxspd
    elsif ballx - 5 < 0 then
        ballxspd := -ballxspd
    end if
    View.Update
    delay (5)
    cls
end loop


-----------------------------------
Cervantes
Sun Nov 13, 2005 8:37 am


-----------------------------------
This example is very clumsily done.  For example, constants that are used inside the class and only inside the class (BALLRADIUS and BALLSPEED) are declared outside the class, then imported.  Very bad.  It would be much better to declare the constants inside the class.  Perhaps make them variables so they can be edited via a particular procedure (an initialization procedure).

Flikerator: You should learn about classes!  Check out Catalysts tutorial in [Turing Tutorials]

-----------------------------------
Flikerator
Sun Nov 13, 2005 10:18 am


-----------------------------------
When are classes usefull? I read the tutorial, and understand them a little bit, but when would they be useful?

Edit - I read it again, and I can see where it would be useful ^^;

Do classes work the same way in other languages? Like C++?

-----------------------------------
Cervantes
Sun Nov 13, 2005 10:44 am


-----------------------------------
When are classes usefull? I read the tutorial, and understand them a little bit, but when would they be useful?

Edit - I read it again, and I can see where it would be useful ^^;
A good example you may wish to check out is my 
Do classes work the same way in other languages? Like C++?

Essentially, though there are differences.  Turing does not support multiple inheritence in any format.  Also, in Turing, you've got to go to the trouble of declaring a pointer to the (parent) class, then creating a new instance of the class (or any of its daughter classes) with its reference being the pointer.  In Ruby, for example, things are much neater:
irb(main):001:0> class Foo
irb(main):002:1>     def initialize( name )
irb(main):003:2>         @bar = name
irb(main):004:2>     end
irb(main):005:1> end
=> nil
irb(main):006:0> baz = Foo.new( "Eric" )
=> #


-----------------------------------
Jorbalax
Sat Nov 26, 2005 8:33 pm


-----------------------------------
For reference, the original program was created by me.  You can find it [url=http://www.compsci.ca/v2/viewtopic.php?t=8616]here.
