ruby_randimage 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: ce89af65e49ca8cf464c82df4a4ee47abae37862
4
+ data.tar.gz: 01144f970a0d3215acb4d57aac44fa8b92f89f78
5
+ SHA512:
6
+ metadata.gz: dd3b7a1ffede928a9c93bfcba90b19e3a5e80835ca20676e4c5f1efa47b330d37fcfa4924d4559b3324ff172471c8e902b9c781c3e6e015f72b69a17a36948b2
7
+ data.tar.gz: 9ee16895fd94d03332bac1cdfdfc731126d3dc48a52f5aa638abc773e0d7ad972f7af77e0c39cf8f9afb7da634ec623702bed105001cfa92adde2eaaad2344a6
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ temp_image_*
11
+ .ruby-version
12
+ .ruby-gemset
13
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -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, ethnicity, 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,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'coveralls', :require => false
5
+ end
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
+ gemspec
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # RubyRandimage
2
+
3
+ [![Build Status](https://travis-ci.org/santiriera626/ruby_randimage.svg?branch=master)](https://travis-ci.org/santiriera626/ruby_randimage)
4
+ [![Coverage Status](https://coveralls.io/repos/github/santiriera626/ruby_randimage/badge.svg?branch=master)](https://coveralls.io/github/santiriera626/ruby_randimage?branch=master)
5
+ [![Code Climate](https://codeclimate.com/github/santiriera626/ruby_randimage/badges/gpa.svg)](https://codeclimate.com/github/santiriera626/ruby_randimage)
6
+ [![security](https://hakiri.io/github/santiriera626/ruby_randimage/master.svg)](https://hakiri.io/github/santiriera626/ruby_randimage/master)
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
+
10
+ TODO: Delete this and the text above, and describe your gem
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'ruby_randimage'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install ruby_randimage
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Development
33
+
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.
35
+
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).
37
+
38
+ ## Contributing
39
+
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.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
data/Rakefile ADDED
@@ -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))
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby_randimage"
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
data/bin/setup ADDED
@@ -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,105 @@
1
+ require "ruby_randimage/version"
2
+ #require "byebug"
3
+
4
+ module RubyRandimage
5
+
6
+ # TODO: [sriera] doc
7
+ DEFAULT_OPTIONS = {
8
+ :title => "image title",
9
+ :colors => ["#aaaaaa", "#990000"],
10
+ :symmetry_axes => [true, true],
11
+ :num_cells => 8,
12
+ :seed => nil
13
+ }
14
+
15
+ # TODO: [sriera] doc
16
+ def self.create_and_save_file filename, options={}
17
+
18
+ # create the svg
19
+ svg = create(options)
20
+
21
+ # save svg to file filename
22
+ File.open(filename, 'wb') { |f| f.write(svg) }
23
+
24
+ end
25
+
26
+ # TODO: [sriera] doc
27
+ def self.create options={}
28
+
29
+ options = DEFAULT_OPTIONS.merge(options)
30
+
31
+ # TODO: [sriera] control de parametros y rspec, controlar seed nil o entero
32
+ 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
34
+
35
+ matrix = generate_matrix options[:num_cells], options[:colors], options[:symmetry_axes], options[:seed]
36
+
37
+ return generate_svg options[:title], matrix
38
+ end
39
+
40
+ private
41
+
42
+ # TODO: [sriera] doc
43
+ def self.generate_matrix num_cells, colors, symmetry_axes, seed = nil
44
+
45
+ srand(seed) if ! seed.nil?
46
+
47
+ cells = Array.new
48
+ num_cells.times { |i| cells[i] = []}
49
+
50
+ num_cols = symmetry_axes[0] ? (num_cells/2.to_f).ceil : num_cells
51
+
52
+ num_rows = symmetry_axes[1] ? (num_cells/2.to_f).ceil : num_cells
53
+
54
+ (num_rows*num_cols).to_i.times do |cell|
55
+
56
+ cell_x = (cell%num_cols)
57
+ cell_y = (cell/num_cols)
58
+
59
+ color = colors[rand(colors.length)]
60
+
61
+ cells[cell_x][cell_y] = color
62
+
63
+ if symmetry_axes[0] && num_cells - 1 != 2*cell_x
64
+ cells[num_cells - cell_x - 1][cell_y] = color
65
+
66
+ if symmetry_axes[1] && num_cells -1 != 2*cell_y
67
+ cells[num_cells - cell_x - 1][num_cells - cell_y - 1] = color
68
+ end
69
+ end
70
+
71
+ if symmetry_axes[1] && num_cells -1 != 2*cell_y
72
+ cells[cell_x][ num_cells - cell_y-1 ] = color
73
+ end
74
+
75
+ end
76
+
77
+ return cells
78
+ end
79
+
80
+ # TODO: [sriera] doc
81
+ def self.generate_svg title, matrix
82
+
83
+ # open svg tag
84
+ size = matrix.length
85
+ svg = "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='#{size}' height='#{size}'>"
86
+
87
+ # set title
88
+ svg << "<title>#{title}</title>"
89
+
90
+ # background with first color
91
+ svg << "<rect width='100%' height='100%' x='0' y='0' fill='#{matrix[0][0]}' stroke='none' shape-rendering='crispEdges'/>"
92
+
93
+ size.times do |col|
94
+ size.times do |row|
95
+ # draw rect if its color its different than background color
96
+ svg << "<rect fill='#{matrix[col][row]}' stroke='none' fill-rule='nonzero' x='#{col}' y='#{row}' width='1' height='1' shape-rendering='crispEdges' />" if matrix[col][row] != matrix[0][0]
97
+ end
98
+ end
99
+
100
+ # close svg tag
101
+ svg << "</svg>"
102
+
103
+ end
104
+
105
+ end
@@ -0,0 +1,3 @@
1
+ module RubyRandimage
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruby_randimage/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_randimage"
8
+ spec.version = RubyRandimage::VERSION
9
+ spec.authors = ["santiriera626" , "camumino", "franx0"]
10
+ spec.email = ["santiriera626@gmail.com", "camumino@gmail.com", "francisco.moya.martinez@gmail.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
+ spec.description = <<-EOT
14
+ description text
15
+ more text.
16
+ EOT
17
+ spec.homepage = ""
18
+ spec.license = "MIT"
19
+
20
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
21
+ # delete this section to allow pushing this gem to any host.
22
+ if spec.respond_to?(:metadata)
23
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
26
+ end
27
+
28
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.5"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency 'rspec', "~> 3.4.0"
36
+
37
+ end
data/tareas.txt ADDED
@@ -0,0 +1,16 @@
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
+
data/test_index.html ADDED
@@ -0,0 +1,28 @@
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>
data/untitled.html ADDED
@@ -0,0 +1,27 @@
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>
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_randimage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - santiriera626
8
+ - camumino
9
+ - franx0
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2016-03-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.4.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 3.4.0
57
+ description: " description text \n more text.\n"
58
+ email:
59
+ - santiriera626@gmail.com
60
+ - camumino@gmail.com
61
+ - francisco.moya.martinez@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".travis.yml"
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - bin/console
75
+ - bin/setup
76
+ - lib/ruby_randimage.rb
77
+ - lib/ruby_randimage/version.rb
78
+ - ruby_randimage.gemspec
79
+ - tareas.txt
80
+ - test_index.html
81
+ - untitled.html
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ allowed_push_host: https://rubygems.org
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.8
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Write a short summary, because Rubygems requires one.
107
+ test_files: []