teaching_printables 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/teaching_printables.rb +1 -0
- data/lib/teaching_printables/factory.rb +35 -0
- data/lib/teaching_printables/quad_rulable.rb +1 -1
- data/lib/teaching_printables/shapeable.rb +78 -0
- data/lib/teaching_printables/svg/svg_components.rb +56 -0
- data/lib/teaching_printables/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8f49accf9c002ca3a847cbd08acbdb200f075fb
|
4
|
+
data.tar.gz: 8e7034e6951893b3970f229364d1a4bec9675ba1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a2d3fd7ab0e5ed89088b554a910d20973ddd05ad5fcd9f7489734bc7bbd4a7b0799d7d0e07c73525290bf701fa1a98358f4b8195309bdc07751ec14860663d3
|
7
|
+
data.tar.gz: 039ab9726a74fa20561b2586a21b0e23b02eab5111ff22ba5fef0e85065ca8077383798a07d1ae229ed1bd4333fddca675b3226981fb0185c5ed72a935e857fe
|
data/lib/teaching_printables.rb
CHANGED
@@ -5,6 +5,7 @@ require 'prawn/measurement_extensions'
|
|
5
5
|
require_relative "teaching_printables/quad_rulable"
|
6
6
|
require_relative "teaching_printables/templatable"
|
7
7
|
require_relative "teaching_printables/gridable"
|
8
|
+
require_relative "teaching_printables/shapeable"
|
8
9
|
require_relative "teaching_printables/factory"
|
9
10
|
require_relative "teaching_printables/tp_document"
|
10
11
|
require_relative "teaching_printables/version"
|
@@ -43,6 +43,41 @@ module TeachingPrintables
|
|
43
43
|
doc.save_as(filename)
|
44
44
|
end
|
45
45
|
|
46
|
+
def Factory.base_tens_shapes_paper(npages,rule_value=1,rule_unit='cm',filename='output.pdf')
|
47
|
+
npages = npages.to_i
|
48
|
+
rule = rule_unit.empty? ? rule_value.to_f : rule_value.to_f.send(rule_unit)
|
49
|
+
|
50
|
+
if !filename || filename.empty?
|
51
|
+
filename = 'output.pdf'
|
52
|
+
end
|
53
|
+
|
54
|
+
doc = TeachingPrintables::TPDocument.new
|
55
|
+
class << doc
|
56
|
+
include Shapeable
|
57
|
+
include QuadRulable
|
58
|
+
end
|
59
|
+
npages.times do |i|
|
60
|
+
doc.create_quad_rule(rule_unit: rule, start_new_page: true)
|
61
|
+
doc.create_tens_and_ones_shapes(rule_unit: rule, start_new_page: false)
|
62
|
+
doc.text_box "Name:", :at => [2.cm, doc.bounds.top - 1.cm]
|
63
|
+
doc.line_width = 2
|
64
|
+
doc.stroke_color = "000000"
|
65
|
+
doc.stroke_line [3.5.cm,doc.bounds.top - 1.5.cm], [10.cm,doc.bounds.top - 1.5.cm]
|
66
|
+
doc.text_box "Date:", :at => [12.cm, doc.bounds.top - 1.cm]
|
67
|
+
doc.stroke_line [13.cm,doc.bounds.top - 1.5.cm], [20.cm,doc.bounds.top - 1.5.cm]
|
68
|
+
end
|
69
|
+
doc.save_as(filename)
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def Factory.centimeter_number_lines(output_file_name = "output.pdf")
|
74
|
+
doc = TeachingPrintables::TPDocument.new
|
75
|
+
class << doc
|
76
|
+
include Gridable
|
77
|
+
end
|
78
|
+
update_grid_options(grid_rows: 5, grid_columns: 1)
|
79
|
+
|
80
|
+
end
|
46
81
|
|
47
82
|
def Factory.hundreds_grid(output_file_name="output.pdf")
|
48
83
|
qr=TeachingPrintables::TPDocument.new
|
@@ -34,7 +34,7 @@ module TeachingPrintables
|
|
34
34
|
start_new_page
|
35
35
|
end
|
36
36
|
|
37
|
-
svg(str,width: ncols*rule_unit, height: nrows*rule_unit, at:[0,rule_height
|
37
|
+
svg(str,width: ncols*rule_unit, height: nrows*rule_unit, at:[0,rule_height]) #position: :center, vposition: :center)
|
38
38
|
|
39
39
|
end
|
40
40
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative "svg/svg_components"
|
2
|
+
require "prawn-svg"
|
3
|
+
module TeachingPrintables
|
4
|
+
# Creates quadrille rulings on paper. Delegates Prawn methods to Prawn::Document.
|
5
|
+
|
6
|
+
module Shapeable
|
7
|
+
attr_accessor :rule_unit
|
8
|
+
|
9
|
+
def rule_unit
|
10
|
+
@rule_unit ||= 1.cm
|
11
|
+
end
|
12
|
+
def rule_height
|
13
|
+
bounds.top - bounds.bottom
|
14
|
+
end
|
15
|
+
def rule_width
|
16
|
+
bounds.right - bounds.left
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_tens_and_ones_shapes(options={})
|
20
|
+
# Start at position 3cm, 3cm from top left corner. Keep drawing shapes until end of page
|
21
|
+
|
22
|
+
fill_colors_enum = %W[red blue green orange].cycle
|
23
|
+
|
24
|
+
if (page_number ==0) || (options[:start_new_page] == true)
|
25
|
+
start_new_page
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
shape_position = [3.cm, rule_height-2.cm]
|
30
|
+
page_height = rule_height - 4.cm
|
31
|
+
remaining_rows = (page_height / rule_unit).floor
|
32
|
+
shapes_rows_arr = []
|
33
|
+
|
34
|
+
while remaining_rows > 2
|
35
|
+
shapes_rows_arr<<rand(3..[11,remaining_rows].min)
|
36
|
+
remaining_rows = remaining_rows-shapes_rows_arr.last
|
37
|
+
end
|
38
|
+
|
39
|
+
shapes_rows_arr.each {|nrows|
|
40
|
+
ones = rand(0..9)
|
41
|
+
svg( SVGComponents::tens_and_ones_shape_svg(nrows-2,ones,fill_color=fill_colors_enum.next),
|
42
|
+
width: 10*rule_unit,
|
43
|
+
height: (nrows-1)*rule_unit,
|
44
|
+
at: [shape_position[0],shape_position[1]-rule_unit])
|
45
|
+
|
46
|
+
@document.fill_color = "FFFFFF"
|
47
|
+
fill_and_stroke_rectangle [14.cm, shape_position[1]-1*rule_unit], 2.cm, 2.cm
|
48
|
+
fill_and_stroke_rectangle [16.cm, shape_position[1]-1*rule_unit], 2.cm, 2.cm
|
49
|
+
@document.fill_color = "000000"
|
50
|
+
text_box "tens", :at => [14.cm, shape_position[1]-1*rule_unit], :width => 2.cm, :align => :center
|
51
|
+
text_box "ones", :at => [16.cm, shape_position[1]-1*rule_unit], :width => 2.cm, :align => :center
|
52
|
+
|
53
|
+
|
54
|
+
if ones == 0
|
55
|
+
shape_position[1] = shape_position[1]-(nrows-1).cm
|
56
|
+
else
|
57
|
+
shape_position[1] = shape_position[1]-nrows.cm
|
58
|
+
end
|
59
|
+
|
60
|
+
}
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
private
|
66
|
+
def parse_options(options)
|
67
|
+
allowed_parameters = [:rule_unit]
|
68
|
+
options.each do |k,v|
|
69
|
+
puts "@#{k.to_s}"
|
70
|
+
instance_variable_set("@#{k.to_s}",v) if allowed_parameters.include?(k)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -71,6 +71,7 @@ class SVGComponents
|
|
71
71
|
fill: "black"
|
72
72
|
}
|
73
73
|
def label(options={})
|
74
|
+
options = DEFAULT_LABEL.merge(options)
|
74
75
|
"<text x=\"#{options[:xpos].to_s}\" y=\"#{options[:ypos].to_s}\" font-size=\"#{options[:font_size].to_s}\" text-anchor=\"#{options[:text_anchor]}\" fill=\"#{options[:fill]}\">#{options[:text]}</text>"
|
75
76
|
end
|
76
77
|
|
@@ -91,6 +92,61 @@ class SVGComponents
|
|
91
92
|
"</svg>"
|
92
93
|
end
|
93
94
|
|
95
|
+
def number_line(startpt,endpt)
|
96
|
+
points_per_unit = 40
|
97
|
+
width = (startpt-endpt+1)*points_per_unit
|
98
|
+
height = 2*points_per_unit
|
99
|
+
str = header(width,height)
|
100
|
+
horizontal_line_opts = {
|
101
|
+
x1: 0,
|
102
|
+
x2: width,
|
103
|
+
y1: points_per_unit,
|
104
|
+
y2: points_per_unit,
|
105
|
+
stroke: "gray",
|
106
|
+
stroke_width: 0.5,
|
107
|
+
stroke_dasharray: "none"
|
108
|
+
}
|
109
|
+
str << line(horizontal_line_opts)
|
110
|
+
|
111
|
+
# make vertical lines
|
112
|
+
for n in (startpt..endpt)
|
113
|
+
verticle_line_opts = {
|
114
|
+
x1: n*points_per_unit,
|
115
|
+
x2: n*points_per_unit,
|
116
|
+
y1: points_per_unit,
|
117
|
+
y2: height,
|
118
|
+
stroke: "gray",
|
119
|
+
stroke_width: 0.5,
|
120
|
+
stroke_dasharray: "none"
|
121
|
+
}
|
122
|
+
str << line(verticle_line_opts)
|
123
|
+
str << label(xpos: n*points_per_unit, ypos: 0, text: "#{n}")
|
124
|
+
end
|
125
|
+
str<<footer
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
def tens_and_ones_shape_svg(tens,ones,fill_color="red")
|
130
|
+
points_per_box = 40
|
131
|
+
|
132
|
+
ncols = 10
|
133
|
+
nrows = tens
|
134
|
+
|
135
|
+
width = ncols*points_per_box
|
136
|
+
height = (nrows+1)*points_per_box
|
137
|
+
str = header(width,height)
|
138
|
+
|
139
|
+
polygon_points = "\"0 0, #{width} 0, " +
|
140
|
+
"#{width} #{height-points_per_box}, " +
|
141
|
+
"#{ones*points_per_box} #{height-points_per_box}, " +
|
142
|
+
"#{ones*points_per_box} #{height}, " +
|
143
|
+
"0 #{height}, " +
|
144
|
+
"0 0\""
|
145
|
+
str<<"<polygon points=#{polygon_points} fill=\"#{fill_color}\" stroke=\"#000\"/>"
|
146
|
+
|
147
|
+
str<<footer
|
148
|
+
end
|
149
|
+
|
94
150
|
def quad_ruled_grid(m_rows,n_columns)
|
95
151
|
|
96
152
|
points_per_box = 40
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teaching_printables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jen Dobson
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/teaching_printables/factory.rb
|
83
83
|
- lib/teaching_printables/gridable.rb
|
84
84
|
- lib/teaching_printables/quad_rulable.rb
|
85
|
+
- lib/teaching_printables/shapeable.rb
|
85
86
|
- lib/teaching_printables/svg/svg_components.rb
|
86
87
|
- lib/teaching_printables/svg/svg_creator.rb
|
87
88
|
- lib/teaching_printables/svg/svg_helpers.rb
|