ruby_svg_image_generator 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.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +11 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +11 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +109 -0
  9. data/Rakefile +8 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/ruby_svg_image_generator.rb +126 -0
  13. data/lib/ruby_svg_image_generator/color_part.rb +50 -0
  14. data/lib/ruby_svg_image_generator/part.rb +30 -0
  15. data/lib/ruby_svg_image_generator/theme.rb +67 -0
  16. data/lib/ruby_svg_image_generator/themes/face_avatars/background.rb +28 -0
  17. data/lib/ruby_svg_image_generator/themes/face_avatars/eyes.rb +28 -0
  18. data/lib/ruby_svg_image_generator/themes/face_avatars/face.rb +36 -0
  19. data/lib/ruby_svg_image_generator/themes/face_avatars/face_avatars.rb +12 -0
  20. data/lib/ruby_svg_image_generator/themes/face_avatars/hair.rb +109 -0
  21. data/lib/ruby_svg_image_generator/themes/face_avatars/mouth.rb +37 -0
  22. data/lib/ruby_svg_image_generator/themes/human_avatars/background.rb +38 -0
  23. data/lib/ruby_svg_image_generator/themes/human_avatars/background_2.rb +57 -0
  24. data/lib/ruby_svg_image_generator/themes/human_avatars/body.rb +38 -0
  25. data/lib/ruby_svg_image_generator/themes/human_avatars/complements.rb +194 -0
  26. data/lib/ruby_svg_image_generator/themes/human_avatars/eyes.rb +38 -0
  27. data/lib/ruby_svg_image_generator/themes/human_avatars/hair.rb +228 -0
  28. data/lib/ruby_svg_image_generator/themes/human_avatars/human_avatars.rb +13 -0
  29. data/lib/ruby_svg_image_generator/themes/human_avatars/mouth.rb +38 -0
  30. data/lib/ruby_svg_image_generator/themes/human_avatars/pants.rb +133 -0
  31. data/lib/ruby_svg_image_generator/themes/human_avatars/shirt.rb +208 -0
  32. data/lib/ruby_svg_image_generator/themes/human_avatars/shoes.rb +95 -0
  33. data/lib/ruby_svg_image_generator/themes/landscape_theme/background.rb +35 -0
  34. data/lib/ruby_svg_image_generator/themes/landscape_theme/clouds_back.rb +86 -0
  35. data/lib/ruby_svg_image_generator/themes/landscape_theme/clouds_front.rb +86 -0
  36. data/lib/ruby_svg_image_generator/themes/landscape_theme/flowers.rb +54 -0
  37. data/lib/ruby_svg_image_generator/themes/landscape_theme/ground.rb +35 -0
  38. data/lib/ruby_svg_image_generator/themes/landscape_theme/landscape_theme.rb +14 -0
  39. data/lib/ruby_svg_image_generator/themes/landscape_theme/mountains_back.rb +52 -0
  40. data/lib/ruby_svg_image_generator/themes/landscape_theme/mountains_front.rb +35 -0
  41. data/lib/ruby_svg_image_generator/themes/landscape_theme/river.rb +71 -0
  42. data/lib/ruby_svg_image_generator/themes/landscape_theme/sun.rb +87 -0
  43. data/lib/ruby_svg_image_generator/themes/landscape_theme/trees_1.rb +55 -0
  44. data/lib/ruby_svg_image_generator/themes/landscape_theme/trees_2.rb +55 -0
  45. data/lib/ruby_svg_image_generator/themes/landscape_theme/trees_3.rb +55 -0
  46. data/lib/ruby_svg_image_generator/themes/monkey_avatars/background.rb +34 -0
  47. data/lib/ruby_svg_image_generator/themes/monkey_avatars/clothes.rb +34 -0
  48. data/lib/ruby_svg_image_generator/themes/monkey_avatars/clothes_necks.rb +66 -0
  49. data/lib/ruby_svg_image_generator/themes/monkey_avatars/eyes.rb +100 -0
  50. data/lib/ruby_svg_image_generator/themes/monkey_avatars/face.rb +50 -0
  51. data/lib/ruby_svg_image_generator/themes/monkey_avatars/hats.rb +51 -0
  52. data/lib/ruby_svg_image_generator/themes/monkey_avatars/makeup.rb +84 -0
  53. data/lib/ruby_svg_image_generator/themes/monkey_avatars/monkey_avatars.rb +12 -0
  54. data/lib/ruby_svg_image_generator/themes/monkey_avatars/mouth.rb +83 -0
  55. data/lib/ruby_svg_image_generator/themes/monkey_avatars/nose.rb +50 -0
  56. data/lib/ruby_svg_image_generator/themes/monkey_avatars/skin.rb +34 -0
  57. data/lib/ruby_svg_image_generator/themes/monkey_avatars/wearable.rb +68 -0
  58. data/lib/ruby_svg_image_generator/themes/robot_avatars/antenna.rb +94 -0
  59. data/lib/ruby_svg_image_generator/themes/robot_avatars/arms.rb +144 -0
  60. data/lib/ruby_svg_image_generator/themes/robot_avatars/body.rb +44 -0
  61. data/lib/ruby_svg_image_generator/themes/robot_avatars/button_middle.rb +94 -0
  62. data/lib/ruby_svg_image_generator/themes/robot_avatars/buttons.rb +94 -0
  63. data/lib/ruby_svg_image_generator/themes/robot_avatars/chest.rb +119 -0
  64. data/lib/ruby_svg_image_generator/themes/robot_avatars/face.rb +144 -0
  65. data/lib/ruby_svg_image_generator/themes/robot_avatars/head.rb +94 -0
  66. data/lib/ruby_svg_image_generator/themes/robot_avatars/legs.rb +69 -0
  67. data/lib/ruby_svg_image_generator/themes/robot_avatars/robot_avatars.rb +12 -0
  68. data/lib/ruby_svg_image_generator/themes/test_theme/test_part_0.rb +29 -0
  69. data/lib/ruby_svg_image_generator/themes/test_theme/test_part_1.rb +33 -0
  70. data/lib/ruby_svg_image_generator/themes/test_theme/test_theme.rb +12 -0
  71. data/lib/ruby_svg_image_generator/version.rb +3 -0
  72. data/ruby_svg_image_generator.gemspec +37 -0
  73. data/tareas.txt +60 -0
  74. metadata +178 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5cfb1d1932bdef6e060e0be11a0c5936a0070705
4
+ data.tar.gz: e8907c90612a8240561044352031bc742fcdda1b
5
+ SHA512:
6
+ metadata.gz: 1adbbcb479ee7e6bf98fab43536bca12cbd5ce416476bf03e8aca4e4ec961b1ceae2e030a454b809bbadeb141ac32f05b30f26e4ff2f99bf835e7ab23bb0076b
7
+ data.tar.gz: ab86edc45f0b5769baccb8121c2c526a7c83a4b106cab98fdf23ebfc49bda60cb484673397071aa59618ed12e411511cbee04b09bc29ead497e13559481a9171
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test_*.svg
11
+ test.html
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.6
7
+ - 2.2.4
8
+ before_install:
9
+ - gem install bundler
10
+ notifications:
11
+ email: false
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'coveralls', :require => false
5
+ end
6
+
7
+ #group :development do
8
+ # gem 'debugger'
9
+ #end
10
+
11
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 santiriera626
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ # RubySvgImageGenerator
2
+
3
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/face0.svg" border="1" width="120">
4
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/face1.svg" border="1" width="120">
5
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/face2.svg" border="1" width="120">
6
+
7
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/human0.svg" border="1" width="120">
8
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/human1.svg" border="1" width="120">
9
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/human2.svg" border="1" width="120">
10
+
11
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/landscape0.svg" border="1" width="120">
12
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/landscape1.svg" border="1" width="120">
13
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/landscape2.svg" border="1" width="120">
14
+
15
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/monkey0.svg" border="1" width="120">
16
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/monkey1.svg" border="1" width="120">
17
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/monkey2.svg" border="1" width="120">
18
+
19
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/robots0.svg" border="1" width="120">
20
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/robots1.svg" border="1" width="120">
21
+ <img src="http://ruby_svg_generator.monkeykoders.net/images/robots2.svg" border="1" width="120">
22
+
23
+
24
+
25
+
26
+ [![Build Status](https://travis-ci.org/monkeyKoders/ruby_svg_image_generator.svg?branch=master)](https://travis-ci.org/monkeyKoders/ruby_svg_image_generator)
27
+ [![Coverage Status](https://coveralls.io/repos/github/monkeyKoders/ruby_svg_image_generator/badge.svg?branch=master)](https://coveralls.io/github/monkeyKoders/ruby_svg_image_generator?branch=master)
28
+ [![Code Climate](https://codeclimate.com/github/monkeyKoders/ruby_svg_image_generator/badges/gpa.svg)](https://codeclimate.com/github/monkeyKoders/ruby_svg_image_generator)
29
+
30
+ ruby_svg_image_generator is a great gem, created for you but specially for your web application users.
31
+
32
+ It is a SVG avatars generator gem based on themes which can be designed by users but also you can find some great pre-designed themes on it.
33
+
34
+ ## Demo App
35
+
36
+ We have implemented a demo app for you to try out: [Demo App](http://ruby_svg_generator.monkeykoders.net)
37
+
38
+ ## Installation
39
+
40
+ Add this line to your application's Gemfile:
41
+
42
+ ```ruby
43
+ gem 'ruby_svg_image_generator'
44
+ ```
45
+
46
+ And then execute:
47
+
48
+ $ bundle
49
+
50
+ Or install it yourself as:
51
+
52
+ $ gem install ruby_svg_image_generator
53
+
54
+ ## Usage
55
+
56
+ Create a random svg image from selected theme
57
+
58
+ RubySvgImageGenerator.create_random(title, options={})
59
+
60
+ title: (String) Created SVG image name
61
+ options: (Hash)
62
+ - theme: (String) Theme where you get the random image
63
+
64
+ Example: RubySvgImageGenerator.create_random('awesome_random_avatar', {theme: RubySvgImageGenerator::T_MONKEY_AVATARS})
65
+
66
+
67
+ Create a random svg image from selected theme and save on the file system
68
+
69
+ RubySvgImageGenerator.create_random_and_save(filename, title, options={})
70
+
71
+ filename: (String): Created SVG image file name
72
+ title: (String) Created SVG image name
73
+ options: (Hash)
74
+ - theme: (String) Theme where you get the random image
75
+
76
+ Example: RubySvgImageGenerator.create_random_and_save('image.svg', 'awesome_random_avatar', {theme: RubySvgImageGenerator::T_LANDSCAPE_THEME})
77
+
78
+ Create an image from selected theme and specific values for parts
79
+
80
+ RubySvgImageGenerator.create(title, options={})
81
+
82
+ title: (String) Created SVG image name
83
+ options: (Hash)
84
+ - theme: (String) Theme where you get the image
85
+ - parts: (Array) Array of index of parts' values which compose the theme
86
+
87
+ Example: RubySvgImageGenerator.create('awesome_avatar', {theme: RubySvgImageGenerator::T_FACE_AVATARS, parts: [0, 1, 5, 0, 1]})
88
+
89
+
90
+ Create an image from selected theme with specific values for parts and save on the file system
91
+
92
+ RubySvgImageGenerator.create_and_save(filename, title, options={})
93
+
94
+ filename: (String): Created SVG image file name
95
+ title: (String) Created SVG image name
96
+ options: (Hash)
97
+ - theme: (String) Theme where you get the image
98
+ - parts: (Array) Array of index of parts' values which compose the theme
99
+
100
+ Example: RubySvgImageGenerator.create('face_avatar.svg', 'awesome_avatar', {theme: RubySvgImageGenerator::T_FACE_AVATARS, parts: [0, 1, 5, 0, 1]})
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/monkeyKoders/ruby_svg_image_generator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
105
+
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
7
+
8
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_svg_image_generator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,126 @@
1
+ require 'ruby_svg_image_generator/version'
2
+ require 'ruby_matrix_to_svg'
3
+
4
+ require 'ruby_svg_image_generator/theme'
5
+ require 'ruby_svg_image_generator/part'
6
+ require 'ruby_svg_image_generator/color_part'
7
+
8
+ require 'ruby_svg_image_generator/themes/face_avatars/face_avatars'
9
+ require 'ruby_svg_image_generator/themes/human_avatars/human_avatars'
10
+ require 'ruby_svg_image_generator/themes/monkey_avatars/monkey_avatars'
11
+ require 'ruby_svg_image_generator/themes/landscape_theme/landscape_theme'
12
+ require 'ruby_svg_image_generator/themes/robot_avatars/robot_avatars'
13
+ require 'ruby_svg_image_generator/themes/test_theme/test_theme'
14
+
15
+ module RubySvgImageGenerator
16
+
17
+ T_HUMAN_AVATARS = :HumanAvatars
18
+ T_FACE_AVATARS = :FaceAvatars
19
+ T_MONKEY_AVATARS = :MonkeyAvatars
20
+ T_LANDSCAPE_THEME = :LandscapeTheme
21
+ T_ROBOT_AVATARS = :RobotAvatars
22
+ T_TEST_THEME = :TestTheme
23
+
24
+ DEFAULT_OPTIONS = {
25
+ :theme => T_TEST_THEME
26
+ }
27
+
28
+ THEMES = [T_HUMAN_AVATARS, T_FACE_AVATARS, T_LANDSCAPE_THEME, T_MONKEY_AVATARS, T_ROBOT_AVATARS]
29
+
30
+ # create an image svg and save it to the given filename
31
+ #
32
+ # Example:
33
+ # >> RubySvgImageGenerator.create_and_save('test_identicon.png', title, options)
34
+ # => result (Fixnum)
35
+ #
36
+ # @param filename [string] the full path and filename to save the image svg to
37
+ # @param title [string] the image svg title
38
+ # @param options [hash] additional options for the image
39
+ #
40
+ def self.create_and_save(filename, title, options={})
41
+
42
+ # create the svg image string
43
+ svg = create(title, options)
44
+
45
+ # save svg to file filename
46
+ File.open(filename, 'wb') { |f| f.write(svg) }
47
+
48
+ end
49
+
50
+ # create an image svg
51
+ #
52
+ # Example:
53
+ # >> RubySvgImageGenerator.create(title, options)
54
+ # => result (String)
55
+ #
56
+ # @param title [string] the image svg title
57
+ # @param options [hash] additional options for the image
58
+ #
59
+ def self.create(title, options={})
60
+
61
+ options = DEFAULT_OPTIONS.merge(options)
62
+
63
+ theme = RubySvgImageGenerator.const_get(options[:theme]).new
64
+
65
+ # generate the cells matrix with image
66
+ matrix = theme.get_matrix options[:parts]
67
+
68
+ # generate and return the svg string with matrix values
69
+ RubyMatrixToSvg.matrix_to_svg title, matrix
70
+ end
71
+
72
+ # create a random image svg and save it to the given filename
73
+ #
74
+ # Example:
75
+ # >> RubySvgImageGenerator.create_random_and_save('test_identicon.png', title, options)
76
+ # => result (Fixnum)
77
+ #
78
+ # @param filename [string] the full path and filename to save the image svg to
79
+ # @param title [string] the image svg title
80
+ # @param options [hash] additional options for the image
81
+ #
82
+ def self.create_random_and_save(filename, title, options={})
83
+
84
+ # create the svg image string
85
+ svg = create_random(title, options)
86
+
87
+ # save svg to file filename
88
+ File.open(filename, 'wb') { |f| f.write(svg) }
89
+
90
+ end
91
+
92
+ # create a random image svg
93
+ #
94
+ # Example:
95
+ # >> RubySvgImageGenerator.create_random( title, options)
96
+ # => result (String)
97
+ #
98
+ # @param title [string] the image svg title
99
+ # @param options [hash] additional options for the image
100
+ #
101
+ def self.create_random(title, options={})
102
+
103
+ options = DEFAULT_OPTIONS.merge(options)
104
+
105
+ theme = RubySvgImageGenerator.const_get(options[:theme]).new
106
+
107
+ # generate the cells matrix with image
108
+ matrix = theme.get_random_matrix
109
+
110
+ # generate and return the svg string with matrix values
111
+ RubyMatrixToSvg.matrix_to_svg title, matrix
112
+ end
113
+
114
+ # create a random image svg
115
+ #
116
+ # Example:
117
+ # >> RubySvgImageGenerator.get_theme_instance( RubySvgImageGenerator::T_HUMAN_AVATARS)
118
+ # => result (Theme)
119
+ #
120
+ # @param theme [constant] the image svg title
121
+ #
122
+ def self.get_theme_instance theme
123
+ return RubySvgImageGenerator.const_get(theme).new
124
+ end
125
+
126
+ end
@@ -0,0 +1,50 @@
1
+ module RubySvgImageGenerator
2
+ class Theme
3
+ class ColorPart < Part
4
+
5
+ def initialize(name)
6
+ super name
7
+ end
8
+
9
+ def each &block
10
+ matrix = []
11
+ self.class::MATRICES.each do |m|
12
+ matrix = Marshal.load(Marshal.dump(m)) # copiamos la matriz m
13
+ self.class::COLORS.each do |color|
14
+ matrix = change_cells matrix, 1, color
15
+ yield matrix
16
+ end
17
+ end
18
+ end
19
+
20
+
21
+ def [](index)
22
+ m = self.class::MATRICES[index/self.class::COLORS.count]
23
+ matrix = Marshal.load(Marshal.dump(m)) # copiamos la matriz m
24
+ color = self.class::COLORS[index%self.class::COLORS.count]
25
+
26
+ return change_cells matrix, 1, color
27
+ end
28
+
29
+ def get_matrix index
30
+ self[index]
31
+ end
32
+
33
+ def get_random_matrix
34
+ self[rand(self.count)]
35
+ end
36
+
37
+ private
38
+
39
+ def change_cells matrix, target_val, val
40
+ matrix.count.times do |row|
41
+ matrix[0].count.times do |col|
42
+ matrix[row][col] = val if matrix[row][col]==target_val
43
+ end
44
+ end
45
+ matrix
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ module RubySvgImageGenerator
2
+ class Theme
3
+ class Part
4
+ include Enumerable
5
+ def initialize(name)
6
+ @name = name
7
+ end
8
+
9
+ def each &block
10
+ self.class::MATRICES.each{|part| yield part }
11
+ end
12
+
13
+ def [](index)
14
+ return self.class::MATRICES[index]
15
+ end
16
+
17
+ def get_matrix index
18
+ self[index]
19
+ end
20
+
21
+ def get_random_matrix
22
+ self.class::MATRICES[rand(self.class::MATRICES.length)]
23
+ end
24
+
25
+ def name
26
+ @name
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,67 @@
1
+ module RubySvgImageGenerator
2
+ class Theme
3
+
4
+ include Enumerable
5
+
6
+ def initialize(name, n_cols, n_rows)
7
+ @name = name
8
+ @n_cols = n_cols
9
+ @n_rows = n_rows
10
+ @parts = []
11
+ @matrix = [[]]
12
+ end
13
+
14
+ def each &block
15
+ @parts.each{|part| yield part}
16
+ end
17
+
18
+ def [](index)
19
+ return @parts[index]
20
+ end
21
+
22
+ def get_matrix parts
23
+ l_parts = []
24
+ parts.each_with_index do |part, index|
25
+ l_parts << self[index].get_matrix(part)
26
+ end
27
+ merge_parts(l_parts)
28
+ end
29
+
30
+ def get_random_matrix
31
+ temp_parts = []
32
+ @parts.each do |part|
33
+ temp_parts << part.get_random_matrix
34
+ end
35
+
36
+ merge_parts(temp_parts)
37
+ end
38
+
39
+ def merge_parts(parts)
40
+ matrix = []
41
+ parts.each do |part|
42
+ n_rows.times do |col|
43
+ matrix[col] ||= Array.new(n_cols, "#ffffff")
44
+ n_cols.times do |row|
45
+ if part[col][row]!= 0
46
+ matrix[col][row] = part[col][row]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ matrix
52
+ end
53
+
54
+ def name
55
+ @name
56
+ end
57
+
58
+ def n_cols
59
+ @n_cols
60
+ end
61
+
62
+ def n_rows
63
+ @n_rows
64
+ end
65
+
66
+ end
67
+ end