c3d2-wiki/CacaANSICam.mw

49 lines
1.0 KiB
Plaintext

<source lang="ruby">#!/usr/bin/env ruby
require 'cucul'
require 'V4l'
require 'socket'
SHRINK_X = 5
SHRINK_Y = 10
Thread::abort_on_exception = true
current = ''
current_lock = Mutex.new
Thread.new {
vid = V4l.new('/dev/video')
cucul = Cucul::Canvas.new(vid.width / SHRINK_X, vid.height / SHRINK_Y)
d = Cucul::Dither::new(24, vid.width, vid.height, 3 * vid.width, 0xff, 0xff00, 0xff0000, 0)
d.antialias = 'prefilter'
d.algorithm = 'fstein'
d.brightness = 0.5
d.gamma = 1.2
loop do
f = vid.get_frame
cucul.dither_bitmap(0, 0, vid.width / SHRINK_X, vid.height / SHRINK_Y, d, f)
current_lock.synchronize {
current = cucul.export_memory('ansi')
}
end
}
s = TCPServer.new(2323)
while (c = s.accept)
puts "accepted #{c.peeraddr.inspect}"
Thread.new {
begin
loop do
current_lock.synchronize {
c.puts "\e[2J#{current}"
c.flush
}
sleep 0.5
end
rescue Errno::EPIPE
rescue Errno::ECONNRESET
end
}
end
</source>
[[Category:Ruby]]
{{Rübÿ Spëëd Mëtäl Cödïng}}