pitchcar 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +21 -0
- data/images/curve_tile.png +0 -0
- data/images/straight_tile.png +0 -0
- data/lib/piece.rb +32 -0
- data/lib/track.rb +34 -0
- data/lib/track_image.rb +64 -0
- data/pitchcar.gemspec +14 -11
- metadata +33 -4
- data/images/pitchcar_curve.png +0 -0
- data/images/pitchcar_straight.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6753a63fdf5f4abfdb83330fba95107c143997b
|
4
|
+
data.tar.gz: 6120074fe200a104e94338f1a05a27132481be7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aa37062956eb9f3822517ee9782b683afda541a9c96262525cd2b7dd53a71c3904b5c32a9bc15376d9033921ae19c2456e939a86e9a758752fec27a848813bc
|
7
|
+
data.tar.gz: 8e7b56d1a5ad4bbc6ecb676db707518fea0184b5e50fd47860d70a1d7e24fc97631b2bf6f983f33bf63eacd6fcf687d8291e5516de65f2c2b706b6c25891dc1c
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/images/curve_tile.png
CHANGED
Binary file
|
data/images/straight_tile.png
CHANGED
Binary file
|
data/lib/piece.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'rmagick'
|
2
3
|
|
3
4
|
module Pitchcar
|
4
5
|
class Piece
|
5
6
|
TYPES = { STRAIGHT: 0, LEFT: 1, RIGHT: 2, STRAIGHT_LEFT_WALL: 3, STRAIGHT_RIGHT_WALL: 4 }
|
6
7
|
DIRECTIONS = { NORTH: 0, EAST: 1, WEST: 2, SOUTH: 3 }
|
8
|
+
STRAIGHT_IMAGE, CURVE_IMAGE = Magick::ImageList.new('images/straight_tile.png', 'images/curve_tile.png').to_a
|
7
9
|
attr_accessor :direction, :x, :y, :type
|
8
10
|
|
9
11
|
def self.starting_piece
|
@@ -62,5 +64,35 @@ module Pitchcar
|
|
62
64
|
def to_h
|
63
65
|
{ x: x, y: y, type: TYPES.key(type).downcase, direction: DIRECTIONS.key(direction).downcase }
|
64
66
|
end
|
67
|
+
|
68
|
+
def image
|
69
|
+
case type
|
70
|
+
when TYPES[:STRAIGHT], TYPES[:STRAIGHT_LEFT_WALL], TYPES[:STRAIGHT_RIGHT_WALL]
|
71
|
+
return STRAIGHT_IMAGE.rotate(90) if direction == DIRECTIONS[:NORTH] || direction == DIRECTIONS[:SOUTH]
|
72
|
+
return STRAIGHT_IMAGE
|
73
|
+
when TYPES[:LEFT]
|
74
|
+
case direction
|
75
|
+
when DIRECTIONS[:NORTH]
|
76
|
+
CURVE_IMAGE.rotate(270)
|
77
|
+
when DIRECTIONS[:EAST]
|
78
|
+
CURVE_IMAGE
|
79
|
+
when DIRECTIONS[:WEST]
|
80
|
+
CURVE_IMAGE.rotate(180)
|
81
|
+
when DIRECTIONS[:SOUTH]
|
82
|
+
CURVE_IMAGE.rotate(90)
|
83
|
+
end
|
84
|
+
when TYPES[:RIGHT]
|
85
|
+
case direction
|
86
|
+
when DIRECTIONS[:NORTH]
|
87
|
+
CURVE_IMAGE
|
88
|
+
when DIRECTIONS[:EAST]
|
89
|
+
CURVE_IMAGE.rotate(90)
|
90
|
+
when DIRECTIONS[:WEST]
|
91
|
+
CURVE_IMAGE.rotate(270)
|
92
|
+
when DIRECTIONS[:SOUTH]
|
93
|
+
CURVE_IMAGE.rotate(180)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
65
97
|
end
|
66
98
|
end
|
data/lib/track.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'csv'
|
2
|
+
require 'bazaar'
|
2
3
|
require_relative 'piece'
|
4
|
+
require_relative 'track_image'
|
3
5
|
require_relative 'boyermoore'
|
4
6
|
|
5
7
|
module Pitchcar
|
@@ -52,6 +54,11 @@ module Pitchcar
|
|
52
54
|
pieces.map(&:to_h).to_json
|
53
55
|
end
|
54
56
|
|
57
|
+
def to_png
|
58
|
+
TrackImage.new(self).render
|
59
|
+
puts "Track image saved to #{Dir.pwd}/track.png"
|
60
|
+
end
|
61
|
+
|
55
62
|
def size
|
56
63
|
x_coords = pieces.map(&:x)
|
57
64
|
y_coords = pieces.map(&:y)
|
@@ -78,6 +85,29 @@ module Pitchcar
|
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
88
|
+
# Returns pieces list sorted from in a top-bottom left-right manner
|
89
|
+
def graph_sorted
|
90
|
+
pieces.sort do |piece, other_piece|
|
91
|
+
if piece.y == other_piece.y
|
92
|
+
piece.x <=> other_piece.x
|
93
|
+
else
|
94
|
+
other_piece.y <=> piece.y
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def title
|
100
|
+
results = { nouns: [], adjs: [] }
|
101
|
+
[{ name: :nouns, types: %w(items superitems) }, {name: :adjs, types: %w(adj superadj) }].each do |part|
|
102
|
+
part[:types].each do |type|
|
103
|
+
Random.srand(hash.hex)
|
104
|
+
results[part[:name]] << Bazaar.get_item(type).capitalize
|
105
|
+
end
|
106
|
+
end
|
107
|
+
Random.srand(hash.hex)
|
108
|
+
"#{results[:adjs].sample} #{results[:nouns].sample}"
|
109
|
+
end
|
110
|
+
|
81
111
|
private
|
82
112
|
|
83
113
|
def rotation_exists?(tracks)
|
@@ -95,6 +125,10 @@ module Pitchcar
|
|
95
125
|
def within_size_restrictions?
|
96
126
|
size[:x].between?(self.min_size[:x], self.max_size[:x]) && size[:y].between?(self.min_size[:y], self.max_size[:y])
|
97
127
|
end
|
128
|
+
|
129
|
+
def hash
|
130
|
+
Digest::SHA256.hexdigest(to_s)
|
131
|
+
end
|
98
132
|
end
|
99
133
|
|
100
134
|
class PieceList < Array
|
data/lib/track_image.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
|
3
|
+
module Pitchcar
|
4
|
+
class TrackImage
|
5
|
+
attr_accessor :track
|
6
|
+
TILE_SIZE = 570
|
7
|
+
OFFSET_SIZE = -46
|
8
|
+
TITLE_OFFSET = 200
|
9
|
+
BLANK_TILE = Magick::Image.new(TILE_SIZE, TILE_SIZE) { |canvas| canvas.background_color = 'white' }
|
10
|
+
|
11
|
+
def initialize(track)
|
12
|
+
self.track = track
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
track_image = render_track(build_tiles)
|
17
|
+
add_title_to(track_image)
|
18
|
+
track_image.write('track.png')
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_tiles
|
24
|
+
min_x = track.pieces.map(&:x).min
|
25
|
+
coordinate = { x: min_x, y: track.pieces.map(&:y).max }
|
26
|
+
sorted_pieces = track.graph_sorted
|
27
|
+
tiles = sorted_pieces.map(&:image)
|
28
|
+
index = 0
|
29
|
+
insert_index = 0
|
30
|
+
while index < track.pieces.size - 1 do
|
31
|
+
piece = sorted_pieces[index]
|
32
|
+
if piece.x == coordinate[:x] && piece.y == coordinate[:y]
|
33
|
+
index += 1
|
34
|
+
else
|
35
|
+
tiles.insert(insert_index, BLANK_TILE)
|
36
|
+
end
|
37
|
+
insert_index += 1
|
38
|
+
new_x = (coordinate[:x] + min_x.abs + 1 ) % track.size[:x] - min_x.abs
|
39
|
+
coordinate[:y] = new_x <= coordinate[:x] ? coordinate[:y] - 1 : coordinate[:y]
|
40
|
+
coordinate[:x] = new_x
|
41
|
+
end
|
42
|
+
pieces = Magick::ImageList.new
|
43
|
+
pieces += tiles
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_track(piece_images)
|
47
|
+
size = track.size
|
48
|
+
track_montage = piece_images.montage do |montage|
|
49
|
+
montage.tile = Magick::Geometry.new(size[:x], size[:y])
|
50
|
+
montage.geometry = Magick::Geometry.new(TILE_SIZE, TILE_SIZE, OFFSET_SIZE, OFFSET_SIZE)
|
51
|
+
end
|
52
|
+
track_montage.extent(track_montage.columns, track_montage.rows + TITLE_OFFSET, 0, -TITLE_OFFSET)
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_title_to(track_image)
|
56
|
+
Magick::Draw.new.annotate(track_image, 0, 0, 0, 40, track.title) do
|
57
|
+
self.font_family = 'Helvetica'
|
58
|
+
self.pointsize = 60
|
59
|
+
self.font_weight = Magick::BoldWeight
|
60
|
+
self.gravity = Magick::NorthGravity
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/pitchcar.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
Gem::Specification.new do |
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'pitchcar'
|
3
|
+
spec.version = '0.5.0'
|
4
|
+
spec.date = '2017-02-23'
|
5
|
+
spec.summary = 'Pitchcar Track Generator'
|
6
|
+
spec.description = 'Generates tracks for pitchcar'
|
7
|
+
spec.authors = ['Jonah Hirsch']
|
8
|
+
spec.email = 'jhirsch@rmn.com'
|
9
|
+
spec.homepage = 'https://github.com/jonahwh/pitchcar_track_generator'
|
10
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.add_runtime_dependency 'bazaar'
|
14
|
+
spec.add_runtime_dependency 'rmagick'
|
12
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pitchcar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonah Hirsch
|
@@ -9,23 +9,52 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-02-23 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bazaar
|
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: rmagick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Generates tracks for pitchcar
|
14
42
|
email: jhirsch@rmn.com
|
15
43
|
executables: []
|
16
44
|
extensions: []
|
17
45
|
extra_rdoc_files: []
|
18
46
|
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
19
49
|
- LICENSE.md
|
20
50
|
- Readme.md
|
21
51
|
- images/curve_tile.png
|
22
|
-
- images/pitchcar_curve.png
|
23
|
-
- images/pitchcar_straight.png
|
24
52
|
- images/straight_tile.png
|
25
53
|
- lib/boyermoore.rb
|
26
54
|
- lib/piece.rb
|
27
55
|
- lib/pitchcar.rb
|
28
56
|
- lib/track.rb
|
57
|
+
- lib/track_image.rb
|
29
58
|
- pitchcar.gemspec
|
30
59
|
- pitchcar_tracks
|
31
60
|
homepage: https://github.com/jonahwh/pitchcar_track_generator
|
data/images/pitchcar_curve.png
DELETED
Binary file
|
Binary file
|