plumo 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: da6fa84e3622b29e242b5f8e88cdf79c4c1ae25d
4
- data.tar.gz: 65bb18eddc24a5661306929ea4093312ef960079
2
+ SHA256:
3
+ metadata.gz: 2165f226a30aad06edd524cdb4e816f77b1e893fc51af826af15d0d18f3c51bf
4
+ data.tar.gz: 840c3b5d51605745d304bf28cd972beee0210b8e3aacd0c277521f873a544177
5
5
  SHA512:
6
- metadata.gz: ba41af30bae3cd2854f16d2edfdc5ebf627de0c7161830b1dd97f0fb465961888326072ece36d8837fbef49acfb9b355a16503d71fe3cc32b4d923a9e11204e2
7
- data.tar.gz: a8dc030e5478b057b313047ed5da1ae5694c2e5cc0321acbb9125e7d72c8fe0b8e4e8cb3ea63059fdd59f012bac7f4457f8bb5a2344de026e22a04ddf9c5f9b2
6
+ metadata.gz: a9648a88c65ae434929202659571b760bb886b7577274b9039699755caca3133769d47d84dcb3f1f9684e95a5c1f613cd1284c913eba6d30be01ae56f56e454e
7
+ data.tar.gz: f048a5ca88cb137c6d42173157a3ed393d082beda9ea79b006de98fef205e3a9c5479283e4d9c28631e0e431674a3f7693271846f584e2f3a5d5971e2a4a8fd1
data/lib/plumo.rb CHANGED
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  require 'webrick'
4
2
  require 'cgi'
5
3
  require 'json'
@@ -7,14 +5,13 @@ require 'pp'
7
5
  require 'timeout'
8
6
 
9
7
  class Plumo
10
-
11
8
  class NullLogger
12
9
  def <<(arg)
13
10
  ;
14
11
  end
15
12
  end
16
13
 
17
- def initialize(w, h, opts={})
14
+ def initialize(w, h, opts = {})
18
15
  @w = w
19
16
  @h = h
20
17
  @session_id = nil
@@ -159,7 +156,7 @@ class Plumo
159
156
  )
160
157
  end
161
158
 
162
- def line(x0, y0, x1, y1, style={})
159
+ def line(x0, y0, x1, y1, style = {})
163
160
  cmds = []
164
161
 
165
162
  if style.key?(:color)
@@ -176,7 +173,7 @@ class Plumo
176
173
  draw(*cmds)
177
174
  end
178
175
 
179
- def stroke_rect(x, y, w, h, style={})
176
+ def stroke_rect(x, y, w, h, style = {})
180
177
  cmds = []
181
178
 
182
179
  if style.key?(:color)
@@ -190,7 +187,7 @@ class Plumo
190
187
  draw(*cmds)
191
188
  end
192
189
 
193
- def fill_rect(x, y, w, h, style={})
190
+ def fill_rect(x, y, w, h, style = {})
194
191
  cmds = []
195
192
 
196
193
  if style.key?(:color)
@@ -205,7 +202,7 @@ class Plumo
205
202
  draw(*cmds)
206
203
  end
207
204
 
208
- def stroke_circle(x, y, r, style={})
205
+ def stroke_circle(x, y, r, style = {})
209
206
  cmds = []
210
207
 
211
208
  if style.key?(:color)
@@ -225,7 +222,7 @@ class Plumo
225
222
  draw(*cmds)
226
223
  end
227
224
 
228
- def fill_circle(x, y, r, style={})
225
+ def fill_circle(x, y, r, style = {})
229
226
  cmds = []
230
227
 
231
228
  if style.key?(:color)
@@ -39,7 +39,11 @@
39
39
  <canvas
40
40
  width="100px" height="100px"
41
41
  style="border: solid 1px #000;"
42
- />
42
+ ></canvas>
43
+
44
+ <div>
45
+ <button id="btn_save">save</button>
46
+ </div>
43
47
  </body>
44
48
 
45
49
  </html>
@@ -1,15 +1,19 @@
1
- const puts = (...args)=>{
1
+ function puts (...args) {
2
2
  console.log(...args);
3
- };
3
+ }
4
+
5
+ function getElement(selector) {
6
+ return document.querySelector(selector);
7
+ }
4
8
 
5
9
  class Comet {
6
- constructor(){
10
+ constructor() {
7
11
  this.timer = null;
8
12
  this.connected = true;
9
- this.sessionId = new Date().getTime();
13
+ this.sessionId = Date.now();
10
14
  }
11
15
 
12
- _open(){
16
+ _open() {
13
17
  $.post("/comet", { sessionid: this.sessionId })
14
18
  .then((data)=>{
15
19
  if (this.connected) {
@@ -26,14 +30,14 @@ class Comet {
26
30
  });
27
31
  }
28
32
 
29
- open(){
33
+ open() {
30
34
  clearTimeout(this.timer);
31
35
  this.timer = setTimeout(()=>{
32
36
  this._open();
33
37
  }, 0);
34
38
  }
35
39
 
36
- onclose(){
40
+ onclose() {
37
41
  this.connected = false;
38
42
  console.info("onclose");
39
43
  $.post("/close");
@@ -42,19 +46,19 @@ class Comet {
42
46
  }
43
47
 
44
48
  class CanvasWrapper {
45
- constructor(el){
49
+ constructor(el) {
46
50
  this.el = el;
47
51
  this.$el = $(el);
48
52
  this.ctx = el.getContext("2d");
49
53
  }
50
54
 
51
- reset(w, h){
55
+ reset(w, h) {
52
56
  this.$el.attr("width" , w);
53
57
  this.$el.attr("height", h);
54
58
  this.$el.show();
55
59
  }
56
60
 
57
- execCmd(cmd){
61
+ execCmd(cmd) {
58
62
  const _cmd = cmd[0];
59
63
  const args = cmd.slice(1);
60
64
 
@@ -71,13 +75,19 @@ class CanvasWrapper {
71
75
  }
72
76
 
73
77
  class App {
74
- constructor(){
78
+ constructor() {
75
79
  this.comet = new Comet();
76
- this.cw = new CanvasWrapper($("canvas").get(0));
80
+ this.cw = new CanvasWrapper(getElement("canvas"));
77
81
  this.resTimes = [];
78
82
  }
79
83
 
80
- start(){
84
+ start() {
85
+ // events
86
+ getElement("#btn_save").addEventListener(
87
+ "click",
88
+ ()=>{ this.saveImage(); }
89
+ );
90
+
81
91
  // comet
82
92
  this.comet.onmessage = this.onmessage.bind(this);
83
93
  this.comet.open();
@@ -88,7 +98,7 @@ class App {
88
98
  }, 1000);
89
99
  }
90
100
 
91
- onmessage(data){
101
+ onmessage(data) {
92
102
  this.refreshRps();
93
103
  this.refreshQsize(data.qsize, data.events.length);
94
104
 
@@ -114,8 +124,8 @@ class App {
114
124
  });
115
125
  }
116
126
 
117
- refreshRps(){
118
- const currentTime = new Date().getTime();
127
+ refreshRps() {
128
+ const currentTime = Date.now();
119
129
  this.resTimes.push(currentTime);
120
130
  const limit = currentTime - 1000;
121
131
 
@@ -127,7 +137,7 @@ class App {
127
137
  $("#rps").text(recent.length);
128
138
  }
129
139
 
130
- refreshQsize(qsize, numEvents){
140
+ refreshQsize(qsize, numEvents) {
131
141
  $("#qsize").text(qsize);
132
142
 
133
143
  let qsizeBar = "#".repeat(numEvents);
@@ -137,7 +147,7 @@ class App {
137
147
  $("#qsize_bar").text(qsizeBar);
138
148
  }
139
149
 
140
- ping(){
150
+ ping() {
141
151
  if (this.comet.connected) {
142
152
  return;
143
153
  }
@@ -156,9 +166,20 @@ class App {
156
166
  $("#ping").text(text + ".");
157
167
  });
158
168
  }
169
+
170
+ saveImage() {
171
+ const dataUrl = getElement("canvas").toDataURL();
172
+ const a = document.createElement("a");
173
+ a.href = dataUrl;
174
+ a.download = "image.png";
175
+ a.click();
176
+ }
159
177
  }
160
178
 
161
- $(()=>{
162
- const app = new App();
163
- app.start();
164
- });
179
+ document.addEventListener(
180
+ "DOMContentLoaded",
181
+ ()=>{
182
+ const app = new App();
183
+ app.start();
184
+ }
185
+ );
data/lib/plumo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
- module Plumo
2
- VERSION = "0.0.4"
1
+ class Plumo
2
+ VERSION = "0.1.0"
3
3
  end
data/plumo.gemspec CHANGED
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'plumo/version'
@@ -21,7 +20,7 @@ Gem::Specification.new do |spec|
21
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
21
  spec.require_paths = ["lib"]
23
22
 
24
- spec.add_development_dependency "bundler", "~> 1.17"
23
+ spec.add_development_dependency "bundler", "~> 2.1"
25
24
  spec.add_development_dependency "rake", "~> 12.0"
26
25
  # spec.add_development_dependency "minitest", "~> 5.0"
27
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plumo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sonota88
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2021-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -75,8 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.6.8
78
+ rubygems_version: 3.0.3
80
79
  signing_key:
81
80
  specification_version: 4
82
81
  summary: Easy 2d-graphincs using Ruby and Canvas