Initial commit

This commit is contained in:
Sasha Koshka 2022-12-03 16:12:39 -05:00
commit 221de059e5
6 changed files with 104 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/video.bin
/png

40
badapple.lua Normal file
View File

@ -0,0 +1,40 @@
local monitor = peripheral.find("monitor")
monitor.setTextScale(0.5)
videoFile = fs.open("video.bin", "rb")
videoData = videoFile.readAll()
monitor.clear()
function drawFrame (frame)
local byteIndex = frame * 24 * 3
for y = 1, 24 do
monitor.setCursorPos(5, y + 2)
for x = 1, 3 do
byteIndex = byteIndex + 1
drawByte(videoData:byte(byteIndex))
end
end
end
function drawByte (byte)
local divisor = 0x80
for i = 1, 8 do
local bit = ((byte / divisor) % 2) >= 1
if bit then
monitor.setBackgroundColor(colors.white)
else
monitor.setBackgroundColor(colors.black)
end
monitor.write(" ")
divisor = divisor / 2
end
end
for index = 1, 2516 do
drawFrame(index)
os.sleep(0.1)
-- os.sleep(0.5)
end

7
convert.sh Normal file
View File

@ -0,0 +1,7 @@
echo "extracting frames"
mkdir -p png
ffmpeg -i vid.mp4 -vf fps=8 png/%d.png
echo "resizing"
magick mogrify -resize 24x24 png/*.png
echo "packing"
go run .

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.tebibyte.media/sashakoshka/badapple-cc
go 1.19

52
main.go Normal file
View File

@ -0,0 +1,52 @@
package main
import "os"
import "io"
import "log"
import "fmt"
import "image"
import _ "image/png"
func main () {
output, err := os.OpenFile("video.bin", os.O_CREATE | os.O_WRONLY | os.O_TRUNC, 0644)
if err != nil { log.Fatal(err) }
for frame := 1; frame <= 2516; frame ++ {
input, err := os.Open(fmt.Sprintf("png/%d.png", frame))
if err != nil { log.Fatal(err) }
err = convert(input, output)
if err != nil { log.Fatal(err) }
input.Close()
}
output.Close()
}
func convert (input io.Reader, output io.Writer) (err error) {
var im image.Image
im, _, err = image.Decode(input)
if err != nil { return err }
buffer := [72]byte { }
index := 0
for y := 0; y < 24; y ++ {
bit := byte(0)
for x := 0; x < 24; x ++ {
red, _, _, _ := im.At(x, y).RGBA()
bitState := byte(0)
if red > 0x8000 { bitState = 1 }
buffer[index] |= bitState << (7 - bit)
bit ++
if bit >= 8 {
bit = 0
index ++
}
}
}
output.Write(buffer[:])
return
}

BIN
vid.mp4 Normal file

Binary file not shown.