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

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




PostPosted: Sat Nov 12, 2005 2:33 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat Nov 12, 2005 3:21 pm   Post subject: (No subject)

flamemaster89 wrote:
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 "omfg sooo trippy cool flashes!".

Capiche?
flamemaster89




PostPosted: Sat Nov 12, 2005 5:55 pm   Post subject: (No subject)

thanks for the feedback Rolling Eyes
Cervantes




PostPosted: Sat Nov 12, 2005 6:12 pm   Post subject: (No subject)

flamemaster89 wrote:
thanks for the feedback Rolling Eyes

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]




PostPosted: Sat Nov 12, 2005 10:24 pm   Post subject: (No subject)

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




PostPosted: Sun Nov 13, 2005 12:35 am   Post subject: (No subject)

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)

code:

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




PostPosted: Sun Nov 13, 2005 8:37 am   Post subject: (No subject)

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




PostPosted: Sun Nov 13, 2005 10:18 am   Post subject: (No subject)

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++?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Nov 13, 2005 10:44 am   Post subject: (No subject)

Flikerator wrote:
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 GUI classes. I was using classes extensively in that RTS engine I was working on a while ago, though I never did release the source to it, largely because I had modified the Turing predefs so much that it would be quite the hassel for people to test things out. If you want, I can send you the things you'd need to run it, however.
Flikerator wrote:

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:
Ruby:
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" )
=> #<Foo:0xb7d1ee30 @bar="Eric">
Jorbalax




PostPosted: Sat Nov 26, 2005 8:33 pm   Post subject: (No subject)

For reference, the original program was created by me. You can find it here.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: