This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Left4Cake's profile picture

ascii video player

Started by Left4Cake, 01 October 2012 - 10:31 PM
Left4Cake #1
Posted 02 October 2012 - 12:31 AM
This is an attempted at making an ascii video play for Computer-craft. The basic format for the video is

movie/format
movie/frames

In the frames file make each frame as it should be displayed (new lines and all) and for each frame put <new frame> on a line separating the two frames. You can also put <change rate #> to change rate to #.

In format you will have to define:to loop forever or not, the amount of time between frames, and the width/height.

Sample video is now nyancat. Just put it on the computer you run the program on.


shell.run( "movie/format" )
local w,h = term.getSize()
while loop do
local sPath = shell.resolve( "movie/frames")
tLines = {}
if fs.exists( sPath ) then
local file = io.open( sPath, "r" )
local sLine = file:read()
shell.run( "clear" )
line = 0
while sLine do
local startX = math.floor( (w - vw) / 2 )
local startY = math.floor( (h - vh) / 2 )
if sLine == "<new frame>" or string.find(sLine, "<change rate ") then
if string.find(sLine, "<change rate ") then
newrate = string.gsub(sLine, "<change rate ", "")
newrate = string.gsub(newrate, ">", "")
rate = newrate * 1
end
line = 0
sleep(rate)
	   else
		term.setCursorPos(startX, startY + line)
term.write( sLine )
line = line + 1
end
sLine = file:read()

end
file:close()
end
end
shell.run( "clear" )

jag #2
Posted 02 October 2012 - 12:43 AM
Cool!
Lyqyd #3
Posted 02 October 2012 - 01:36 AM
As poorly as this is set up (storing each frame in its own file?!), I'd say this may be verging on malicious. There's a reason the included ASCII movie keeps its frames inside the program file.
Left4Cake #4
Posted 02 October 2012 - 03:03 AM
(storing each frame in its own file?!)

Good point. I fixed that now.
D3matt #5
Posted 02 October 2012 - 03:22 AM
As poorly as this is set up (storing each frame in its own file?!), I'd say this may be verging on malicious. There's a reason the included ASCII movie keeps its frames inside the program file.
I think that's just a bit of an exxageration, don't you?
Lyqyd #6
Posted 02 October 2012 - 05:08 AM
That's some pretty hefty unnecessary IO load. Depending on the rate (let's say 30Hz), you're looking at thirty different hard drive seeks per second, for extremely tiny files (sub-sector). One minute of video would be 30 * 60 frames, or 1800 tiny individual files. An animation that's much longer and you start getting into ridiculous quantities of tiny files. So, no. I don't think it's entirely in the realm of the benign. Perhaps not malicious as such, but the code is (was?) not good code.

It's far better to store each frame in a table in a single file and then simply display each frame of the table.