wordlelike 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/wordlelike.rb +112 -0
- data/lib/wordlelike/version.rb +3 -0
- data/wordlelike.gemspec +25 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f4d1ca44a071a57ac36055a9feaea524eae7a386
|
4
|
+
data.tar.gz: c58ac6bb16c5fd6f45cbb46df92c057873896ce3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43bdb5858574f0dd3a5dc4d2255b5871e4b8b63e7ee283bc6f5fc39e3b684afc1ca20f24b04d143d37e5488800b977459effea1780a4eda57714c7abe836b335
|
7
|
+
data.tar.gz: ea3945e1c4f35382cfb60af75274902d8df3ede4867ef16f5eff380b3976578214edcbacf3d226122e2cd70b4a8e7b9e73ffb89f3c1e40d2f7ebe8a713acb3a4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Rob Styles
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Wordlelike
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'wordlelike'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install wordlelike
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/wordlelike/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 new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/wordlelike.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'wordlelike/version'
|
2
|
+
require 'RMagick'
|
3
|
+
include Magick
|
4
|
+
|
5
|
+
module Wordlelike
|
6
|
+
|
7
|
+
class Cloud
|
8
|
+
|
9
|
+
def self.draw(filename, counted_words, palette = nil)
|
10
|
+
puts "#{DateTime.now}\tStarting #{filename}"
|
11
|
+
#puts counted_words
|
12
|
+
#puts palette
|
13
|
+
|
14
|
+
counted_words.sort_by! { |word, count| count }
|
15
|
+
counted_words.reverse!
|
16
|
+
max_count = counted_words.map { |word, count| count }.max
|
17
|
+
min_count = counted_words.map { |word, count| count }.min
|
18
|
+
|
19
|
+
canvas = Magick::ImageList.new
|
20
|
+
width, height = 1280, 1280
|
21
|
+
canvas.new_image(width, height, Magick::HatchFill.new('white', 'gray90'))
|
22
|
+
|
23
|
+
#title = Magick::Draw.new
|
24
|
+
#title.font_family = 'helvetica'
|
25
|
+
#title.pointsize = 72
|
26
|
+
#title.annotate(canvas, 0, 0, 10, 100, title) unless title.nil?
|
27
|
+
|
28
|
+
placements = []
|
29
|
+
counted_words.each do |word, count, colour|
|
30
|
+
colour ||= 'black'
|
31
|
+
#puts "Processing #{word} as worth #{count}"
|
32
|
+
percentage_size = ((count - min_count) / (max_count - min_count).to_f)
|
33
|
+
#puts "Size: #{percentage_size}"
|
34
|
+
text = Magick::Draw.new
|
35
|
+
text.font_family = 'helvetica'
|
36
|
+
text.pointsize = (72 * percentage_size).round + 12
|
37
|
+
#text.gravity = Magick::CenterGravity
|
38
|
+
#text.translate(width/2, height/2)
|
39
|
+
metrics = text.get_type_metrics(canvas, word)
|
40
|
+
#puts metrics
|
41
|
+
tw, th = metrics.width, metrics.height
|
42
|
+
x_offset = width/2 - tw/2
|
43
|
+
y_offset = height/2 - th/2
|
44
|
+
r, theta = 0, 0
|
45
|
+
x1 = metrics.bounds.x1 + x_offset
|
46
|
+
y1 = metrics.bounds.y1 + (metrics.height - metrics.ascent) + y_offset
|
47
|
+
x2 = x1 + metrics.width
|
48
|
+
y2 = y1 + metrics.ascent - metrics.descent
|
49
|
+
while intersects(placements, x1, y1, x2, y2)
|
50
|
+
add_x, add_y = p2c(r += 0.01, theta += 1)
|
51
|
+
x1 += add_x
|
52
|
+
y1 += add_y
|
53
|
+
x2 += add_x
|
54
|
+
y2 += add_y
|
55
|
+
#puts "#{word} is intersecting, moving to #{x1}, #{y1}, #{x2}, #{y2}"
|
56
|
+
end
|
57
|
+
placements << [x1, y1, x2, y2]
|
58
|
+
#puts "Storing: #{[x1, y1, x2, y2]}"
|
59
|
+
text.annotate(canvas, 0, 0, x1, y2 + metrics.descent, word) { self.fill = colour }
|
60
|
+
#rect = Magick::Draw.new
|
61
|
+
#rect.fill_opacity(0.1)
|
62
|
+
#rect.rectangle(x1, y1, x2, y2)
|
63
|
+
#rect.draw(canvas)
|
64
|
+
#dot = Magick::Draw.new
|
65
|
+
#dot.fill_opacity(0.2)
|
66
|
+
#dot.ellipse(x1, y1, 2, 2, 0, 360)
|
67
|
+
#dot.draw(canvas)
|
68
|
+
end
|
69
|
+
|
70
|
+
if palette
|
71
|
+
size = ((width * 0.8) / palette.length) - 2
|
72
|
+
x = width - (width * 0.9)
|
73
|
+
y = height - size - 10
|
74
|
+
|
75
|
+
rect = Magick::Draw.new
|
76
|
+
rect.fill('white')
|
77
|
+
rect.rectangle(0, (height - size - size - 10), width, height)
|
78
|
+
rect.draw(canvas)
|
79
|
+
|
80
|
+
|
81
|
+
palette.each_with_index do |(k,color),i|
|
82
|
+
#puts "#{k}, #{color}, #{i}"
|
83
|
+
rect = Magick::Draw.new
|
84
|
+
rect.fill(color)
|
85
|
+
rect.rectangle(x, y, x + size, y + size)
|
86
|
+
rect.draw(canvas)
|
87
|
+
label = Magick::Draw.new
|
88
|
+
label.rotation = -10
|
89
|
+
label.font_family = 'helvetica'
|
90
|
+
label.pointsize = 10
|
91
|
+
label.annotate(canvas, 0, 0, x + (size / 2), y - 2, k)
|
92
|
+
x += size + 2
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
canvas.write(filename)
|
97
|
+
puts "#{DateTime.now}\tFinished #{filename}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.intersects(placements, r1x1, r1y1, r1x2, r1y2)
|
101
|
+
placements.each do |r2x1, r2y1, r2x2, r2y2|
|
102
|
+
return true if (r1x2 >= r2x1) && (r1y2 >= r2y1) && (r1x1 <= r2x2) && (r1y1 <= r2y2)
|
103
|
+
end
|
104
|
+
false
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.p2c(r, theta)
|
108
|
+
[r * Math.cos(theta), r * Math.sin(theta)]
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
data/wordlelike.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wordlelike/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'wordlelike'
|
8
|
+
spec.version = Wordlelike::VERSION
|
9
|
+
spec.authors = ['Rob Styles']
|
10
|
+
spec.email = ['rob.styles@dynamicorange.com']
|
11
|
+
spec.summary = 'A small gem for drawing wordle style word clouds'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rmagick'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordlelike
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rob Styles
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A small gem for drawing wordle style word clouds
|
56
|
+
email:
|
57
|
+
- rob.styles@dynamicorange.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/wordlelike.rb
|
68
|
+
- lib/wordlelike/version.rb
|
69
|
+
- wordlelike.gemspec
|
70
|
+
homepage: ''
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.0
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A small gem for drawing wordle style word clouds
|
94
|
+
test_files: []
|