ruby_randimage 0.0.1 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ce89af65e49ca8cf464c82df4a4ee47abae37862
4
- data.tar.gz: 01144f970a0d3215acb4d57aac44fa8b92f89f78
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjEyMDg4NmY1MTVhNjg2OWQxNzUxZjljNjZmMzc1MTVlMDQzODgwOA==
5
+ data.tar.gz: !binary |-
6
+ NjFkYTU5Y2JkNGExZmE0MTNiMzQ0ZTc0ZTg3NTEyNmMwYTRiOGUwYQ==
5
7
  SHA512:
6
- metadata.gz: dd3b7a1ffede928a9c93bfcba90b19e3a5e80835ca20676e4c5f1efa47b330d37fcfa4924d4559b3324ff172471c8e902b9c781c3e6e015f72b69a17a36948b2
7
- data.tar.gz: 9ee16895fd94d03332bac1cdfdfc731126d3dc48a52f5aa638abc773e0d7ad972f7af77e0c39cf8f9afb7da634ec623702bed105001cfa92adde2eaaad2344a6
8
+ metadata.gz: !binary |-
9
+ OGViMTFhMTc2ZjgzMTg0MDczOGJiN2RiNjdmZWVkMmEzNDYxYjc4ZDUwZTRi
10
+ YTk4MmVlYjQ1YWI0NjJhZGQ4YjU3NGQ5Y2U4NGZhYTk3ODhlYThjNTAzNWEz
11
+ MTgzM2M4MjIzMzIxZTA2M2E2ZWM2ZmFlODczMmIyMDhmYTBkZmI=
12
+ data.tar.gz: !binary |-
13
+ ODhkYzlhNTkyZWUwNGRkYjE3MzU4ZjViYWMxMmRjMzc2NTdlZGYxZTUxMWUz
14
+ NjhjNDVjYzU3MTVkYmFhNDMwMzJiMmUyYWUxMjJjZTUxZGJhYTFhNDA2NTI0
15
+ Y2FkZWYwNTRkZTUxNDQ2YTRmZDkyZWE0NTJiYzBiZDA3MTQ4NzI=
data/.gitignore CHANGED
@@ -8,6 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  temp_image_*
11
+ test_index.html
11
12
  .ruby-version
12
13
  .ruby-gemset
13
- .byebug_history
14
+ .byebug_history
data/Gemfile CHANGED
@@ -4,10 +4,4 @@ group :test do
4
4
  gem 'coveralls', :require => false
5
5
  end
6
6
 
7
- #group :development do
8
- #TODO: [sriera] quitar estas gemas antes del nuild
9
- # gem 'byebug'
10
- #end
11
-
12
- # Specify your gem's dependencies in ruby_randimage.gemspec
13
7
  gemspec
data/README.md CHANGED
@@ -5,9 +5,13 @@
5
5
  [![Code Climate](https://codeclimate.com/github/santiriera626/ruby_randimage/badges/gpa.svg)](https://codeclimate.com/github/santiriera626/ruby_randimage)
6
6
  [![security](https://hakiri.io/github/santiriera626/ruby_randimage/master.svg)](https://hakiri.io/github/santiriera626/ruby_randimage/master)
7
7
 
8
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_randimage`. To experiment with that code, run `bin/console` for an interactive prompt.
9
8
 
10
- TODO: Delete this and the text above, and describe your gem
9
+ Are you looking for an amazing avatar generator for your website users? ruby_randimage is your gem!
10
+
11
+ A powerful, customizable and sophisticated awesome SVG avatars generator from several options such as symmetries, size, color palette and color densities.
12
+
13
+ RubyRandimage is a pure Ruby library without any dependencies.
14
+
11
15
 
12
16
  ## Installation
13
17
 
@@ -27,17 +31,43 @@ Or install it yourself as:
27
31
 
28
32
  ## Usage
29
33
 
30
- TODO: Write usage instructions here
34
+ Create a random svg image saved on the file system.
35
+
36
+ RubyRandimage.create_and_save_file("ruby_randimage.svg")
37
+
38
+ Create a random svg image String
39
+
40
+ svg = RubyRandimage.create
41
+
42
+ Returned String can be used in a simple way in your HTML document settting a size for your image
43
+
44
+ <img src="data:image/svg+xml;utf8, <%= raw(svg) %>" width="200px">
45
+
46
+ ## Customizing your random svg image
47
+
48
+ Random svg image can be customized setting the following options:
49
+
50
+ title: (String) SVG <title> tag for image. Example: "awesome_avatar"
51
+ colors: (Array) colors to compose your image, Example: ["#aaaaaa", "#990000"] or ["#aaa", "#900"].
52
+ symmetry_axes: (Array).
53
+ - No symmetry: [false, false]
54
+ - X symmetry: [true, false]
55
+ - Y symmetry: [false, true]
56
+ - Full symmetry: [true, true]
57
+ num_cells: (Fixnum) Number of rows and columns in the image. Min: 2, Max:16
58
+ seed: (Fixnum) seed to set random numbers.
31
59
 
32
- ## Development
60
+ Examples
33
61
 
34
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+ svg = RubyRandimage.create( title: "ruby rand image", num_cells: 8, colors: ["#fff", "f00"], symmetry_axes: [true, true])
35
63
 
36
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+ Colors tip: You can define each color density setting the same color multiple times. For example to create an image with aproximately 75% white cells and 25% red cells you can do:
65
+
66
+ svg = RubyRandimage.create( title: "ruby rand image", num_cells: 8, colors: ["#fff", "#fff", "#fff", "f00"], symmetry_axes: [true, true])
37
67
 
38
68
  ## Contributing
39
69
 
40
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby_randimage. 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.
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/santiriera626/ruby_randimage. 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.
41
71
 
42
72
 
43
73
  ## License
@@ -1,21 +1,33 @@
1
1
  require "ruby_randimage/version"
2
- #require "byebug"
2
+
3
+
4
+ # RubyRandimage creates a random image with the input values.
5
+ # The image created has a width = num_cells and all the internal squares have a width of 1px
6
+ # The first cell color its used as backgroud color
7
+ # You can set the random seed to create images like an identicon image
3
8
 
4
9
  module RubyRandimage
5
10
 
6
- # TODO: [sriera] doc
7
11
  DEFAULT_OPTIONS = {
8
- :title => "image title",
9
- :colors => ["#aaaaaa", "#990000"],
10
- :symmetry_axes => [true, true],
11
- :num_cells => 8,
12
- :seed => nil
12
+ :title => "image title", # the title of the image
13
+ :colors => ["#aaaaaa", "#990000"], # the colors of the image
14
+ :symmetry_axes => [true, true], # the symetry of x and y axes
15
+ :num_cells => 8, # the number of cells in the image
16
+ :seed => nil # the seed to fix random numbers
13
17
  }
14
18
 
15
- # TODO: [sriera] doc
19
+ # create a random image svg and save it to the given filename
20
+ #
21
+ # Example:
22
+ # >> RubyRandimage.create_and_save_file('test_identicon.png', options)
23
+ # => result (Fixnum)
24
+ #
25
+ # @param filename [string] the full path and filename to save the image svg to
26
+ # @param options [hash] additional options for the image
27
+ #
16
28
  def self.create_and_save_file filename, options={}
17
29
 
18
- # create the svg
30
+ # create the svg image string
19
31
  svg = create(options)
20
32
 
21
33
  # save svg to file filename
@@ -23,61 +35,99 @@ module RubyRandimage
23
35
 
24
36
  end
25
37
 
26
- # TODO: [sriera] doc
38
+ # create a random image svg and return it as a svg string
39
+ #
40
+ # Example:
41
+ # >> RubyRandimage.create(options)
42
+ # => (String)
43
+ #
44
+ # @param options [hash] additional options for the image
45
+ #
27
46
  def self.create options={}
28
47
 
29
48
  options = DEFAULT_OPTIONS.merge(options)
30
49
 
31
- # TODO: [sriera] control de parametros y rspec, controlar seed nil o entero
32
50
  raise "title is invalid" if options[:title] == nil || options[:title] == ''
33
- raise "num_cells must be between 2 and 256" if options[:num_cells] < 2 || options[:num_cells] > 256
51
+ raise "num_cells must be between 2 and 16" if options[:num_cells] < 2 || options[:num_cells] > 16
52
+ raise "symmetry_axes must be a two elemnts array" if options[:symmetry_axes].class != Array || options[:symmetry_axes].count!=2
53
+ raise "colors must be an array with at least two elemments" if options[:colors].class != Array || options[:colors].count < 2
54
+ raise "seed is invalid, must be nil or fixnum" if !options[:seed].nil? && options[:seed].class != Fixnum
34
55
 
56
+ # generate the cells matrix with colors
35
57
  matrix = generate_matrix options[:num_cells], options[:colors], options[:symmetry_axes], options[:seed]
36
58
 
59
+ # generate and return the svg string with matrix values
37
60
  return generate_svg options[:title], matrix
38
61
  end
39
62
 
40
63
  private
41
64
 
42
- # TODO: [sriera] doc
65
+ # create a num_cells*num_cells matrix of colors randomly
66
+ #
67
+ # Example:
68
+ # >> generate_matrix(8, ["#ffffff", "#ffffff", #ff0000], [true, false])
69
+ # => (Array[Array[(String)]])
70
+ #
71
+ # @param num_cells (Fixnum) number of image cells
72
+ # @param colors (Array) the image colors
73
+ # @param symmetry_axes (Array) the image symmetry_axes [x_axis, y_axis]
74
+ # @param seed (Fixnum) The seed to init the rand object
75
+
43
76
  def self.generate_matrix num_cells, colors, symmetry_axes, seed = nil
44
77
 
45
- srand(seed) if ! seed.nil?
78
+ # init rand object if seed!=nil
79
+ srand(seed) if ! seed.nil?
46
80
 
81
+ # init matrix
47
82
  cells = Array.new
48
83
  num_cells.times { |i| cells[i] = []}
49
84
 
85
+ # set num_cols and num_rows for the symmetry_axes setted
50
86
  num_cols = symmetry_axes[0] ? (num_cells/2.to_f).ceil : num_cells
51
-
52
87
  num_rows = symmetry_axes[1] ? (num_cells/2.to_f).ceil : num_cells
53
88
 
89
+ # for each cell
54
90
  (num_rows*num_cols).to_i.times do |cell|
55
-
91
+
92
+ # cell position at matrix
56
93
  cell_x = (cell%num_cols)
57
94
  cell_y = (cell/num_cols)
58
95
 
96
+ # random color from colors list
59
97
  color = colors[rand(colors.length)]
60
98
 
99
+ # fill cell
61
100
  cells[cell_x][cell_y] = color
62
101
 
102
+ # mirror cell x_axis
63
103
  if symmetry_axes[0] && num_cells - 1 != 2*cell_x
64
104
  cells[num_cells - cell_x - 1][cell_y] = color
65
105
 
106
+ # mirror cell x_axis and y_axis
66
107
  if symmetry_axes[1] && num_cells -1 != 2*cell_y
67
108
  cells[num_cells - cell_x - 1][num_cells - cell_y - 1] = color
68
109
  end
69
110
  end
70
111
 
112
+ #mirror cell y_axis
71
113
  if symmetry_axes[1] && num_cells -1 != 2*cell_y
72
114
  cells[cell_x][ num_cells - cell_y-1 ] = color
73
115
  end
74
-
75
116
  end
76
117
 
118
+ # return the matrix of colors
77
119
  return cells
78
120
  end
79
121
 
80
- # TODO: [sriera] doc
122
+ # generate the svg string
123
+ #
124
+ # Example:
125
+ # >> generate_svg("svg_title" , matrix)
126
+ # => (String)
127
+ #
128
+ # @param title (String) the title of the svg image
129
+ # @param matrix (Array[Array[(String)]]) the colors matrix
130
+
81
131
  def self.generate_svg title, matrix
82
132
 
83
133
  # open svg tag
@@ -101,5 +151,4 @@ module RubyRandimage
101
151
  svg << "</svg>"
102
152
 
103
153
  end
104
-
105
154
  end
@@ -1,3 +1,3 @@
1
1
  module RubyRandimage
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -9,12 +9,11 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["santiriera626" , "camumino", "franx0"]
10
10
  spec.email = ["santiriera626@gmail.com", "camumino@gmail.com", "francisco.moya.martinez@gmail.com"]
11
11
 
12
- spec.summary = %q{Write a short summary, because Rubygems requires one.}
12
+ spec.summary = %q{Pure Ruby library to create SVG random images}
13
13
  spec.description = <<-EOT
14
- description text
15
- more text.
14
+ A powerful, customizable and sophisticated awesome SVG avatars generator from several options such as symmetries, size, color palette and color densities.
16
15
  EOT
17
- spec.homepage = ""
16
+ spec.homepage = "https://rubygems.org/gems/ruby_randimage"
18
17
  spec.license = "MIT"
19
18
 
20
19
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_randimage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - santiriera626
@@ -10,51 +10,55 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2016-03-15 00:00:00.000000000 Z
13
+ date: 2016-03-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.5'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  version: '1.5'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ~>
34
34
  - !ruby/object:Gem::Version
35
35
  version: '10.0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ~>
41
41
  - !ruby/object:Gem::Version
42
42
  version: '10.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rspec
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ~>
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.4.0
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ~>
55
55
  - !ruby/object:Gem::Version
56
56
  version: 3.4.0
57
- description: " description text \n more text.\n"
57
+ description: ! ' A powerful, customizable and sophisticated awesome SVG avatars
58
+ generator from several options such as symmetries, size, color palette and color
59
+ densities.
60
+
61
+ '
58
62
  email:
59
63
  - santiriera626@gmail.com
60
64
  - camumino@gmail.com
@@ -63,9 +67,9 @@ executables: []
63
67
  extensions: []
64
68
  extra_rdoc_files: []
65
69
  files:
66
- - ".gitignore"
67
- - ".rspec"
68
- - ".travis.yml"
70
+ - .gitignore
71
+ - .rspec
72
+ - .travis.yml
69
73
  - CODE_OF_CONDUCT.md
70
74
  - Gemfile
71
75
  - LICENSE.txt
@@ -76,10 +80,7 @@ files:
76
80
  - lib/ruby_randimage.rb
77
81
  - lib/ruby_randimage/version.rb
78
82
  - ruby_randimage.gemspec
79
- - tareas.txt
80
- - test_index.html
81
- - untitled.html
82
- homepage: ''
83
+ homepage: https://rubygems.org/gems/ruby_randimage
83
84
  licenses:
84
85
  - MIT
85
86
  metadata:
@@ -90,18 +91,18 @@ require_paths:
90
91
  - lib
91
92
  required_ruby_version: !ruby/object:Gem::Requirement
92
93
  requirements:
93
- - - ">="
94
+ - - ! '>='
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  requirements:
98
- - - ">="
99
+ - - ! '>='
99
100
  - !ruby/object:Gem::Version
100
101
  version: '0'
101
102
  requirements: []
102
103
  rubyforge_project:
103
- rubygems_version: 2.4.8
104
+ rubygems_version: 2.4.3
104
105
  signing_key:
105
106
  specification_version: 4
106
- summary: Write a short summary, because Rubygems requires one.
107
+ summary: Pure Ruby library to create SVG random images
107
108
  test_files: []
data/tareas.txt DELETED
@@ -1,16 +0,0 @@
1
-
2
- fijar o liberar versiones gemas en .gemspec
3
- app demo para readme
4
- comentarios en codigo
5
- decidir si se pasa como parámetro el tamaño de la imagen y dentro se hacen los calculos
6
- - haciendo pruebas no se gana demasiado:
7
- PROS:
8
- - simplicidad al no tener que pasar el tamaño de la imagen deseado, cosa que es indiferente pues se escala por html/css
9
- - El tamaño del svg es menor pues todos los anchos son "1" y todos los numeros enteros
10
- CONTRAS:
11
- - Hay que pintar las imagenes del tamaño deseado o se pintaran del tamaño grid_size*grid_size
12
-
13
- corregir todos los comentarios para que sean decentes en ingles
14
- ver TODO: y FIX:
15
-
16
-
@@ -1,28 +0,0 @@
1
- <html>
2
- <img src="temp_image_0.svg" width="160" heigth="160" border="1"></img><br><br>
3
- <img src="temp_image_1.svg" width="160" heigth="160" border="1"></img><br><br>
4
- <img src="temp_image_2.svg" width="160" heigth="160" border="1"></img><br><br>
5
- <img src="temp_image_3.svg" width="160" heigth="160" border="1"></img><br><br>
6
- <img src="temp_image_4.svg" width="160" heigth="160" border="1"></img><br><br>
7
- <img src="temp_image_5.svg" width="160" heigth="160" border="1"></img><br><br>
8
- <img src="temp_image_6.svg" width="160" heigth="160" border="1"></img><br><br>
9
- <img src="temp_image_7.svg" width="160" heigth="160" border="1"></img><br><br>
10
- <img src="temp_image_8.svg" width="160" heigth="160" border="1"></img><br><br>
11
- <img src="temp_image_9.svg" width="160" heigth="160" border="1"></img><br><br>
12
- <img src="temp_image_10.svg" width="160" heigth="160" border="1"></img><br><br>
13
- <img src="temp_image_11.svg" width="160" heigth="160" border="1"></img><br><br>
14
- <img src="temp_image_12.svg" width="160" heigth="160" border="1"></img><br><br>
15
- <img src="temp_image_13.svg" width="160" heigth="160" border="1"></img><br><br>
16
- <img src="temp_image_14.svg" width="160" heigth="160" border="1"></img><br><br>
17
- <img src="temp_image_15.svg" width="160" heigth="160" border="1"></img><br><br>
18
- <img src="temp_image_16.svg" width="160" heigth="160" border="1"></img><br><br>
19
- <img src="temp_image_17.svg" width="160" heigth="160" border="1"></img><br><br>
20
- <img src="temp_image_18.svg" width="160" heigth="160" border="1"></img><br><br>
21
- <img src="temp_image_19.svg" width="160" heigth="160" border="1"></img><br><br>
22
- <img src="temp_image_20.svg" width="160" heigth="160" border="1"></img><br><br>
23
- <img src="temp_image_21.svg" width="160" heigth="160" border="1"></img><br><br>
24
- <img src="temp_image_22.svg" width="160" heigth="160" border="1"></img><br><br>
25
- <img src="temp_image_23.svg" width="160" heigth="160" border="1"></img><br><br>
26
- <img src="temp_image_24.svg" width="160" heigth="160" border="1"></img><br><br>
27
-
28
- </html>
@@ -1,27 +0,0 @@
1
-
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
- <script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.4.6"></script>
6
- </head>
7
- <body>
8
- <script type="text/javascript">
9
- var svg = d3.select("body").append("svg:svg")
10
- .attr("width", 200)
11
- .attr("height", 200);
12
- svg.append("svg:text")
13
- .attr("x", 100)
14
- .attr("y", 100)
15
- .attr("text-anchor", "middle")
16
- .attr("dy", ".35em")
17
- .text("TEST FAILED");
18
- svg.selectAll("rect")
19
- .data(d3.range(400))
20
- .enter().append("svg:rect")
21
- .attr("x", function(d) { return d / 2; })
22
- .attr("width", .5)
23
- .attr("height", 200);
24
- </script>
25
- <p>400 contiguous opaque <tt>&lt;svg:rect&gt;</tt> elements, each .5-pixel wide. The text underneath the rects should not be visible.
26
- </body>
27
- </html>