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

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




PostPosted: Mon Mar 10, 2008 2:08 pm   Post subject: Implosions

Balls that are drawn consecutively in an array and have a shrinking radius that corresponds to a timed delay. I left it so you could control the starting x/y locations with the mouse, as it gives it a really cool trail effect. It also looks cool if you set them to random locations or give the main x/y's physics to bounce around/etc, so feel free to mess around.

Turing:

const COLORS : array 0 .. 14 of int := init (30, 29, 28, 27, 26, 25, 24, 23 ,22 ,21, 20, 19, 18, 17, 16 )
const BGCOLOR := green
const MBCOLOR := black
const STARTRAD := 50
const RADDECREASE := 1
const RDDELAY := 5 %delay for decrease in radius
const NBDELAY := 5  %delay for new implosions

View.Set ("graphics:max;max, offscreenonly, nobuttonbar, title:Ball Implosions")
colorback (BGCOLOR)

%contains ball location, color, radius, and time since last radius decrease
var ballArray : flexible array 1 .. 0 of
    record
        x, y, ts, col : int
        rad : real
    end record

%for removing expired elements from the ballArray
var removeArray : flexible array 1 .. 0 of int

%time comparing function for delays
fcn HasTimePassed (timesince, delayamount : int) : boolean
    if Time.Elapsed - timesince > delayamount then
        result true
    end if
    result false
end HasTimePassed

var TimeSinceLast : int := 0
var mx, my, mb : int

%control color changes
var iSelect : int := 0
var iTransValue : int := 1

loop

    %creates a new implosion at the specified location (mx, my) after a certain amount of time has passed
    if HasTimePassed (TimeSinceLast, NBDELAY) then
        Mouse.Where (mx, my, mb)
        new ballArray, upper (ballArray) + 1
        ballArray (upper (ballArray)).rad := STARTRAD
        ballArray (upper (ballArray)).x := mx %Rand.Int (round (ballArray (upper (ballArray)).rad), maxx - round (ballArray (upper (ballArray)).rad))
        ballArray (upper (ballArray)).y := my %Rand.Int (round (ballArray (upper (ballArray)).rad), maxy - round (ballArray (upper (ballArray)).rad))
        ballArray (upper (ballArray)).ts := 0
        ballArray (upper (ballArray)).col := COLORS (iSelect)
        TimeSinceLast := Time.Elapsed
       
        %alternates moving up and down the color array
        iSelect := (iSelect + iTransValue) mod (upper (COLORS) + 1)
        if iSelect = 0 or iSelect = upper (COLORS) then
        iTransValue := -iTransValue
        end if
    end if

    for i : 1 .. upper (ballArray)
        %draws current ball
        Draw.FillOval (ballArray (i).x, ballArray (i).y, round (ballArray (i).rad), round (ballArray (i).rad), ballArray (i).col)
        Draw.Oval (ballArray (i).x, ballArray (i).y, round (ballArray (i).rad), round (ballArray (i).rad), black)
       
        % decreases ball radius when appropriate
        if HasTimePassed (ballArray (i).ts, RDDELAY) then
            ballArray (i).rad -= RADDECREASE
            ballArray (i).ts := Time.Elapsed
        end if
       
        %draws a static-colored ball in the lead (otherwise it flickers from changing colors constantly)
        if i = upper (ballArray) then
            Draw.FillOval (ballArray (i).x, ballArray (i).y, STARTRAD, STARTRAD, MBCOLOR)
        end if
       
        %records which balls have shrunk too far
        if ballArray (i).rad < 1 then
            new removeArray, upper (removeArray) + 1
            removeArray (upper (removeArray)) := i
        end if
    end for
   
    %removes balls that have shrunk too far
    for i : 1 .. upper (removeArray)
        for j : removeArray (i) + 1 .. upper (ballArray)
            ballArray (j - 1) := ballArray (j)
        end for
        new ballArray, upper (ballArray) - 1
    end for
    new removeArray, 0
   
    View.Update
    exit when hasch
    delay (5)
    cls
end loop
Sponsor
Sponsor
Sponsor
sponsor
Mackie




PostPosted: Mon Mar 10, 2008 3:08 pm   Post subject: RE:Implosions

Nice, but it would be better if the circle colour was size dependent.
Jorbalax




PostPosted: Mon Mar 10, 2008 4:50 pm   Post subject: Re: Implosions

Yeah that does look good.

Turing:

const COLORS : array 0 .. 14 of int := init (30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16)
const BGCOLOR := green
const MBCOLOR := black
const STARTRAD := 50
const RADDECREASE := 0.5
const RDDELAY := 5 %delay for decrease in radius
const NBDELAY := 5  %delay for new implosions

View.Set ("graphics:max;max, offscreenonly, nobuttonbar, title:Ball Implosions")
colorback (BGCOLOR)

%contains ball location, color, radius, and time since last radius decrease
var ballArray : flexible array 1 .. 0 of
    record
        x, y, ts, col : int
        rad : real
    end record

%for removing expired elements from the ballArray
var removeArray : flexible array 1 .. 0 of int

%time comparing function for delays
fcn HasTimePassed (timesince, delayamount : int) : boolean
    if Time.Elapsed - timesince > delayamount then
        result true
    end if
    result false
end HasTimePassed

var TimeSinceLast : int := 0
var mx, my, mb : int

%control color changes
var iSelect : int := 0
var iTransValue : int := 1
var radiusColor : array 0 .. STARTRAD of int

%sets a color corresponding to a radius size
for decreasing i : STARTRAD .. 0
    radiusColor (i) := COLORS (iSelect)
    iSelect := (iSelect + iTransValue) mod (upper (COLORS) + 1)
    if iSelect = 0 or iSelect = upper (COLORS) then
        iTransValue := -iTransValue
    end if
end for

loop

    %creates a new implosion at the specified location (mx, my) after a certain amount of time has passed
    if HasTimePassed (TimeSinceLast, NBDELAY) then
        Mouse.Where (mx, my, mb)
        new ballArray, upper (ballArray) + 1
        ballArray (upper (ballArray)).rad := STARTRAD
        ballArray (upper (ballArray)).x := mx %Rand.Int (round (ballArray (upper (ballArray)).rad), maxx - round (ballArray (upper (ballArray)).rad))
        ballArray (upper (ballArray)).y := my %Rand.Int (round (ballArray (upper (ballArray)).rad), maxy - round (ballArray (upper (ballArray)).rad))
        ballArray (upper (ballArray)).ts := 0
        ballArray (upper (ballArray)).col := radiusColor (STARTRAD)
        TimeSinceLast := Time.Elapsed

    end if

    for i : 1 .. upper (ballArray)
        %draws current ball
        Draw.FillOval (ballArray (i).x, ballArray (i).y, round (ballArray (i).rad), round (ballArray (i).rad), ballArray (i).col)
        Draw.Oval (ballArray (i).x, ballArray (i).y, round (ballArray (i).rad), round (ballArray (i).rad), black)

        % decreases ball radius when appropriate
        if HasTimePassed (ballArray (i).ts, RDDELAY) then
            ballArray (i).rad -= RADDECREASE
            ballArray (i).col := radiusColor (round (ballArray(i).rad))
            ballArray (i).ts := Time.Elapsed
        end if

        %records which balls have shrunk too far
        if ballArray (i).rad < 1 then
            new removeArray, upper (removeArray) + 1
            removeArray (upper (removeArray)) := i
        end if
    end for

    %removes balls that have shrunk too far
    for i : 1 .. upper (removeArray)
        for j : removeArray (i) + 1 .. upper (ballArray)
            ballArray (j - 1) := ballArray (j)
        end for
        new ballArray, upper (ballArray) - 1
    end for
    new removeArray, 0

    View.Update
    exit when hasch
    delay (5)
    cls
end loop
A.J




PostPosted: Mon Mar 10, 2008 5:48 pm   Post subject: Re: Implosions

You could also use path finding (like A*) to help you add a 'friend' circle that follows you wherever you go.
You could also store coordinates and different sizes of balls in a type/record.
here's an example:
code:

type ballinfo :
    record
        x, y, size : int
    end record
var numofballs := Rand.Int (5, 8)
var balls : array 1 .. numofballs of ballinfo

This way, you could store the different pieces of information in one single array Very Happy.
just a few suggestions Very Happy

(keep asking for help, as we are here to help you Very Happy)

A.J
Jorbalax




PostPosted: Mon Mar 10, 2008 8:38 pm   Post subject: Re: Implosions

Yeah, making it into a chain would give you the same effect. I actually made this quite some time ago as a test for an implosion effect for a ball type game I was making...I was just sorting through some programs I had made, dug it up and start messing around with it again. I'll post the game after some touch ups, it's kinda cool.

As for storing info in a single array...
Turing:
%contains ball location, color, radius, and time since last radius decrease
var ballArray : flexible array 1 .. 0 of
    record
        x, y, ts, col : int
        rad : real
    end record
Sean




PostPosted: Tue Mar 11, 2008 7:00 am   Post subject: Re: Implosions

I like the effect, and they way it fades from black to white, then back to black.

Now, to expand this, try it with different shapes Razz
Doug101




PostPosted: Tue Apr 01, 2008 10:46 am   Post subject: Re: Implosions

sweet program its really fun and simple its the most fun ive had in a while
Tallguy




PostPosted: Thu Apr 17, 2008 10:04 am   Post subject: RE:Implosions

really well done
Sponsor
Sponsor
Sponsor
sponsor
andrew.




PostPosted: Fri Apr 18, 2008 8:35 pm   Post subject: Re: Implosions

Really nice.

P.S. Move your mouse in spirals. It makes it look a bit like a time portal. lol.
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  [ 9 Posts ]
Jump to:   


Style:  
Search: