rubatar 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 00be07b048a722189ce2b6765f5feb3870f685cb
4
+ data.tar.gz: cbdad968fcadfd4e3e6c0faac147c1b0102d1db3
5
+ SHA512:
6
+ metadata.gz: 4b76d3384ee0cfae03ea2b3e2e0a8b7eded9cd8d93b3dc265b52c26448f992cb1cf840f917c00c509408d4be484e7d51fb72ccbe9ac5c87cadd7c65115afa4dd
7
+ data.tar.gz: 5d9dfa4545e8442a966f880b0bcce60b5f9a3ff260fa3a8b595acf0d2e5945f369f8e79010c5ebb9e2a5bc28578214aa05bc353a511fee1d146df79ae25fa5be
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ .idea/
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'chunky_png', '~> 1.3.1'
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Felix Kaaman
2
+
3
+ This software is provided 'as-is', without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+
19
+ 3. This notice may not be removed or altered from any source
20
+ distribution.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rubatar
2
+
3
+ Generates random 5x5 avatars.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubatar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubatar
18
+
19
+ ## Usage
20
+
21
+ rubatar -w128 -h128 -oavatar.png
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it [here](https://github.com/psuhh/rubatar/fork)
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/rubatar ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ $:.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
5
+
6
+ require 'rubatar'
7
+ require 'optparse'
8
+
9
+ OptionParser.new do |o|
10
+ o.on('-w WIDTH') { |w| $width = w.to_i }
11
+ o.on('-h HEIGHT') { |h| $height = h.to_i }
12
+ o.on('-o OUTPUT') { |output| $output = output }
13
+ o.on('--help') { puts o; exit }
14
+ o.parse!
15
+ end
16
+
17
+ avatar = Rubatar::Avatar.new($width, $height, $output)
18
+ avatar.generate
19
+ avatar.save
@@ -0,0 +1,46 @@
1
+ require 'chunky_png'
2
+
3
+ module Rubatar
4
+ class Avatar
5
+ attr_accessor :width, :height, :output
6
+
7
+ def initialize(width, height, output)
8
+ @width = width
9
+ @height = height
10
+ @output = output
11
+ @img = ChunkyPNG::Image.new(5, 5)
12
+ @color = ChunkyPNG::Color.parse(Hash.seed)
13
+ end
14
+
15
+ def size=(width, height)
16
+ @width = width
17
+ @height = height
18
+ end
19
+
20
+ def generate
21
+ data = Array.new(25, 0)
22
+ (0..5).each do |y|
23
+ (0..5).each do |x|
24
+ if x < 3
25
+ data[x + y * 5] = (Hash::rand & 0x1).zero? ? 1 : 0
26
+ else
27
+ data[x + y * 5] = data[(4 - x) + y * 5];
28
+ end
29
+ end
30
+ end
31
+
32
+ data.each_with_index do |val, idx|
33
+ unless val.zero?
34
+ @img.set_pixel(idx % 5, idx / 5, @color)
35
+ end
36
+ end
37
+ end
38
+
39
+ def save
40
+ #copy_img = ChunkyPNG::Image.new(5, 5)
41
+ #copy_img.initialize_copy(@img)
42
+ @img.resample_nearest_neighbor!(@width, @height)
43
+ @img.save(@output)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ module Rubatar
2
+ module Hash
3
+ attr_reader :inc
4
+
5
+ @@inc = Random::rand((2**(0.size * 8 -2) -1))
6
+
7
+ def self.rand
8
+ taps = 0x80306031
9
+ seed = @@inc
10
+ unless (seed & 0x1).zero?
11
+ seed = (1 << 31) | ((seed ^ taps) >> 1)
12
+ else
13
+ seed = seed >> 1
14
+ end
15
+ @@inc = seed
16
+ seed
17
+ end
18
+
19
+ def self.seed
20
+ @@inc
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Rubatar
2
+ VERSION = '0.0.1'
3
+ end
data/lib/rubatar.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'rubatar/version'
2
+ require 'rubatar/avatar'
3
+ require 'rubatar/hash'
data/rubatar.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+ require 'rubatar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rubatar'
8
+ spec.version = Rubatar::VERSION
9
+ spec.authors = 'Felix Kaaman'
10
+ spec.email = 'trundmatu@gmail.com'
11
+ spec.summary = 'Generates random 5x5 avatars.'
12
+ spec.homepage = 'http://www.github.com/psuhh/rubatar'
13
+ spec.license = 'zlib'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'rake'
22
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubatar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Felix Kaaman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email: trundmatu@gmail.com
43
+ executables:
44
+ - rubatar
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - bin/rubatar
54
+ - lib/rubatar.rb
55
+ - lib/rubatar/avatar.rb
56
+ - lib/rubatar/hash.rb
57
+ - lib/rubatar/version.rb
58
+ - rubatar.gemspec
59
+ homepage: http://www.github.com/psuhh/rubatar
60
+ licenses:
61
+ - zlib
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Generates random 5x5 avatars.
83
+ test_files: []
84
+ has_rdoc: