ascii_art 0.4.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e465c17c093866118f5d4323bc350c37729d1712
4
+ data.tar.gz: 5e8022b32b4e1c45c7cad83de1bf9b752ad26bd9
5
+ SHA512:
6
+ metadata.gz: 82728e777271005239312d6c6333b0f37b09c3e2d7e9515c2baabbf41743a4ac49b7df436f6aaa0e61a61ff92691dca37fac5e29dc2daa3dba6e8a9603763614
7
+ data.tar.gz: 181dcecdd96bdfb909b9b09633007870c1e86d21fe22d71f8e5cb3b41550011b5262e59edea6d496ad2b4e9d5e18049bbef1e314171d95b0720c144801ece67b
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
16
+ drawing.txt
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'curses'
6
+ gem 'commander'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chris C Cerami
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ascii_art.svg)](http://badge.fury.io/rb/ascii_art)
2
+
3
+ # ASCII Art
4
+
5
+ ```
6
+ __________ ____ __________________.___.
7
+ \______ \ | \______ \__ | |
8
+ | _/ | /| | _// | |
9
+ | | \ | / | | \\____ |
10
+ |____|_ /______/ |______ // ______|
11
+ \/ \/ \/
12
+ _____ __________________ .___.___ _____ _____________________
13
+ / _ \ / _____/\_ ___ \| | | / _ \\______ \__ ___/
14
+ / /_\ \ \_____ \ / \ \/| | | / /_\ \| _/ | |
15
+ / | \/ \\ \___| | | / | \ | \ | |
16
+ \____|__ /_______ / \______ /___|___|____\____|__ /____|_ / |____|
17
+ \/ \/ \/ /_____/ \/ \/
18
+ ```
19
+
20
+ ## Description
21
+
22
+ The ascii_art gem will allow you to turn your terminal into a canvas for creating images with ASCII characters.
23
+
24
+ ## Installation
25
+
26
+ Install the gem with:
27
+
28
+ $ gem install ascii_art
29
+
30
+ ## Usage
31
+
32
+ To open a new canvas, simply use:
33
+
34
+ ```ruby
35
+ AsciiArt.start
36
+ ```
37
+
38
+ or from the command line:
39
+
40
+ ```
41
+ $ ascii_art start
42
+ ```
43
+
44
+ This will open a blank canvas on which you can start drawing.
45
+
46
+ ### Key Commands
47
+
48
+ Key | Action
49
+ ----------------------|--------------------------------------
50
+ Arrows | Move the cursor around the screen
51
+ `tab` | "Lift" the brush so you can move the cursor without marking the canvas
52
+ `p` | "Print" the drawing, saving it to a `drawing.txt` file in your current directory
53
+ Other character keys | Change the character being drawn
54
+ `esc` | Quit the program
55
+
56
+ If you would like to specify a different file to which your drawing should be saved, you can use the -f or --file option on the command line:
57
+
58
+ ```
59
+ $ ascii_art start -f my_drawing.txt
60
+ ```
61
+ ```
62
+ $ ascii_art start --file best_art.txt
63
+ ```
64
+
65
+ If you'd like to continue working on a drawing you've started previously, you can load files into the app using the `scan` command:
66
+
67
+ ```
68
+ $ ascii_art scan an_old_drawing.txt
69
+ ```
70
+
71
+ and can still use the -f option to set the print destination:
72
+
73
+ ```
74
+ $ ascii_art scan an_old_drawing.txt -f my_new_masterpiece.txt
75
+ ```
76
+
77
+ This will read the file you specify and draw its contents to a new canvas. In order to prevent overwriting any of your beautiful handiwork, the brush will start in the lifted position, and can be lowered with the `tab` key.
78
+
79
+ ## Contributing
80
+
81
+ If you would like to contribute to AsciiArt, feel free to create a
82
+ pull request. If you'd like to contact me, you can reach me at
83
+ [chrisccerami@gmail.com](mailto:chrisccerami@gmail.com) or on
84
+ Twitter [@chrisccerami](https://twitter.com/chrisccerami).
85
+
86
+ 1. Fork it ( https://github.com/chrisccerami/ascii_art/fork )
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create a new Pull Request
91
+
92
+ ## License
93
+
94
+ Copyright (c) 2015 Chris C Cerami
95
+
96
+ MIT License
97
+
98
+ Permission is hereby granted, free of charge, to any person obtaining
99
+ a copy of this software and associated documentation files (the
100
+ "Software"), to deal in the Software without restriction, including
101
+ without limitation the rights to use, copy, modify, merge, publish,
102
+ distribute, sublicense, and/or sell copies of the Software, and to
103
+ permit persons to whom the Software is furnished to do so, subject to
104
+ the following conditions:
105
+
106
+ The above copyright notice and this permission notice shall be
107
+ included in all copies or substantial portions of the Software.
108
+
109
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
110
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
111
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
112
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
113
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
114
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
115
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
6
+
7
+ task :console do
8
+ exec "irb -r ascii_art -I ./lib"
9
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ascii_art/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ascii_art"
8
+ spec.version = AsciiArt::VERSION
9
+ spec.authors = ["Chris C Cerami"]
10
+ spec.email = ["chrisccerami@gmail.com"]
11
+ spec.date = '2015-07-17'
12
+ spec.summary = "A command line app for drawing and saving ASCII art"
13
+ spec.description = "Using this gem, you can create ASCII style drawings in your command line, which you can choose to save to a .txt file."
14
+ spec.homepage = "http://rubygems.org/gems/ascii_art"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_path = "lib"
21
+
22
+ spec.required_ruby_version = '~> 2.0'
23
+
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_runtime_dependency 'curses'
27
+ spec.add_runtime_dependency 'commander', '~> 4.3'
28
+ end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'ascii_art'
6
+ require 'ascii_art/version'
7
+
8
+ program :version, AsciiArt::VERSION
9
+ program :description, 'A command line app for drawing and saving ASCII art'
10
+
11
+ command :start do |c|
12
+ c.syntax = 'ascii_art start [options]'
13
+ c.summary = 'Open a new canvas to begin drawing'
14
+ c.description = c.summary
15
+ c.example 'Starts the ascii_art program', 'ascii_art start'
16
+ c.example 'Starts the app with a custom save filename', 'ascii_art start -f my_file.txt'
17
+ c.option '-f', '--file FILENAME', String, 'Change the filename where your art will be saved'
18
+ c.action do |args, options|
19
+ AsciiArt.start(options.file)
20
+ end
21
+ end
22
+
23
+ command :scan do |c|
24
+ c.syntax = 'ascii_art scan [options]'
25
+ c.summary = 'Load a txt file to continue drawing'
26
+ c.description = c.summary
27
+ c.example 'Starts the app with a drawing preloaded from a txt file', 'ascii_art scan my_file.txt'
28
+ c.option '-f', '--file FILENAME', String, 'Change the filename where your art will be saved'
29
+ c.action do |args, options|
30
+ AsciiArt.start_with_scan(args.first, options.file)
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # external dependencies
2
+ require 'curses'
3
+ require 'singleton'
4
+
5
+ # internal dependencies
6
+ require 'ascii_art/painter'
7
+ require 'ascii_art/canvas'
8
+ require 'ascii_art/brush'
9
+ require 'ascii_art/printer'
10
+ require 'ascii_art/scanner'
11
+
12
+ module AsciiArt
13
+ def self.start(filename=nil)
14
+ Painter.new(filename).paint
15
+ end
16
+
17
+ def self.start_with_scan(load_file, print_file=nil)
18
+ Painter.new(print_file).load_drawing(load_file)
19
+ end
20
+ end
@@ -0,0 +1,36 @@
1
+ module AsciiArt
2
+ class Brush
3
+ attr_accessor :stroke, :x_pos, :y_pos, :lifted
4
+ def initialize(stroke, x, y)
5
+ @stroke = stroke
6
+ @x_pos = x
7
+ @y_pos = y
8
+ @lifted = false
9
+ end
10
+
11
+ def raise_or_lower
12
+ @lifted = !@lifted
13
+ end
14
+
15
+ def move(x, y)
16
+ @x_pos = x
17
+ @y_pos = y
18
+ end
19
+
20
+ def move_up
21
+ move(@x_pos, @y_pos - 1)
22
+ end
23
+
24
+ def move_down
25
+ move(@x_pos, @y_pos + 1)
26
+ end
27
+
28
+ def move_left
29
+ move(@x_pos - 1, @y_pos)
30
+ end
31
+
32
+ def move_right
33
+ move(@x_pos + 1, @y_pos)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ module AsciiArt
2
+ class Canvas
3
+ include Curses
4
+ include Singleton
5
+
6
+ attr_accessor :surface
7
+
8
+ def initialize
9
+ noecho
10
+ @surface = init_screen
11
+ stdscr.keypad = true
12
+ end
13
+
14
+ def close
15
+ close_screen
16
+ exit
17
+ end
18
+
19
+ def move(x, y)
20
+ setpos(y, x)
21
+ end
22
+
23
+ def paint(x, y, string)
24
+ move(x, y)
25
+ addstr(string)
26
+ end
27
+
28
+ def accept_input
29
+ loop do
30
+ return getch
31
+ end
32
+ end
33
+
34
+ def clear(x, y)
35
+ move(x, y)
36
+ delch
37
+ insch(' ')
38
+ end
39
+
40
+ def read_at_cursor
41
+ inch
42
+ end
43
+
44
+ def line_count
45
+ lines
46
+ end
47
+
48
+ def column_count
49
+ cols
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,80 @@
1
+ module AsciiArt
2
+ require_relative 'canvas'
3
+ class Painter
4
+ def initialize(print_file=nil)
5
+ @canvas = Canvas.instance
6
+ @brush = Brush.new('.', 0, 0)
7
+ @print_file = print_file
8
+ @printer
9
+ @scanner
10
+ at_exit { canvas.close }
11
+ end
12
+
13
+ COMMAND_KEYS = [
14
+ Canvas::KEY_UP,
15
+ Canvas::KEY_DOWN,
16
+ Canvas::KEY_LEFT,
17
+ Canvas::KEY_RIGHT,
18
+ 9, # tab key character code
19
+ 27, # esc key character code
20
+ 'p'
21
+ ]
22
+
23
+ def paint
24
+ canvas.paint(brush.x_pos, brush.y_pos, brush.stroke)
25
+ command_loop
26
+ end
27
+
28
+ def load_drawing(filename)
29
+ Scanner.new(filename).scan
30
+ brush.lifted = true
31
+ move_brush
32
+ command_loop
33
+ end
34
+
35
+ def command_loop
36
+ loop do
37
+ follow_commands
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ attr_accessor :scanner
44
+ attr_reader :canvas, :brush, :printer, :print_file
45
+
46
+ def follow_commands
47
+ char = canvas.accept_input
48
+ if COMMAND_KEYS.include?(char)
49
+ system_commands(char)
50
+ else
51
+ brush.stroke = char
52
+ end
53
+ move_brush
54
+ end
55
+
56
+ def move_brush
57
+ if brush.lifted
58
+ canvas.move(brush.x_pos, brush.y_pos)
59
+ else
60
+ canvas.paint(brush.x_pos, brush.y_pos, brush.stroke)
61
+ end
62
+ end
63
+
64
+ def system_commands(char)
65
+ inputs = {
66
+ Canvas::KEY_UP => proc { brush.move_up },
67
+ Canvas::KEY_LEFT => proc { brush.move_left },
68
+ Canvas::KEY_DOWN => proc { brush.move_down },
69
+ Canvas::KEY_RIGHT => proc { brush.move_right },
70
+ 9 => proc { brush.raise_or_lower },
71
+ 27 => proc { canvas.close },
72
+ 'p' => proc {
73
+ printer = Printer.new(print_file ||= 'drawing.txt')
74
+ printer.print
75
+ }
76
+ }
77
+ inputs[char].call
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,23 @@
1
+ module AsciiArt
2
+ require_relative 'canvas'
3
+ class Printer
4
+ attr_accessor :canvas, :lines, :columns, :file
5
+ def initialize(filename)
6
+ @canvas = Canvas.instance
7
+ @lines = @canvas.line_count
8
+ @columns = @canvas.column_count
9
+ @file = File.new(filename, 'w')
10
+ end
11
+
12
+ def print
13
+ (0..lines - 1).each do |y|
14
+ (0..columns - 1).each do |x|
15
+ canvas.move(x, y)
16
+ file.write(canvas.read_at_cursor.chr)
17
+ end
18
+ file.write("\n")
19
+ end
20
+ file.close
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module AsciiArt
2
+ class Scanner
3
+ require_relative 'canvas'
4
+
5
+ attr_accessor :filename
6
+ attr_reader :drawing
7
+ def initialize(filename)
8
+ @filename = filename
9
+ @drawing
10
+ end
11
+
12
+ def scan
13
+ row = 0
14
+ open_file.each_line do |line|
15
+ Canvas.instance.paint(0, row, line)
16
+ row += 1
17
+ end
18
+ end
19
+
20
+ def open_file
21
+ File.open(filename, "r")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module AsciiArt
2
+ VERSION = "0.4.2"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ascii_art
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
+ platform: ruby
6
+ authors:
7
+ - Chris C Cerami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: curses
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: commander
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.3'
55
+ description: Using this gem, you can create ASCII style drawings in your command line,
56
+ which you can choose to save to a .txt file.
57
+ email:
58
+ - chrisccerami@gmail.com
59
+ executables:
60
+ - ascii_art
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - ascii_art.gemspec
70
+ - bin/ascii_art
71
+ - lib/ascii_art.rb
72
+ - lib/ascii_art/brush.rb
73
+ - lib/ascii_art/canvas.rb
74
+ - lib/ascii_art/painter.rb
75
+ - lib/ascii_art/printer.rb
76
+ - lib/ascii_art/scanner.rb
77
+ - lib/ascii_art/version.rb
78
+ homepage: http://rubygems.org/gems/ascii_art
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A command line app for drawing and saving ASCII art
102
+ test_files: []