
-----------------------------------
TheZsterBunny
Sun Feb 22, 2004 1:59 pm

A simpler way to do animation?
-----------------------------------
Hrm. I'm working on some fun stuff, and am having some issues with animation. I have this working, but its terribly inefficient. There must be an easier way to do it.

It is a 5 stage animation for some sort of plasma bolt. It fires from the centre of the screen to wherever you click. The animation is pretty bad, but i'll fix that once the code is straightened out.

-bunny

-----------------------------------
Andy
Sun Feb 22, 2004 2:01 pm


-----------------------------------
post ur code so we can see

-----------------------------------
shorthair
Sun Feb 22, 2004 2:05 pm


-----------------------------------
have you tried the view.Update , and .Area , when you post the code im sure we can help you

-----------------------------------
Cervantes
Sun Feb 22, 2004 2:12 pm


-----------------------------------
from the Turing examples folder


% The "SmoothAnimateHouse" program.

% This program demonstrates the View.Update and setscreen ("offscreenonly")

% Draw a house
drawbox (30, 30, 100, 100, black)
drawbox (50, 30, 80, 60, brightred)
drawbox (35, 70, 55, 90, green)
drawline (45, 70, 45, 90, green)
drawline (35, 80, 55, 80, green)
drawbox (75, 70, 95, 90, green)
drawline (85, 70, 85, 90, green)
drawline (75, 80, 95, 80, green)
drawline (30, 100, 65, 135, brightblue)
drawline (65, 135, 100, 100, brightblue)
drawline (90, 110, 90, 150, black)
drawline (75, 125, 75, 150, black)
drawline (75, 150, 90, 150, black)
locate (maxrow, 2)
put "Home sweet home" ..

% Create the picture
const PIC_WIDTH := 130
const PIC_HEIGHT := 160
var pic := Pic.New (0, 0, PIC_WIDTH, PIC_HEIGHT)

% Animate 10 of them around the screen
var x, y, dx, dy : array 1 .. 10 of int
cls
for i : 1 .. 10
    x (i) := Rand.Int (10, maxx - 10 - PIC_WIDTH)
    y (i) := Rand.Int (10, maxy - 10 - PIC_HEIGHT)
    dx (i) := Rand.Int (-3, 3)
    dy (i) := Rand.Int (-3, 3)
end for

loop
    cls
    locate (maxrow, 10)
    put "Old Animation Technique.  Press any key to see the new technique" ..
    for i : 1 .. 10
        if x (i) + dx (i) < 0 or x (i) + dx (i) + PIC_WIDTH > maxx then
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < 0 or y (i) + dy (i) + PIC_HEIGHT > maxy then
            dy (i) := -dy (i)
        end if
        x (i) := x (i) + dx (i)
        y (i) := y (i) + dy (i)
        Pic.Draw (pic, x (i), y (i), picMerge)
    end for
    exit when hasch
end loop

% Read the character from the buffer.
var ch : string (1)
getch (ch)

% Now, any drawing to the screen won't appear until a View.Update is
% given.  Note that you can turn this off with 
setscreen ("offscreenonly")
loop
    cls
    locate (maxrow, 10)
    put "New Animation Technique.  Press any key to quit" ..
    for i : 1 .. 10
        if x (i) + dx (i) < 0 or x (i) + dx (i) + PIC_WIDTH > maxx then
            dx (i) := -dx (i)
        end if
        if y (i) + dy (i) < 0 or y (i) + dy (i) + PIC_HEIGHT > maxy then
            dy (i) := -dy (i)
        end if
        x (i) := x (i) + dx (i)
        y (i) := y (i) + dy (i)
        
        % Note this only draws on the offscreen window.  Nothing appears
        % in the visible window.
        Pic.Draw (pic, x (i), y (i), picMerge)
    end for
    % All the houses have been drawn.  Now update the screen.
    View.Update
    exit when hasch
end loop
setscreen ("nooffscreenonly")


-----------------------------------
TheZsterBunny
Sun Feb 22, 2004 2:27 pm

The Code
-----------------------------------
sorry, i guess i forgot to attach.


% Slow Blue Energy Shot
var x1, y1, x2, y2, width : int
var mx, my, mb : int
proc blueshot (x1, y1, x2, y2, width : int)
    cls
    for decreasing stage : 5 .. 1
        if stage = 5 then
            drawfilloval (x1, y1, width div 2, width div 2, blue)
        elsif stage = 4 then
            Draw.ThickLine (x1, y1, ((((x1 + x2) div 2) + x1) div 2), ((((y1 + y2) div 2) + y1) div 2), width, blue)
        elsif stage = 3 then
            Draw.ThickLine (x1, y1, (x1 + x2) div 2, (y1 + y2) div 2, width, blue)
        elsif stage = 2 then
            Draw.ThickLine (x1, y1, ((((x1 + x2) div 2) + x2) div 2), ((((y1 + y2) div 2) + y2) div 2), width, blue)
        elsif stage = 1 then
            Draw.ThickLine (x1, y1, x2, y2, width, blue)
        end if
        delay (50)
    end for
end blueshot
loop
    mousewhere (mx, my, mb)
    if mb = 1 then
        blueshot (maxx div 2, maxy div 2, mx, my, 5)
    end if
end loop


And while i'm here


var mx, my, mb : int
var clr : int
proc GADOOMBA (x1, y1, rad1, rad2, excolor : int)
    cls
    for explosion : 1000000 .. 2718283 by 500
        drawfilloval (x1, y1, round ((ln (explosion / 1000000)) * rad1), round ((ln (explosion / 1000000)) * rad2), excolor)
    end for
end GADOOMBA

loop
    mousewhere (mx, my, mb)
    randint (clr, 0, maxcolor)
    if mb = 1 then
        GADOOMBA (mx, my, 80, 100, clr)
    end if
end loop


Please excuse variable/procedure names. I pride uniquosity in my programs.

-bunny

-----------------------------------
TheXploder
Sun Feb 22, 2004 2:54 pm


-----------------------------------
I don't get what you are trying to do, but try this:

% Slow Blue Energy Shot

View.Set ("offscreenonly")
var x1, y1, x2, y2, width : int
var mx, my, mb : int
var stage := 5
var c := 0
proc blueshot (x1, y1, x2, y2, width : int)
    cls
    loop
        locate (1, 1)
        put stage
        if c = 5 then
            stage := stage - 1
            if stage  1000001 then
        cls
        count := 1
    end if
end loop


Here is the finished animation for the second part of my code. this is a firey explosion. supposedly

-bunny
