pixelflut 0.0.13 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/TODO.md DELETED
@@ -1,11 +0,0 @@
1
- # Pixelflut
2
-
3
- ## Todo
4
-
5
- - [x] limit connections _per IP_
6
- - [x] allow 10 (pixel-)actions per client
7
- - [ ] extend `pxf generate`
8
- - [x] add a pre-processor for images
9
- - [ ] mention the Gosu gem in the README
10
- - [ ] add `pxf info` command to get some server information
11
- - [ ] clarify that `pxf convert` require RMagick
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def options(cfg)
5
- require 'optparse'
6
- OptionParser.new do |opts|
7
- opts.summary_indent = ' '
8
- opts.banner = 'usage: pxf convert [options] IMAGE'
9
- opts.separator(nil)
10
- opts.separator('valid options:')
11
- opts.on('-x', '--transpose-x X', Integer, 'transpose image X pixels'){ |v| cfg[:offset_x] = v }
12
- opts.on('-y', '--transpose-y Y', Integer, 'transpose image Y pixels'){ |v| cfg[:offset_y] = v }
13
- opts.on('-w', '--width WIDTH', Integer, 'resize the image to given WIDTH'){ |v| cfg[:width] = v }
14
- opts.on('-h', '--height HEIGHT', Integer, 'resize the image to given HEIGHT'){ |v| cfg[:height] = v }
15
- end
16
- end
17
-
18
- def help(short)
19
- puts(options(nil), nil) unless short
20
- puts('Convert given IMAGE file to Pixelflut format.')
21
- exit
22
- end
23
-
24
- def err(msg, code = 1)
25
- $stderr.puts("pxf: #{msg}")
26
- exit(code)
27
- end
28
-
29
- def create_options
30
- {}.tap{ |cfg| options(cfg).parse! }
31
- rescue OptionParser::ParseError => e
32
- err(e)
33
- end
34
-
35
- help(false) if '--help' == ARGV[0]
36
- help(true) if '--short-help' == ARGV[0]
37
- options = create_options
38
- err('too few arguments') if ARGV.empty?
39
- require File.realdirpath('../../lib/pixelflut/converter.rb', __FILE__)
40
- err('unable to load library - RMagick') unless Pixelflut::Converter::AVAIL
41
- require File.realdirpath('../../lib/pixelflut/canvas/streamed.rb', __FILE__)
42
- begin
43
- canvas = Pixelflut::Canvas::Streamed.new($stdout)
44
- canvas.offset_x = options[:offset_x] if options[:offset_x]
45
- canvas.offset_y = options[:offset_y] if options[:offset_y]
46
- ARGV.each do |file_name|
47
- cvt = Pixelflut::Converter.new(file_name)
48
- cvt.resize_to(options[:width], options[:height]) if options[:width]
49
- cvt.draw(canvas)
50
- end
51
- rescue Pixelflut::Converter::Error => e
52
- err(e.message, 2)
53
- rescue Interrupt
54
- exit
55
- end
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def help(short)
5
- puts('usage: pxf generate FILE [FILE2, ...]', nil) unless short
6
- puts('Execute given generator FILEs.')
7
- end
8
-
9
- def extract_options(args)
10
- files, options = [], {}
11
- while !args.empty?
12
- arg = args.shift
13
- next files << arg unless arg[0] == '-'
14
- next options.merge!(Hash[arg[1..-1].chars.map!{ |c| [c.to_sym, true] }]) unless arg[1] == '-'
15
- options[arg[2..-1].to_sym] = args.shift
16
- end
17
- args[0, 0] = files
18
- options
19
- end
20
-
21
- case ARGV[0]
22
- when '--help'
23
- help(false)
24
- when '--short-help'
25
- help(true)
26
- else
27
- $options = extract_options(ARGV)
28
- require File.realdirpath('../../lib/pixelflut/canvas/streamed.rb', __FILE__)
29
- begin
30
- ARGV.each{ |file| Pixelflut::Canvas::Streamed.new.instance_eval(IO.read(file), file, 0) }
31
- print "QUIT\n"
32
- rescue Interrupt
33
- exit
34
- end
35
- end
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def help(short)
5
- puts('usage: pxf help COMMAND', nil) unless short
6
- puts('Print help for given COMMAND.')
7
- exit
8
- end
9
-
10
- def err(msg)
11
- $stderr.puts("pxf: #{msg}")
12
- exit(1)
13
- end
14
-
15
- help(false) if ARGV[0] == '--help'
16
- help(true) if ARGV[0] == '--short-help'
17
- root = File.realdirpath('../', __FILE__).freeze
18
- exec(File.join(root, 'pxf')) if ARGV.empty?
19
- ARGV.each do |cmd|
20
- fname = File.join(root, 'pxf-' + cmd)
21
- err("no such command - #{cmd}") unless File.executable?(fname)
22
- system(fname, '--help')
23
- end
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def options(cfg)
5
- require 'optparse'
6
- OptionParser.new do |opts|
7
- opts.summary_indent = ' '
8
- opts.banner = 'usage: pxf info [options]'
9
- opts.separator(nil)
10
- opts.separator('valid options:')
11
- opts.on('-h', '--host HOST', String, 'target host name (default localhost)'){ |v| cfg[:host] = v }
12
- opts.on('-p', '--port PORT', Integer, 'target port (default 1234)'){ |v| cfg[:port] = v }
13
- end
14
- end
15
-
16
- def help(short)
17
- puts(options(nil), nil) unless short
18
- puts('Get info about a Pixelflut server.')
19
- exit
20
- end
21
-
22
- def err(msg, code = 1)
23
- $stderr.puts("pxf: #{msg}")
24
- exit(code)
25
- end
26
-
27
- def create_options
28
- {port: 1234}.tap{ |cfg| options(cfg).parse! }
29
- rescue OptionParser::ParseError => e
30
- err(e)
31
- end
32
-
33
- help(false) if '--help' == ARGV[0]
34
- help(true) if '--short-help' == ARGV[0]
35
- options = create_options
36
- require File.realdirpath('../../lib/pixelflut/client/socket.rb', __FILE__)
37
- begin
38
- socket = Pixelflut::Client::Socket.new(Addrinfo.tcp(options[:host], options[:port]))
39
-
40
-
41
- err("unable to connect - #{options[:host]}:options[:port])", 2) unless socket.connect? || socket.wait_writable(5)
42
- err("server busy - #{options[:host]}:options[:port])", 3) unless socket.write_with_timout("SIZE\n", 5)
43
- line = socket.readline_with_timeout(5)
44
- socket.close
45
- err("server does not respond - #{options[:host]}:options[:port])", 4) unless line
46
- mark, width, height = line.split(' ', 3)
47
- width = width.to_i
48
- height = height.to_i
49
- err("no Pixelflut server - #{options[:host]}:options[:port])", 5) if mark != 'SIZE' || width <= 0 || height <= 0
50
- puts "canvas size: #{width}x#{height}"
51
- rescue SocketError, SystemCallError => e
52
- err(e.message, 2)
53
- rescue Interrupt
54
- exit
55
- end
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def options(cfg)
5
- require 'optparse'
6
- OptionParser.new do |opts|
7
- opts.summary_indent = ' '
8
- opts.banner = 'usage: pxf send [options] FILE'
9
- opts.separator(nil)
10
- opts.separator('valid options:')
11
- opts.on('-h', '--host HOST', String, 'target host name (default localhost)'){ |v| cfg[:host] = v }
12
- opts.on('-p', '--port PORT', Integer, 'target port (default 1234)'){ |v| cfg[:port] = v }
13
- opts.on('-c', '--connections COUNT', Integer, 'count of connections (default 8)'){ |v| cfg[:count] = v }
14
- end
15
- end
16
-
17
- def help(short)
18
- puts(options(nil), nil) unless short
19
- puts('Send given Pixelflut ASCII file to a server.')
20
- exit
21
- end
22
-
23
- def err(msg, code = 1)
24
- $stderr.puts("pxf: #{msg}")
25
- exit(code)
26
- end
27
-
28
- def create_options
29
- {port: 1234, count: 8}.tap{ |cfg| options(cfg).parse! }
30
- rescue OptionParser::ParseError => e
31
- err(e)
32
- end
33
-
34
- help(false) if '--help' == ARGV[0]
35
- help(true) if '--short-help' == ARGV[0]
36
- options = create_options
37
- require File.realdirpath('../../lib/pixelflut/client.rb', __FILE__)
38
- begin
39
- Pixelflut::Client.new(options[:host], options[:port], ARGF.readlines, options[:count]).run
40
- rescue SystemCallError => e
41
- err(e.message, 2)
42
- rescue Interrupt
43
- exit
44
- end
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def options(cfg)
5
- require 'optparse'
6
- OptionParser.new do |opts|
7
- opts.summary_indent = ' '
8
- opts.banner = 'usage: pxf server [options]'
9
- opts.separator(nil)
10
- opts.separator('valid options:')
11
- opts.on('-b', '--bind ADDR', String, 'bind address') do |v|
12
- cfg.server.host = v
13
- end
14
- opts.on('-p', '--port PORT', Integer, 'bind port(default: 1234)') do |v|
15
- cfg.server.port = v
16
- end
17
- opts.on('-k', '--keep-alive', Float, 'set maximum keep-alive time') do |v|
18
- cfg.server.keep_alive_time = v
19
- end
20
- opts.on('-r', '--read_buffer SIZE', Integer, 'set read buffer size (default: 1024)') do |v|
21
- cfg.server.read_buffer_size = v
22
- end
23
- opts.on('-l', '--peer-limit NUMBER', Integer, 'limit number of connections per peer (default: 8)') do |v|
24
- cfg.server.peer_limit = v
25
- end
26
- opts.on('-c', '--command-limit NUMBER', Integer, 'limit of continious processed commands (default: 10)') do |v|
27
- cfg.server.command_limit = v
28
- end
29
- opts.on('-w', '--width WIDTH', Integer, 'set canvas width (default: 800)') do |v|
30
- cfg.width = v
31
- end
32
- opts.on('-h', '--height HEIGHT', Integer, 'set canvas height (default: 600)') do |v|
33
- cfg.height = v
34
- end
35
- opts.on('-f', '--[no-]fullscreen', 'run in fullscreen mode') do |v|
36
- cfg.fullscreen = v
37
- end
38
- end
39
- end
40
-
41
- def help(short)
42
- puts(options(nil), nil) unless short
43
- puts('Start Pixelflut server.')
44
- exit
45
- end
46
-
47
- help(false) if ARGV[0] == '--help'
48
- help(true) if ARGV[0] == '--short-help'
49
-
50
- def create_configuration
51
- cfg = Pixelflut::App::Configuration.default
52
- options(cfg).parse!
53
- cfg
54
- rescue OptionParser::ParseError => e
55
- $stderr.puts("pxf: #{e}")
56
- exit(1)
57
- end
58
-
59
- begin
60
- require File.realdirpath('../../lib/pixelflut.rb', __FILE__)
61
- Pixelflut::App.run(create_configuration)
62
- rescue Interrupt
63
- exit
64
- end
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- def help(short)
5
- puts('usage: pxf version', nil) unless short
6
- puts('Print version information.')
7
- end
8
-
9
- case ARGV[0]
10
- when '--help'
11
- help(false)
12
- when '--short-help'
13
- help(true)
14
- else
15
- require File.realdirpath('../../lib/pixelflut/version.rb', __FILE__).freeze
16
- puts("pxf #{Pixelflut::VERSION}")
17
- end
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'gosu'
4
- require_relative 'server'
5
- require_relative 'text_image'
6
-
7
- module Pixelflut
8
- class App < Gosu::Window
9
- Configuration = Struct.new(:width, :height, :fullscreen, :server) do
10
- def self.default
11
- new(nil, nil, false, Server::Configuration.default)
12
- end
13
- end
14
-
15
- def self.run(configuration = Configuration.default)
16
- new(configuration).show
17
- end
18
-
19
- def initialize(configuration)
20
- if configuration.fullscreen
21
- super(configuration.width || Gosu.screen_width, configuration.height || Gosu.screen_height, fullscreen: true)
22
- else
23
- super(configuration.width || 800, configuration.height || 600)
24
- end
25
- Process.setproctitle('pxflut')
26
- @image = TextImage.new(width, height)
27
- @server = Server.new(@image, configuration.server)
28
- log(self.caption = "Pixelflut@#{configuration.server.host}:#{configuration.server.port}")
29
- log(configuration.server)
30
- reset!
31
- end
32
-
33
- def show
34
- @server.run
35
- super
36
- end
37
-
38
- def reset!
39
- @image.clear
40
- log("clean image: #{@image.width}x#{@image.height}")
41
- end
42
-
43
- def update
44
- # self.caption = @image.changes
45
- @draw_image = nil unless @image.changes.zero?
46
- end
47
-
48
- def draw
49
- (@draw_image ||= Gosu::Image.new(@image.changed, tileable: true, retro: true)).draw(0, 0, 0)
50
- end
51
-
52
- def log(*args)
53
- print("[#{Time.now}] ")
54
- puts(*args)
55
- end
56
-
57
- def button_down(id)
58
- return close! if Gosu::Button::KbEscape == id
59
- return reset! if Gosu::Button::KbSpace == id
60
- return log("connections: #{@server.connection_count}") if Gosu::Button::KbC == id
61
- end
62
-
63
- def close
64
- close!
65
- end
66
-
67
- def needs_redraw?
68
- @draw_image.nil?
69
- end
70
-
71
- def needs_cursor?
72
- false
73
- end
74
- end
75
- end
76
-
77
- begin
78
- Pixelflut::App.run
79
- rescue Interrupt
80
- exit
81
- end if __FILE__ == $PROGRAM_NAME
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'canvas/streamed'
4
- require_relative 'canvas/buffered'
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Pixelflut
4
- module Canvas
5
- class Base
6
- attr_accessor :offset_x, :offset_y
7
-
8
- def initialize
9
- clear!
10
- end
11
-
12
- def clear!
13
- @offset_x = @offset_y = 0
14
- @color = 'ffffffff'
15
- end
16
-
17
- def translate(x, y)
18
- ox, oy = @offset_x, @offset_y
19
- @offset_x += x
20
- @offset_y += y
21
- yield
22
- ensure
23
- @offset_x, @offset_y = ox, oy
24
- end
25
-
26
- def color(color)
27
- oc = @color
28
- @color = color
29
- yield
30
- ensure
31
- @color = oc
32
- end
33
-
34
- def []=(x, y, color)
35
- out("PX #{x(x)} #{y(y)} #{color}\n")
36
- end
37
-
38
- def pix(x, y, color = @color)
39
- out("PX #{x(x)} #{y(y)} #{color}\n")
40
- end
41
-
42
- def rect(x1, y1, x2, y2, color = @color)
43
- out("RC #{x(x1)} #{y(y1)} #{x(x2)} #{y(y2)} #{color}\n")
44
- end
45
-
46
- def line(x1, y1, x2, y2, color = @color)
47
- return rect(x1, y1, x2, y2, color) if x1 == x2 || y1 == y2
48
- x, y, curpixel = x1, y1, 0
49
- deltax = (x2 - x1).abs
50
- deltay = (y2 - y1).abs
51
- xinc1 = xinc2 = x2 >= x1 ? 1 : -1
52
- yinc1 = yinc2 = y2 >= y1 ? 1 : -1
53
- if deltax >= deltay
54
- xinc1 = yinc2 = 0
55
- den, numadd, numpixels, num = deltax, deltay, deltax, deltax / 2
56
- else
57
- xinc2 = yinc1 = 0
58
- den, numadd, numpixels, num = deltay, deltax, deltay, deltay / 2
59
- end
60
- while curpixel <= numpixels
61
- num += numadd
62
- if num >= den
63
- num -= den
64
- x += xinc1
65
- y += yinc1
66
- end
67
- x += xinc2
68
- y += yinc2
69
- pix(x, y, color)
70
- curpixel += 1
71
- end
72
- end
73
-
74
- def ascii(x, y, dim = 10, color = @color, pic = nil)
75
- pic ||= yield
76
- sx = x
77
- pic.each_line do |line|
78
- line.chomp!
79
- line.each_char do |c|
80
- rect(x, y, x + dim, y + dim, color) if ' ' != c && '_' != c
81
- x += dim
82
- end
83
- x = sx
84
- y += dim
85
- end
86
- end
87
-
88
- protected
89
-
90
- def x(x)
91
- x + @offset_x
92
- end
93
-
94
- def y(y)
95
- y + @offset_y
96
- end
97
- end
98
- end
99
- end