]>
Dogcows Code - chaz/rasterize/blob - animate.lua
4 -- CS5600 University of Utah
6 -- mcgarvey@eng.utah.edu
9 -- This program that draws a scene multiple times from different camera angles
10 -- and positions. The rasters are saved in the `frames' directory, and if
11 -- ffmpeg is installed, they will also be combined into a video file. The
12 -- camera will make a full rotation along the X and Z axes, around a specified
13 -- point (center), all the while looking at some other point (look).
14 -- This must be called from the same directory where the rasterize program is.
16 local size
= {w
= 640, h
= 480} -- width and height of the viewport
17 local frames
= 512 -- number of animation frames
19 local look
= {x
= 2, y
= 1, z
= 2} -- the point to look at
20 local center
= {x
= 0, y
= 1, z
= 0} -- center of rotation
21 local distance
= 4 -- the distance from the center
22 local start
= math
.pi
-- where is the first frame
24 local jobs
= 6 -- number of concurrent renderings
26 -- the actual objects of the scene that will be drawn:
28 L 0 1000000 0 1 1 1 1 1 1
29 L 0 0 1000000 1 1 1 1 1 1
31 c 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1
35 c 0.7 0.3 0.2 0.8 0.2 0.1 0.9 0.2 0.2
39 c 0.1 0.2 0.7 0.1 0.3 0.9 0.2 0.1 0.8
43 c 0.9 0.8 0.9 0.8 0.7 0.9 0.9 0.8 0.7
53 function vec_add(a
, b
)
54 return {x
= a
.x
+ b
.x
, y
= a
.y
+ b
.y
, z
= a
.z
+ b
.z
}
57 function vec_scale(v
, s
)
58 return {x
= v
.x
* s
, y
= v
.y
* s
, z
= v
.z
* s
}
61 local fmt
= string.format
62 local write = function(...) io
.write(fmt(...)) end
66 local filename
= fmt("frames/anim%04d.bmp", i
)
67 local command
= fmt("./rasterize -o %s >/dev/null", filename
)
68 local out
= io
.popen(command
, "w")
69 write("\27[80D\27[2Kframe\t %4d / %d", i
+ 1, frames
)
79 ]], size
.w
, size
.h
, v
.x
, v
.y
, v
.z
, look
.x
, look
.y
, look
.z
, size
.w
/size
.h
, scene
))
80 i
, v
= coroutine
.yield()
86 print("Animating scene...")
90 table.insert(threads
, coroutine
.wrap(render
))
93 os
.execute("rm -rf frames && mkdir frames >/dev/null 2>&1")
94 for i
= 0,(frames
-1) do
95 local t
= start
+ 2 * math
.pi
* i
/ frames
101 v
= vec_add(vec_scale(v
, distance
), center
)
102 threads
[1 + (i
% jobs
)](i
, v
)
104 for _
,thread
in ipairs(threads
) do thread(null
) end
107 if os
.execute("ffmpeg -i frames/anim%04d.bmp -b 1024k -y -an scene.avi") == 0 then
108 print("Animation written to scene.avi.")
This page took 0.038863 seconds and 5 git commands to generate.