CacaANSICam

Aus C3D2
Version vom 28. Juni 2008, 16:03 Uhr von Astro (Diskussion | Beiträge)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

<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>


Speed metal coding 64x64.jpg
Rübÿ Spëëd Mëtäl Cödïng
Coders: Astro | Conny | Sven
Projects: CacaANSICam | Date Determinator | DVB-Scraping | Filmnächte-Scraping | GeeKal | Gruntmaster | Harvester | Hirn | Irb | Jargon-File | Ruby-MediaWiki | Miniwebserver | Momomoto | Pentabarf | Podcast-fetching | Ruby | Ruby-Geekend | Ruby und Ruby on Rails | Sedusa | VDS-Badges | Xmotoctl | Youtube-Scraping