peter_pan 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 692af1cd2a9e3475428ba3ea1a3b432ad130b762
4
+ data.tar.gz: 187e9b546dec65a4fbd4d380aaeb3dfde279d396
5
+ SHA512:
6
+ metadata.gz: 767b95aafa0fea9912984b6265fe34fee6157da042dcbf8bd16c370b3b4a239e3d5d712219590c53f9fe7e07a53c5e3699122139e1b048549451378c810201ba
7
+ data.tar.gz: 99af0967d7d0b82ce6f339b87e19644007db8dd88236a7784c9c83c52f082e690e362884f392e2ff33461552fd91bc71272ab1d03edf6d17176c03807cbba183
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ rpm.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in peter_pan.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matthew Nielsen
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.
@@ -0,0 +1,167 @@
1
+ ## Peter Pan - a Ruby gem providing a virtual screen buffer with viewport panning. For the Dream Cheeky LED sign and others.
2
+
3
+ Peter Pan gives you a large, virtual text frame buffer and a virtual
4
+ viewport you can move around over it. You can plot points or draw text in the
5
+ buffer and scroll the viewport over it to simulate scrolling text or scrolling
6
+ graphics.
7
+
8
+ It was written to make it easier to get text on the Dream Cheeky LED sign, but
9
+ it'll work for any thing that that accepts a formatted text string as input.
10
+
11
+ The dream-cheeky-led gem (https://github.com/Aupajo/dream-cheeky-led) is not a
12
+ dependency, but it can be used in conjunction with this gem to get scrolling
13
+ text and graphics on your Dream Cheeky LED sign.
14
+
15
+ This gem uses the "transpo" font from Lewis Clayton's dcled_ruby project
16
+ (https://github.com/Lewis-Clayton/dcled_ruby).
17
+
18
+ ## Installation
19
+
20
+ Install normally:
21
+
22
+ $ gem install peter_pan
23
+
24
+ And then require it normally:
25
+
26
+ ```ruby
27
+ require 'peter_pan'
28
+ ```
29
+
30
+ To write to a Dream Cheeky LED sign using `examples/dream_cheeky.rb`, also
31
+ install the dream-cheeky-led gem:
32
+
33
+ $ gem install dream-cheeky-led --pre
34
+
35
+ ## Examples
36
+
37
+ There are basic examples in the `examples/` directory:
38
+
39
+ dream_cheeky.rb: write to a USB Dream Cheeky Sign
40
+ to_screen.rb: write to the screen
41
+
42
+ These examples show the basic concepts of drawing text to the buffer and
43
+ panning the viewport over the buffer.
44
+
45
+ ## Usage
46
+
47
+ ### Dots
48
+
49
+ Print dots to the buffer, render the viewport in two places illustrating how
50
+ it only shows the area of the newport:
51
+
52
+ ```ruby
53
+ > require 'peter_pan'
54
+ > p = PeterPan.new
55
+ > p.plot(1,1)
56
+ > p.plot(3,3)
57
+ > p.plot(8,8)
58
+ > p.plot(21,2)
59
+ > p.plot(25,4)
60
+ > puts p.pretty_print_buffer
61
+ +--------------------------+
62
+ | |
63
+ | * |
64
+ | * |
65
+ | * |
66
+ | *|
67
+ | |
68
+ | |
69
+ | |
70
+ | |
71
+ +--------------------------+
72
+ > puts p.pretty_print_viewport(0,0)
73
+ +---------------------+
74
+ | |
75
+ | * |
76
+ | |
77
+ | * |
78
+ | |
79
+ | |
80
+ | |
81
+ +---------------------+
82
+ > puts p.pretty_print_viewport(5,0)
83
+ +---------------------+
84
+ | |
85
+ | |
86
+ | * |
87
+ | |
88
+ | *|
89
+ | |
90
+ | |
91
+ +---------------------+
92
+ ```
93
+
94
+ ### Text
95
+
96
+ Print text to the buffer and render the viewport over a portion.
97
+
98
+ ```ruby
99
+ > require 'peter_pan'
100
+ > p = PeterPan.new
101
+ > p.write(0, 0, "Hello.")
102
+ > puts p.pretty_print_buffer
103
+ +-----------------------------------+
104
+ |* * ** ** |
105
+ |* * * * |
106
+ |* * *** * * *** |
107
+ |***** * * * * * * |
108
+ |* * ***** * * * * |
109
+ |* * * * * * * ** |
110
+ |* * *** *** *** *** ** |
111
+ +-----------------------------------+
112
+ > puts p.pretty_print_viewport(5,0)
113
+ +---------------------+
114
+ | ** ** |
115
+ | * * |
116
+ | *** * * *|
117
+ | * * * * * |
118
+ | ***** * * * |
119
+ | * * * * |
120
+ | *** *** *** *|
121
+ +---------------------+
122
+ ```
123
+
124
+ ### Change viewport size
125
+
126
+ The viewport dimensions default to 21x7, the size of the Dream Cheeky LED,
127
+ but can be changed by passing arguments to the initializer.
128
+
129
+ ```ruby
130
+ > p = PeterPan.new( viewport_width: 5, viewport_height: 5 )
131
+ > p.write(0, 0, "Hello.")
132
+ > puts p.pretty_print_viewport(5,0)
133
+ +-----+
134
+ | |
135
+ | |
136
+ | ***|
137
+ | * |
138
+ | ****|
139
+ +-----+
140
+ ```
141
+
142
+ ### Printing without ascii borders
143
+
144
+ To print the buffer and viewport without the ascii-art borders, replace
145
+ `pretty_print_viewport` with 'show_viewport` using the same arguments:
146
+
147
+ ```ruby
148
+ > p = PeterPan.new( viewport_width: 5, viewport_height: 5 )
149
+ > p.write(0, 0, "Hello.")
150
+ > puts p.show_viewport(5,0)
151
+
152
+
153
+ ***
154
+ *
155
+ ****
156
+ ```
157
+
158
+ All other `pretty_*` methods have `show_*` counterparts that will return data
159
+ without the enclosing border.
160
+
161
+ ### Animated panning the viewport
162
+
163
+ Please see the examples in `examples/`.
164
+
165
+ ## Documentation
166
+
167
+ TODO: add link to RDOC here.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Example of using peter_pan with the Dream Cheeky LED display via the
4
+ # dream-cheeky-led gem (https://github.com/Aupajo/dream-cheeky-led).
5
+ require 'peter_pan'
6
+ require 'dream-cheeky/led'
7
+
8
+ p = PeterPan.new
9
+
10
+ lines = [
11
+ "One",
12
+ "Two",
13
+ "Three",
14
+ "Four",
15
+ "Five"
16
+ ]
17
+
18
+ lines.each_with_index do |line, i|
19
+ p.write(0, (i*p.font["height"])+(1*i), line)
20
+ end
21
+
22
+ puts p.pretty_print_buffer
23
+
24
+ message_board = DreamCheeky::LEDMessageBoard.first
25
+
26
+ loop do
27
+ coords = [
28
+ [0,0],
29
+ [0, p.buffer_height-p.font["height"]],
30
+ [p.buffer_width-p.viewport_width, p.buffer_height-p.font["height"]],
31
+ [p.buffer_width-p.viewport_width, 0],
32
+ [0,0]
33
+ ]
34
+
35
+ p.path_viewport(coords).each do |vp|
36
+ message_board.draw(vp)
37
+ sleep(0.05)
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Draws words to the virtual butter and then pans the viewport around it.
4
+ require 'peter_pan'
5
+
6
+ p = PeterPan.new
7
+
8
+ lines = [
9
+ "One",
10
+ "Two",
11
+ "Three"
12
+ ]
13
+
14
+ lines.each_with_index do |line, i|
15
+ p.write(0, (i*p.font["height"])+(1*i), line)
16
+ end
17
+
18
+ loop do
19
+ coords = [
20
+ [0,0],
21
+ [0, p.buffer_height-p.font["height"]],
22
+ [p.buffer_width-p.viewport_width, p.buffer_height-p.font["height"]],
23
+ [p.buffer_width-p.viewport_width, 0],
24
+ [0,0]
25
+ ]
26
+
27
+ p.pretty_pan_viewport(coords).each do |vp|
28
+ print "\e[2J\e[f" # clear screen
29
+ puts p.pretty_print_buffer # print whole buffer
30
+ puts vp # print current viewport frame
31
+ sleep(0.1)
32
+ end
33
+
34
+ end
@@ -0,0 +1,757 @@
1
+ name: 'transpo'
2
+ version: '0.0.1'
3
+ width: 5
4
+ height: 7
5
+ characters:
6
+ ' ':
7
+ - '.....'
8
+ - '.....'
9
+ - '.....'
10
+ - '.....'
11
+ - '.....'
12
+ - '.....'
13
+ - '.....'
14
+ '!':
15
+ - '..*..'
16
+ - '..*..'
17
+ - '..*..'
18
+ - '..*..'
19
+ - '.....'
20
+ - '..*..'
21
+ - '..*..'
22
+ '"':
23
+ - '.*.*.'
24
+ - '.*.*.'
25
+ - '.*.*.'
26
+ - '.....'
27
+ - '.....'
28
+ - '.....'
29
+ - '.....'
30
+ '#':
31
+ - '.*.*.'
32
+ - '.*.*.'
33
+ - '*****'
34
+ - '.*.*.'
35
+ - '*****'
36
+ - '.*.*.'
37
+ - '.*.*.'
38
+ '$':
39
+ - '.*...'
40
+ - '.*.*.'
41
+ - '.***.'
42
+ - '...*.'
43
+ - '...*.'
44
+ - '.....'
45
+ - '.....'
46
+ '%':
47
+ - '**...'
48
+ - '**..*'
49
+ - '...*.'
50
+ - '..*..'
51
+ - '.*...'
52
+ - '*..**'
53
+ - '...**'
54
+ '&':
55
+ - '.*...'
56
+ - '*.*..'
57
+ - '*.*..'
58
+ - '.*...'
59
+ - '*.*.*'
60
+ - '*..*.'
61
+ - '.**.*'
62
+ "'":
63
+ - '..*..'
64
+ - '..*..'
65
+ - '..*..'
66
+ - '.....'
67
+ - '.....'
68
+ - '.....'
69
+ - '.....'
70
+ '(':
71
+ - '...*.'
72
+ - '..*..'
73
+ - '.*...'
74
+ - '.*...'
75
+ - '.*...'
76
+ - '..*..'
77
+ - '...*.'
78
+ ')':
79
+ - '.*...'
80
+ - '..*..'
81
+ - '...*.'
82
+ - '...*.'
83
+ - '...*.'
84
+ - '..*..'
85
+ - '.*...'
86
+ '*':
87
+ - '.....'
88
+ - '..*..'
89
+ - '*.*.*'
90
+ - '.***.'
91
+ - '*.*.*'
92
+ - '..*..'
93
+ - '.....'
94
+ '+':
95
+ - '.....'
96
+ - '..*..'
97
+ - '..*..'
98
+ - '*****'
99
+ - '..*..'
100
+ - '..*..'
101
+ - '.....'
102
+ ',':
103
+ - '.....'
104
+ - '.....'
105
+ - '.....'
106
+ - '.....'
107
+ - '.**..'
108
+ - '..*..'
109
+ - '.*...'
110
+ '-':
111
+ - '.....'
112
+ - '.....'
113
+ - '.....'
114
+ - '*****'
115
+ - '.....'
116
+ - '.....'
117
+ - '.....'
118
+ '.':
119
+ - '.....'
120
+ - '.....'
121
+ - '.....'
122
+ - '.....'
123
+ - '.....'
124
+ - '.**..'
125
+ - '.**..'
126
+ '/':
127
+ - '.....'
128
+ - '....*'
129
+ - '...*.'
130
+ - '..*..'
131
+ - '.*...'
132
+ - '*....'
133
+ - '.....'
134
+ '0':
135
+ - '.***.'
136
+ - '*...*'
137
+ - '*..**'
138
+ - '*.*.*'
139
+ - '**..*'
140
+ - '*...*'
141
+ - '.***.'
142
+ '1':
143
+ - '..*..'
144
+ - '.**..'
145
+ - '..*..'
146
+ - '..*..'
147
+ - '..*..'
148
+ - '..*..'
149
+ - '.***.'
150
+ '2':
151
+ - '.***.'
152
+ - '*...*'
153
+ - '....*'
154
+ - '...*.'
155
+ - '..*..'
156
+ - '.*...'
157
+ - '*****'
158
+ '3':
159
+ - '*****'
160
+ - '...*.'
161
+ - '..*..'
162
+ - '...*.'
163
+ - '....*'
164
+ - '*...*'
165
+ - '.***.'
166
+ '4':
167
+ - '...*.'
168
+ - '..**.'
169
+ - '.*.*.'
170
+ - '*..*.'
171
+ - '*****'
172
+ - '...*.'
173
+ - '...*.'
174
+ '5':
175
+ - '*****'
176
+ - '*....'
177
+ - '****.'
178
+ - '....*'
179
+ - '....*'
180
+ - '*...*'
181
+ - '.***.'
182
+ '6':
183
+ - '..**.'
184
+ - '.*...'
185
+ - '*....'
186
+ - '****.'
187
+ - '*...*'
188
+ - '*...*'
189
+ - '.***.'
190
+ '7':
191
+ - '*****'
192
+ - '....*'
193
+ - '...*.'
194
+ - '..*..'
195
+ - '.*...'
196
+ - '.*...'
197
+ - '.*...'
198
+ '8':
199
+ - '.***.'
200
+ - '*...*'
201
+ - '*...*'
202
+ - '.***.'
203
+ - '*...*'
204
+ - '*...*'
205
+ - '.***.'
206
+ '9':
207
+ - '.***.'
208
+ - '*...*'
209
+ - '*...*'
210
+ - '.****'
211
+ - '....*'
212
+ - '...*.'
213
+ - '.**..'
214
+ ':':
215
+ - '.....'
216
+ - '.**..'
217
+ - '.**..'
218
+ - '.....'
219
+ - '.**..'
220
+ - '.**..'
221
+ - '.....'
222
+ ';':
223
+ - '.....'
224
+ - '.**..'
225
+ - '.**..'
226
+ - '.....'
227
+ - '.**..'
228
+ - '..*..'
229
+ - '.*...'
230
+ '<':
231
+ - '...*.'
232
+ - '..*..'
233
+ - '.*...'
234
+ - '*....'
235
+ - '.*...'
236
+ - '..*..'
237
+ - '...*.'
238
+ '=':
239
+ - '.....'
240
+ - '.....'
241
+ - '*****'
242
+ - '.....'
243
+ - '*****'
244
+ - '.....'
245
+ - '.....'
246
+ '>':
247
+ - '.*...'
248
+ - '..*..'
249
+ - '...*.'
250
+ - '....*'
251
+ - '...*.'
252
+ - '..*..'
253
+ - '.*...'
254
+ '?':
255
+ - '.***.'
256
+ - '*...*'
257
+ - '....*'
258
+ - '...*.'
259
+ - '..*..'
260
+ - '.....'
261
+ - '..*..'
262
+ '@':
263
+ - '.***.'
264
+ - '*...*'
265
+ - '*.*.*'
266
+ - '*.***'
267
+ - '*.*..'
268
+ - '*....'
269
+ - '.****'
270
+ 'A':
271
+ - '.***.'
272
+ - '*...*'
273
+ - '*...*'
274
+ - '*****'
275
+ - '*...*'
276
+ - '*...*'
277
+ - '*...*'
278
+ 'B':
279
+ - '****.'
280
+ - '*...*'
281
+ - '*...*'
282
+ - '****.'
283
+ - '*...*'
284
+ - '*...*'
285
+ - '****.'
286
+ 'C':
287
+ - '.***.'
288
+ - '*...*'
289
+ - '*....'
290
+ - '*....'
291
+ - '*....'
292
+ - '*...*'
293
+ - '.***.'
294
+ 'D':
295
+ - '****.'
296
+ - '*...*'
297
+ - '*...*'
298
+ - '*...*'
299
+ - '*...*'
300
+ - '*...*'
301
+ - '****.'
302
+ 'E':
303
+ - '*****'
304
+ - '*....'
305
+ - '*....'
306
+ - '****.'
307
+ - '*....'
308
+ - '*....'
309
+ - '*****'
310
+ 'F':
311
+ - '*****'
312
+ - '*....'
313
+ - '*....'
314
+ - '****.'
315
+ - '*....'
316
+ - '*....'
317
+ - '*....'
318
+ 'G':
319
+ - '.***.'
320
+ - '*...*'
321
+ - '*....'
322
+ - '*.***'
323
+ - '*...*'
324
+ - '*...*'
325
+ - '.****'
326
+ 'H':
327
+ - '*...*'
328
+ - '*...*'
329
+ - '*...*'
330
+ - '*****'
331
+ - '*...*'
332
+ - '*...*'
333
+ - '*...*'
334
+ 'I':
335
+ - '.***.'
336
+ - '..*..'
337
+ - '..*..'
338
+ - '..*..'
339
+ - '..*..'
340
+ - '..*..'
341
+ - '.***.'
342
+ 'J':
343
+ - '..***'
344
+ - '...*.'
345
+ - '...*.'
346
+ - '...*.'
347
+ - '...*.'
348
+ - '*..*.'
349
+ - '.**..'
350
+ 'K':
351
+ - '*...*'
352
+ - '*..*.'
353
+ - '*.*..'
354
+ - '**...'
355
+ - '*.*..'
356
+ - '*..*.'
357
+ - '*...*'
358
+ 'L':
359
+ - '*....'
360
+ - '*....'
361
+ - '*....'
362
+ - '*....'
363
+ - '*....'
364
+ - '*....'
365
+ - '*****'
366
+ 'M':
367
+ - '*...*'
368
+ - '**.**'
369
+ - '*.*.*'
370
+ - '*.*.*'
371
+ - '*...*'
372
+ - '*...*'
373
+ - '*...*'
374
+ 'N':
375
+ - '*...*'
376
+ - '*...*'
377
+ - '**..*'
378
+ - '*.*.*'
379
+ - '*..**'
380
+ - '*...*'
381
+ - '*...*'
382
+ 'O':
383
+ - '.***.'
384
+ - '*...*'
385
+ - '*...*'
386
+ - '*...*'
387
+ - '*...*'
388
+ - '*...*'
389
+ - '.***.'
390
+ 'P':
391
+ - '****.'
392
+ - '*...*'
393
+ - '*...*'
394
+ - '****.'
395
+ - '*....'
396
+ - '*....'
397
+ - '*....'
398
+ 'Q':
399
+ - '.***.'
400
+ - '*...*'
401
+ - '*...*'
402
+ - '*...*'
403
+ - '*.*.*'
404
+ - '*..*.'
405
+ - '.**.*'
406
+ 'R':
407
+ - '****.'
408
+ - '*...*'
409
+ - '*...*'
410
+ - '****.'
411
+ - '*.*..'
412
+ - '*..*.'
413
+ - '*...*'
414
+ 'S':
415
+ - '.****'
416
+ - '*....'
417
+ - '*....'
418
+ - '.***.'
419
+ - '....*'
420
+ - '....*'
421
+ - '****.'
422
+ 'T':
423
+ - '*****'
424
+ - '..*..'
425
+ - '..*..'
426
+ - '..*..'
427
+ - '..*..'
428
+ - '..*..'
429
+ - '..*..'
430
+ 'U':
431
+ - '*...*'
432
+ - '*...*'
433
+ - '*...*'
434
+ - '*...*'
435
+ - '*...*'
436
+ - '*...*'
437
+ - '.***.'
438
+ 'V':
439
+ - '*...*'
440
+ - '*...*'
441
+ - '*...*'
442
+ - '*...*'
443
+ - '.*.*.'
444
+ - '.*.*.'
445
+ - '..*..'
446
+ 'W':
447
+ - '*...*'
448
+ - '*...*'
449
+ - '*...*'
450
+ - '*...*'
451
+ - '*.*.*'
452
+ - '*.*.*'
453
+ - '.*.*.'
454
+ 'X':
455
+ - '*...*'
456
+ - '*...*'
457
+ - '.*.*.'
458
+ - '..*..'
459
+ - '.*.*.'
460
+ - '*...*'
461
+ - '*...*'
462
+ 'Y':
463
+ - '*...*'
464
+ - '*...*'
465
+ - '*...*'
466
+ - '.*.*.'
467
+ - '..*..'
468
+ - '..*..'
469
+ - '..*..'
470
+ 'Z':
471
+ - '*****'
472
+ - '....*'
473
+ - '...*.'
474
+ - '..*..'
475
+ - '.*...'
476
+ - '*....'
477
+ - '*****'
478
+ '[':
479
+ - '..**.'
480
+ - '.*..*'
481
+ - '*...*'
482
+ - '*****'
483
+ - '*...*'
484
+ - '*..*.'
485
+ - '.**..'
486
+ '\':
487
+ - '.....'
488
+ - '*....'
489
+ - '.*...'
490
+ - '..*..'
491
+ - '...*.'
492
+ - '....*'
493
+ - '.....'
494
+ ']':
495
+ - '**...'
496
+ - '..*..'
497
+ - '..*..'
498
+ - '...*.'
499
+ - '..*..'
500
+ - '..*..'
501
+ - '**...'
502
+ '^':
503
+ - '..*..'
504
+ - '.*.*.'
505
+ - '*...*'
506
+ - '.....'
507
+ - '.....'
508
+ - '.....'
509
+ - '.....'
510
+ '_':
511
+ - '.....'
512
+ - '.....'
513
+ - '.....'
514
+ - '.....'
515
+ - '.....'
516
+ - '.....'
517
+ - '*****'
518
+ '`':
519
+ - '..*..'
520
+ - '..*..'
521
+ - '...*.'
522
+ - '.....'
523
+ - '.....'
524
+ - '.....'
525
+ - '.....'
526
+ 'a':
527
+ - '.....'
528
+ - '.....'
529
+ - '.***.'
530
+ - '....*'
531
+ - '.****'
532
+ - '*...*'
533
+ - '.****'
534
+ 'b':
535
+ - '*....'
536
+ - '*....'
537
+ - '*.**.'
538
+ - '**..*'
539
+ - '*...*'
540
+ - '*...*'
541
+ - '****.'
542
+ 'c':
543
+ - '.....'
544
+ - '.....'
545
+ - '.***.'
546
+ - '*....'
547
+ - '*....'
548
+ - '*...*'
549
+ - '.***.'
550
+ 'd':
551
+ - '....*'
552
+ - '....*'
553
+ - '.**.*'
554
+ - '*..**'
555
+ - '*...*'
556
+ - '*...*'
557
+ - '.****'
558
+ 'e':
559
+ - '.....'
560
+ - '.....'
561
+ - '.***.'
562
+ - '*...*'
563
+ - '*****'
564
+ - '*....'
565
+ - '.***.'
566
+ 'f':
567
+ - '..**.'
568
+ - '.*..*'
569
+ - '.*...'
570
+ - '***..'
571
+ - '.*...'
572
+ - '.*...'
573
+ - '.*...'
574
+ 'g':
575
+ - '.....'
576
+ - '.****'
577
+ - '*...*'
578
+ - '*...*'
579
+ - '.****'
580
+ - '....*'
581
+ - '.***.'
582
+ 'h':
583
+ - '*....'
584
+ - '*....'
585
+ - '*.**.'
586
+ - '**..*'
587
+ - '*...*'
588
+ - '*...*'
589
+ - '*...*'
590
+ 'i':
591
+ - '..*..'
592
+ - '.....'
593
+ - '.**..'
594
+ - '..*..'
595
+ - '..*..'
596
+ - '..*..'
597
+ - '.***.'
598
+ 'j':
599
+ - '...*.'
600
+ - '.....'
601
+ - '..**.'
602
+ - '...*.'
603
+ - '...*.'
604
+ - '*..*.'
605
+ - '.**..'
606
+ 'k':
607
+ - '.*...'
608
+ - '.*...'
609
+ - '.*..*'
610
+ - '.*.*.'
611
+ - '.**..'
612
+ - '.*.*.'
613
+ - '.*..*'
614
+ 'l':
615
+ - '.**..'
616
+ - '..*..'
617
+ - '..*..'
618
+ - '..*..'
619
+ - '..*..'
620
+ - '..*..'
621
+ - '.***.'
622
+ 'm':
623
+ - '.....'
624
+ - '.....'
625
+ - '**.*.'
626
+ - '*.*.*'
627
+ - '*.*.*'
628
+ - '*...*'
629
+ - '*...*'
630
+ 'n':
631
+ - '.....'
632
+ - '.....'
633
+ - '*.**.'
634
+ - '**..*'
635
+ - '*...*'
636
+ - '*...*'
637
+ - '*...*'
638
+ 'o':
639
+ - '.....'
640
+ - '.....'
641
+ - '.***.'
642
+ - '*...*'
643
+ - '*...*'
644
+ - '*...*'
645
+ - '.***.'
646
+ 'p':
647
+ - '.....'
648
+ - '.....'
649
+ - '****.'
650
+ - '*...*'
651
+ - '****.'
652
+ - '*....'
653
+ - '*....'
654
+ 'q':
655
+ - '.....'
656
+ - '.....'
657
+ - '.**.*'
658
+ - '*..**'
659
+ - '.****'
660
+ - '....*'
661
+ - '....*'
662
+ 'r':
663
+ - '.....'
664
+ - '.....'
665
+ - '*.**.'
666
+ - '**..*'
667
+ - '*....'
668
+ - '*....'
669
+ - '*....'
670
+ 's':
671
+ - '.....'
672
+ - '.....'
673
+ - '.***.'
674
+ - '*....'
675
+ - '.***.'
676
+ - '....*'
677
+ - '****.'
678
+ 't':
679
+ - '.*...'
680
+ - '.*...'
681
+ - '***..'
682
+ - '.*...'
683
+ - '.*...'
684
+ - '.*..*'
685
+ - '..**.'
686
+ 'u':
687
+ - '.....'
688
+ - '.....'
689
+ - '*...*'
690
+ - '*...*'
691
+ - '*...*'
692
+ - '*..**'
693
+ - '.**.*'
694
+ 'v':
695
+ - '.....'
696
+ - '.....'
697
+ - '*...*'
698
+ - '*...*'
699
+ - '*...*'
700
+ - '.*.*.'
701
+ - '..*..'
702
+ 'w':
703
+ - '.....'
704
+ - '.....'
705
+ - '*...*'
706
+ - '*...*'
707
+ - '*.*.*'
708
+ - '*.*.*'
709
+ - '.*.*.'
710
+ 'x':
711
+ - '.....'
712
+ - '.....'
713
+ - '*...*'
714
+ - '.*.*.'
715
+ - '..*..'
716
+ - '.*.*.'
717
+ - '*...*'
718
+ 'y':
719
+ - '.....'
720
+ - '.....'
721
+ - '*...*'
722
+ - '*...*'
723
+ - '.****'
724
+ - '....*'
725
+ - '.***.'
726
+ 'z':
727
+ - '.....'
728
+ - '.....'
729
+ - '*****'
730
+ - '...*.'
731
+ - '..*..'
732
+ - '.*...'
733
+ - '*****'
734
+ '{':
735
+ - '...**'
736
+ - '..*..'
737
+ - '..*..'
738
+ - '.*...'
739
+ - '..*..'
740
+ - '..*..'
741
+ - '...**'
742
+ '|':
743
+ - '..*..'
744
+ - '..*..'
745
+ - '..*..'
746
+ - '..*..'
747
+ - '..*..'
748
+ - '..*..'
749
+ - '..*..'
750
+ '~':
751
+ - '.....'
752
+ - '.*...'
753
+ - '*.*.*'
754
+ - '...*.'
755
+ - '.....'
756
+ - '.....'
757
+ - '.....'
@@ -0,0 +1,246 @@
1
+ # Peter Pan - a Ruby gem providing a virtual screen buffer with viewport
2
+ # panning. For the Dream Cheeky LED sign and others.
3
+ #
4
+ # Home page at https://github.com/xunker/peter_pan
5
+ #
6
+ # Author:: Matthew Nielsen (mailto:xunker@pyxidis.org)
7
+ # Copyright:: Copyright (c) 2014
8
+ # License:: MIT
9
+
10
+ require 'yaml'
11
+ class PeterPan
12
+ attr_reader :viewport_width, :viewport_height, :empty_point_character
13
+
14
+ VERSION = "1.0.0"
15
+
16
+ # Possible Options:
17
+ #
18
+ # * :viewport_width - Viewport width, integer, default 21
19
+ # * :viewport_height - Viewport height, integer, default 7
20
+ # * :empty_point_character - the char of an empty cell (default ' ')
21
+ # * :buffer_width - Buffer width, integer, default 0
22
+ # * :buffer_height - Buffer height, integer, default 0
23
+ #
24
+ # NOTE: The buffer will automatically expand dimensionally to hold
25
+ # any point that is #plot()'ed or text written with #write().
26
+ def initialize(opts={})
27
+ @viewport_width = (opts[:viewport_width] || 21).to_i # x
28
+ @viewport_height = (opts[:viewport_height] || 7).to_i # y
29
+ @font_name = 'transpo' # only font for now
30
+ @empty_point_character = (opts[:empty_point_character] || ' ')
31
+ buffer_changed!(false)
32
+ clear_buffer!(
33
+ :width => (opts[:buffer_width] || 0),
34
+ :height => (opts[:buffer_height] || 0)
35
+ )
36
+ end
37
+
38
+ # Draw a point in the virtual buffer.
39
+ # The virtual buffer will be enlarged automatically.
40
+ def plot(x, y, value='*')
41
+ 1.upto(y+1) do |i|
42
+ @buffer[i-1] ||= []
43
+ 1.upto(x+1) do |ii|
44
+ @buffer[i-1][ii-1] ||= @empty_point_character
45
+ end
46
+ end
47
+
48
+ @buffer[y][x] = value.to_s.slice(0,1)
49
+
50
+ buffer_changed!
51
+ end
52
+
53
+ # Same as #show_buffer but with an ascii-art border around it.
54
+ def pretty_print_buffer
55
+ wrap_frame_with_border(show_buffer)
56
+ end
57
+
58
+ # Return the current buffer as a string delimited by "\n" characters
59
+ def show_buffer
60
+ normalize_buffer_width
61
+
62
+ @buffer.map{|bx| "#{bx.join}\n" }.join
63
+ end
64
+
65
+ # Return an integer of the width of the buffer at it's widest point.
66
+ def buffer_width
67
+ if !@buffer_width || buffer_changed?
68
+ @buffer_width = 0
69
+ @buffer.each do |by|
70
+ @buffer_width = by.size if by.size > @buffer_width
71
+ end
72
+ end
73
+ @buffer_width
74
+ end
75
+
76
+ # Return an integer of the height of the buffer at it tallest point
77
+ def buffer_height
78
+ @buffer.size
79
+ end
80
+
81
+ # Show a viewport area of the larger buffer.
82
+ # width and height of the viewport can be set in the object
83
+ # initialization for defaults, or manually here.
84
+ # Returns a string delimited by "\n" characters.
85
+ def show_viewport(x,y,x2=@viewport_width,y2=@viewport_height)
86
+ normalize_buffer_width
87
+
88
+ y.upto((y2-1)+y).map do |i|
89
+ buffer_row = @buffer[i] || @viewport_width.times.map{@empty_point_character}
90
+ sprintf("%-#{x2}s", buffer_row[x..((x2-1)+x)].join) + "\n"
91
+ end.join
92
+ end
93
+
94
+ # Same as #show_viewort, but with an ascii-art border around it.
95
+ def pretty_print_viewport(x,y,x2=@viewport_width,y2=@viewport_height)
96
+ wrap_frame_with_border(show_viewport(x,y,x2,y2))
97
+ end
98
+
99
+ # Move the viewport over the buffer from x1/y1 to x2/y2.
100
+ # Returns an array of strings. Each string is a frame of the pan path
101
+ # of the kind returned by #show_viewport.
102
+ def pan_viewport(x1, y1, x2, y2)
103
+ calculate_integral_points(x1, y1, x2, y2).map do |px, py|
104
+ show_viewport(px, py)
105
+ end
106
+ end
107
+
108
+ # Same as #pan_viewport, but with an ascii-art border around each frame.
109
+ def pretty_pan_viewport(x1, y1, x2, y2)
110
+ pan_viewport(x1, y1, x2, y2).map{|vp| wrap_frame_with_border(vp) }
111
+ end
112
+
113
+ # Like pan_viewport, but multiple pairs of coordinates can be passed.
114
+ # The first pair will be used as the start and the viewport will be
115
+ # panned from coordinate-pair to coordinate-pair.
116
+ # It expects to be passed an array-like list of coordinate pairs.
117
+ # It returns an array of string representing the frames of the pathing.
118
+ def path_viewport(*coordinates)
119
+ coordinates.flatten!
120
+ start_x = coordinates.shift
121
+ start_y = coordinates.shift
122
+ coordinates.flatten.each_slice(2).map do |x,y|
123
+ pan = pan_viewport(start_x, start_y, x, y)
124
+ start_x = x
125
+ start_y = y
126
+ pan
127
+ end.flatten
128
+ end
129
+
130
+ # Same as #path_viewport, but with an ascii-art border around each frame.
131
+ def pretty_pan_viewport(*coordinates)
132
+ path_viewport(coordinates).map{|vp| wrap_frame_with_border(vp) }
133
+ end
134
+
135
+ # Draw a text sprint to the buffer at given coordinates.
136
+ # * sprite is an ARRAY of string representing the image.
137
+ def plot_sprite(sprite, x, y)
138
+ sprite.each_with_index do |line, line_y|
139
+ line.split('').each_with_index do |c, char_x|
140
+ plot(char_x + x, line_y + y, c)
141
+ end
142
+ end
143
+ end
144
+
145
+ # Write a string to the buffer at the given coordinates.
146
+ def write(x, y, message)
147
+ letter_x = x
148
+ message.split('').each do |c|
149
+ char = font['characters'][c].map{|l|l.gsub('.', @empty_point_character)}
150
+ plot_sprite(char, letter_x, y)
151
+ letter_x = letter_x + font['width'] + 1
152
+ end
153
+ end
154
+
155
+ # clears everything out of the buffer.
156
+ # By default, sets the buffer dimensions to 0x0. Optionally, you can pass
157
+ # :width and :height args and the buffer dimentions will be set accordingly.
158
+ # By default the buffer will be filled with space character, but you can
159
+ # set the char to be used by passing :clear_with
160
+ def clear_buffer!(opts={})
161
+ opts = { :width => 0, :height => 0, :clear_with => @empty_point_character }.merge(opts)
162
+ @buffer = [[]]
163
+ opts[:height].times do |y|
164
+ @buffer[y] = []
165
+ opts[:width].times do |x|
166
+ @buffer[y][x] = opts[:clear_with].to_s.slice(0,1)
167
+ end
168
+ end
169
+ buffer_changed!
170
+ end
171
+
172
+ # returns a data structure representing the current font used by #write.
173
+ def font
174
+ @font ||= YAML.load(File.new("./fonts/#{@font_name}.yml").read)
175
+ end
176
+
177
+ private
178
+
179
+ def buffer_changed!(val = true)
180
+ @buffer_changed = val
181
+ end
182
+
183
+ def buffer_changed?
184
+ !!@buffer_changed
185
+ end
186
+
187
+ def normalize_buffer_width
188
+ return unless buffer_changed?
189
+
190
+ @buffer.each do |by|
191
+ if by.size < buffer_width
192
+ (by.size-1).upto(buffer_width-1) do |i|
193
+ by[i] = @empty_point_character
194
+ end
195
+ end
196
+ end
197
+
198
+ buffer_changed!
199
+ end
200
+
201
+
202
+ def wrap_frame_with_border(content)
203
+ content_width = content.index("\n")
204
+ str = "+#{'-' * content_width}+\n"
205
+ vp = content
206
+ str << vp.gsub(/^/, '|').gsub(/$/, '|').gsub(/^\|$/, '')
207
+ str << "+#{'-' * content_width}+\n"
208
+ str
209
+ end
210
+
211
+ # Why yes, actually, I did fail Jr. High math. Why do you ask?
212
+ def calculate_integral_points(x1, y1, x2, y2)
213
+ x_integrals = calculate_integrals(x1, x2)
214
+ y_integrals = calculate_integrals(y1, y2)
215
+
216
+ (x_integrals, y_integrals) = standardize_integral_lengths(x_integrals, y_integrals)
217
+
218
+ x_integrals.zip(y_integrals)
219
+ end
220
+
221
+ def standardize_integral_lengths(one, two)
222
+ while one.length < two.length
223
+ one.unshift(one.first)
224
+ end
225
+
226
+ while two.length < one.length
227
+ two.unshift(two.first)
228
+ end
229
+
230
+ [one, two]
231
+ end
232
+
233
+ def calculate_integrals(starting, ending)
234
+ integrals = []
235
+ if starting < ending
236
+ starting.upto(ending) do |i|
237
+ integrals << i
238
+ end
239
+ else
240
+ starting.downto(ending) do |i|
241
+ integrals << i
242
+ end
243
+ end
244
+ integrals
245
+ end
246
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'peter_pan'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "peter_pan"
8
+ spec.version = PeterPan::VERSION
9
+ spec.authors = ["Matthew Nielsen"]
10
+ spec.email = ["xunker@pyxidis.org"]
11
+ spec.description = %q{A virtual screen buffer with viewport panning. For the Dream Cheeky LED sign and others.}
12
+ spec.summary = %q{A virtual screen buffer with viewport panning. For the Dream Cheeky LED sign and others.}
13
+ spec.homepage = "https://github.com/xunker/peter_pan"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peter_pan
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Nielsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-02-05 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "1.3"
22
+ type: :development
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id003
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ description: A virtual screen buffer with viewport panning. For the Dream Cheeky LED sign and others.
36
+ email:
37
+ - xunker@pyxidis.org
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - examples/dream_cheeky.rb
51
+ - examples/to_screen.rb
52
+ - fonts/transpo.yml
53
+ - lib/peter_pan.rb
54
+ - peter_pan.gemspec
55
+ homepage: https://github.com/xunker/peter_pan
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - *id003
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - *id003
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 2.0.13
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: A virtual screen buffer with viewport panning. For the Dream Cheeky LED sign and others.
78
+ test_files: []
79
+