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

Username:   Password: 
 RegisterRegister   
 Animation Question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
revangrey




PostPosted: Sat Dec 20, 2008 6:51 pm   Post subject: Animation Question

Could someone please explain to me in simple terms how to do two things?

I have two questions and they consist of:

How do you make two or more animations run at the same time (like how would you make snow fall, while a snowman waves his arms, while santa does the can't dance?)?

next how would you make one animation start when another stops?(or start one animation midway through another, such as when my death star laser starts firing somewhat backwards how do I make a red line going across where it has passed?)?

I do not expect anyone to do my work for me but graphics is my worst unit so you may want to be fairly exact in your explanations. I know some of this may be obvious to some of you but please no "you are just trying to get people to do your work for you" comments. I'm really not.

what I have so far consits of:

Turing:
%snow
View.Set ("offscreenonly")
setscreen ("graphics: 1200, 500")
%Music.PlayFileReturn()
type SnowType :
    record
        X, Y, Spd, Size : int
    end record
var Snow : array 1 .. 100 of SnowType
for rep : 1 .. 100
    Snow (rep).X := Rand.Int (5, 645)
    Snow (rep).Y := Rand.Int (5, 475)
    Snow (rep).Spd := Rand.Int (1, 3)
    Snow (rep).Size := Snow (rep).Spd
end for
loop
    for rep : 1 .. 100
        Snow (rep).Y -= Snow (rep).Spd
        if Snow (rep).Y < Snow (rep).Size then
            Snow (rep).Y := Rand.Int (475, 575)
        end if
        drawfilloval (Snow (rep).X, Snow (rep).Y, Snow (rep).Size, Snow (rep).Size, white)
    end for
    View.Update
    cls







    colorback (blue)
    cls

    %background/skyline
    drawfillbox (0, 0, 1200, 100, white)
    %moon
    drawfilloval (40, 350, 50, 50, grey)

    drawoval (40, 350, 55, 55, grey)
    drawoval (40, 350, 65, 65, grey)
    drawoval (40, 350, 70, 70, grey)
    %house  with window

    %everywhere?
    drawfillbox (100, 100, 300, 200, 7)     %house
    drawline (100, 200, 200, 300, red)     %left
    drawline (300, 200, 200, 300, red)     %right
    drawline (100, 200, 300, 200, red)
    drawfill (120, 201, red, red)
    drawfillbox (60, 1, 20, 200, 6)      %tree
    drawfillbox (115, 100, 150, 150, 30)     %door
    drawfilloval (120, 118, 5, 5, black)     %doorknob
    drawfillbox (100, 200, 300, 250, red)     %chimmeney

    %Stars
    drawfillstar (120, 320, 140, 340, yellow)
    drawfillstar (200, 350, 220, 370, yellow)
    drawfillstar (220, 320, 240, 340, yellow)
    drawfillstar (330, 430, 350, 450, yellow)
    drawfillstar (150, 350, 170, 370, yellow)
    drawfillstar (170, 300, 190, 320, yellow)
    drawfillstar (450, 350, 470, 370, yellow)
    drawfillstar (480, 380, 500, 400, yellow)
    drawfillstar (520, 300, 540, 320, yellow)
    drawfillstar (600, 320, 620, 340, yellow)
    drawfillstar (520, 320, 540, 340, yellow)
    drawfillstar (600, 240, 620, 260, yellow)


    drawfillbox (212, 245, 180, 212, 30)

    drawfillbox (180, 140, 245, 180, 100)
    drawline (180, 160, 245, 160, 42)
    drawline (212, 140, 212, 180, 42)


    drawfilloval (350, 93, 15, 15, 31)
    drawfilloval (350, 120, 12, 12, 31)
    drawfilloval (350, 142, 10, 10, 31)

    var font1 : int
    font1 := Font.New ("Comicsans:14:bold,italic")
    Font.Draw ("MERRY CHRISTMAS", 50, 30, font1, green)


end loop



the Christmas program is quite unfinished and I am going to make some adjustments but I would like to know how to animate properly asap. The christmas program is an assignement.
Turing:

%Death Star program
setscreen ("offscreenonly")
setscreen ("graphics: 1200, 500")
colorback (black)
cls
var x : int := maxx - 100
loop

    drawfilloval (300, 300, 300, 300, grey)
    drawline (maxx div 2, maxy div 2, x, 100, brightgreen)
    x -= 1

    View.Update
    delay (10)
    exit when x = 100
    cls

end loop

the death star thing is purely for fun and not very important

any and all help is appreciated, thank you for your time
Sponsor
Sponsor
Sponsor
sponsor
Amit




PostPosted: Sat Dec 20, 2008 10:08 pm   Post subject: Re: Animation Question

I would use procedures. You already have the snow animation working, so just take all the code and put it into a procedure. The main part should be a loop calling the procedure. Each procedure would move, then draw the animation. As for stoping and starting the animation, just have a boolean variable to control each procedure. It would look something like this ...

Turing:

setscreen(offscreenonly)

<all variable>

<all procedures>

loop

if (shouldSnow) then
     proc makeItSnow
end if

if (snowman) then
     proc Snowman
end if

if (shouldDance) then
     proc santaDance
end if

View.Update
end loop
revangrey




PostPosted: Sun Dec 21, 2008 12:14 am   Post subject: Re: Animation Question

thank you for the suggestion, but could you or anyone for that matter explain how to use procedures properly?

My teacher has not taught us how, and I doubt she will.

Any additional suggestions are much appreciated, I know almost nothing about graphics.



Ignorance most certainly is not bliss Very Happy
revangrey




PostPosted: Mon Dec 29, 2008 12:20 am   Post subject: Re: Animation Question

sorry about the double post but could someone please help me with these programs before the end of the break?

the christmas project is due at the end of the break...
Tony




PostPosted: Mon Dec 29, 2008 1:31 am   Post subject: RE:Animation Question

links to the common tutorials, including use of procedures, can be found in Turing Walkthrough.

The idea behind animation is that you have a single loop that draws frame after frame. A procedure is simply a way to group a block of code together, that can later be called from any other place -- for the purposes of animation it simply makes things a lot cleaner and easier to understand.

I really like Amit's suggestion on using flags (boolean variables) to set when a particular part of a frame should or should not be drawn.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
revangrey




PostPosted: Wed Dec 31, 2008 6:17 pm   Post subject: Re: Animation Question

thanks for the advice!

new question:

is there a way to move an object you have drawn?

like say I drew a tree or a star, and I want to move it to a new area but keep the same size etc. without having to find the right numbers all over again.

(like is there some formula I am unaware of ?)

any and all suggestions appreciated (regarding anything to do with this assignment and I mean ANYTHING)!

thanks in advance!
The_Bean




PostPosted: Wed Dec 31, 2008 6:33 pm   Post subject: Re: Animation Question

You've already moved objects with the snow. When moving boxes you just have to make all points relative to the one that is moving.
Homer_simpson




PostPosted: Wed Dec 31, 2008 6:47 pm   Post subject: Re: Animation Question

set x,y position variables

e.g.


Turing:

var y : int := 0
for x : 1 .. 300
    y :=  x
    drawfilloval (100 + x, 100 + y, 20, 20, 10)
    delay (5)
    cls

end for
Sponsor
Sponsor
Sponsor
sponsor
revangrey




PostPosted: Wed Dec 31, 2008 7:18 pm   Post subject: Re: Animation Question

sorry I wasn't clear enough

I meant like if I have already drawn something

and I put it in a stupid place

how would I move that object into a new place

within the code that is

say my moon is on the left

and I now want it on the right for example

I don't mean a moving object within the animation

I mean literally changing the code

but I am now doubting that there is an "easy" way...
Homer_simpson




PostPosted: Thu Jan 01, 2009 3:42 pm   Post subject: Re: Animation Question

yeah if u dont want to rewrite all the coordinates, you just add an x and y to your orginal coordinated, for example if u want to move your moon to the right :
Turing:
colorback (black)
cls
var moonx : int
moonx := 200

%%%%%%%%%%%draw moon%%%%%%%%%
drawfilloval (150 + moonx, 350, 20, 20, white)
drawfilloval (145 + moonx, 355, 3, 3, gray)
drawfilloval (153 + moonx, 345, 4, 4, gray)
drawfilloval (157 + moonx, 357, 2, 2, gray)


Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]
revangrey




PostPosted: Thu Jan 01, 2009 4:17 pm   Post subject: Re: Animation Question

thanks a million!
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: