A simpler way to do animation?
Author |
Message |
TheZsterBunny
|
Posted: Sun Feb 22, 2004 1:59 pm Post subject: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Andy
|
Posted: Sun Feb 22, 2004 2:01 pm Post subject: (No subject) |
|
|
post ur code so we can see |
|
|
|
|
|
shorthair
|
Posted: Sun Feb 22, 2004 2:05 pm Post subject: (No subject) |
|
|
have you tried the view.Update , and .Area , when you post the code im sure we can help you |
|
|
|
|
|
Cervantes
|
Posted: Sun Feb 22, 2004 2:12 pm Post subject: (No subject) |
|
|
from the Turing examples folder
code: |
% 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
|
Posted: Sun Feb 22, 2004 2:27 pm Post subject: The Code |
|
|
sorry, i guess i forgot to attach.
code: |
% 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
code: |
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
|
Posted: Sun Feb 22, 2004 2:54 pm Post subject: (No subject) |
|
|
I don't get what you are trying to do, but try this:
code: | % 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 <= 0 then
stage := 6
exit
end if
c := 0
end if
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 (10)
c := c + 1
View.Update
end loop
end blueshot
loop
mousewhere (mx, my, mb)
if mb = 1 then
blueshot (maxx div 2, maxy div 2, mx, my, 5)
end if
View.Update
end loop |
|
|
|
|
|
|
TheZsterBunny
|
Posted: Sun Feb 22, 2004 2:58 pm Post subject: (No subject) |
|
|
My goal was to have turing draw the moving line in stages by itsself rather than using 'if stage =' for it.
I've been using offscreenonly for a while, its nothing new to me, but i appreciate you (plural) sending examples. Maybe one day i'll send in my paint program.
The second program is an explosion where the rate of expansion slows as the circle grows.
-bunny |
|
|
|
|
|
TheZsterBunny
|
Posted: Mon Feb 23, 2004 3:25 pm Post subject: Followbomb |
|
|
code: |
var clr : int
var count := 1
% Deathmanship
var mx, my, mb : int
colorback (black)
cls
process kbomb (x1, y1, rad1, rad2, clr : int)
for x : 1 .. 90
drawfilloval (x1, y1, round ((sind (x)) * rad1), round ((sind (x)) * rad2), clr)
delay (5)
end for
drawfilloval (x1, y1, round ((sind (90)) * rad1), round ((sind (90)) * rad2), black)
end kbomb
loop
mousewhere (mx, my, mb)
if mb = 1 then
clr := Rand.Int (41, 43)
fork kbomb (mx, my, 25, 25, clr)
delay (50)
end if
count := count + 1
if count > 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|