oekaki 0.1.4 → 0.1.5

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
2
  SHA1:
3
- metadata.gz: 2c1e71b934906a7cb076791108504709515d4253
4
- data.tar.gz: 07b385f02f2f514bce69049a805a8427443927ba
3
+ metadata.gz: c96851106c0f57e9f13fa74fbd356b5ca0b8b16b
4
+ data.tar.gz: 23096e87b6d8ecac83c0d5d644a4300edf231a26
5
5
  SHA512:
6
- metadata.gz: 3634834be985b965c7168bfa06d39d79b9b335e871d37921743f6c1ed86fbb35ff12643dbb1094eab69060e2a1b5d439e8785841cc31c464d1d09d9853319104
7
- data.tar.gz: 16f5b93a27f97bbf2d8fb511199e648aeab3b5dbaed3f7e7cc8d6d94a53761fcf813128af4cac4b5e8efa56a095cafbb4b73bfb6a7dc54ac771170027597e91a
6
+ metadata.gz: 112c0c43213190106f6e2482847ed2163ab4e79a1dd337ced6fa3158607f482dc6a26c8fad68f74f82e8e919b282dd4d4f73d2efc399639c5d76cc9475ee2c55
7
+ data.tar.gz: 9c33099cddcf14aab96e84b20bc7a5cd7bf9d76fe7bb4f7aa0bbc7c1d7523df808e922dab7104cc716fcbf52e4120fe837c039e6ee500c570a106536321909b4
data/README CHANGED
@@ -179,3 +179,35 @@
179
179
  end
180
180
  end
181
181
  end
182
+  
183
+  
184
+ require 'oekaki'
185
+
186
+ Width, Height = 600, 400
187
+
188
+ Oekaki.app width: Width, height: Height, title: "C curve" do
189
+ draw do
190
+ clear
191
+
192
+ t = Oekaki::Turtle.new
193
+ t.move(-130, -100)
194
+ t.color(0, 65535, 0)
195
+ ratio = sqrt(2) / 2
196
+
197
+ drawing = lambda do |length, depth|
198
+ if depth.zero?
199
+ t.forward(length)
200
+ else
201
+ t.left(45)
202
+ drawing[length * ratio, depth - 1]
203
+ t.right(90)
204
+ drawing[length * ratio, depth - 1]
205
+ t.left(45)
206
+ end
207
+ end
208
+
209
+ drawing[260.0, 10]
210
+ end
211
+ end
212
+  
213
+  
@@ -0,0 +1,28 @@
1
+ require 'oekaki'
2
+
3
+ Width, Height = 600, 400
4
+
5
+ Oekaki.app width: Width, height: Height, title: "C curve" do
6
+ draw do
7
+ clear
8
+
9
+ t = Oekaki::Turtle.new
10
+ t.move(-130, -100)
11
+ t.color(0, 65535, 0)
12
+ ratio = sqrt(2) / 2
13
+
14
+ drawing = lambda do |length, depth|
15
+ if depth.zero?
16
+ t.forward(length)
17
+ else
18
+ t.left(45)
19
+ drawing[length * ratio, depth - 1]
20
+ t.right(90)
21
+ drawing[length * ratio, depth - 1]
22
+ t.left(45)
23
+ end
24
+ end
25
+
26
+ drawing[260.0, 10]
27
+ end
28
+ end
@@ -192,6 +192,54 @@ module Oekaki
192
192
  end
193
193
  end
194
194
 
195
+ class Turtle < Tool
196
+ def initialize
197
+ @pen = Tool.new
198
+ @pen_po = Vector[0, 0]
199
+ @dir = Vector[1, 0]
200
+ @color_t = [65535, 65535, 65535]
201
+ @width, @height = @pen.get_window_size
202
+ end
203
+ attr_accessor :pen_po, :dir
204
+
205
+ def left(deg)
206
+ θ = PI * deg / 180
207
+ @dir = Matrix[[cos(θ), -sin(θ)], [sin(θ), cos(θ)]] * @dir
208
+ end
209
+
210
+ def right(deg)
211
+ left(-deg)
212
+ end
213
+
214
+ def forward(length, draw = true)
215
+ next_po = @pen_po + @dir * length
216
+ if draw
217
+ @pen.color(*@color_t)
218
+ @pen.line(@width / 2 + next_po[0], @height / 2 - next_po[1],
219
+ @width / 2 + @pen_po[0], @height / 2 - @pen_po[1])
220
+ end
221
+ @pen_po = next_po
222
+ end
223
+
224
+ def back(length)
225
+ forward(-length, false)
226
+ end
227
+
228
+ def color(r, g, b)
229
+ @color_t = [r, g, b]
230
+ @pen.color(*@color_t)
231
+ end
232
+
233
+ def circle(radius, fill = false)
234
+ @pen.color(*@color_t)
235
+ @pen.circle(fill, @width / 2 + @pen_po[0], @height / 2 - @pen_po[1], radius)
236
+ end
237
+
238
+ def move(x, y)
239
+ @pen_po = Vector[x, y]
240
+ end
241
+ end
242
+
195
243
  def self.app(width: 300, height: 300, title: "oekaki", resizable: false, &bk)
196
244
  W.title = title
197
245
  W.set_size_request(width, height)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oekaki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - obelisk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-12 00:00:00.000000000 Z
11
+ date: 2018-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gtk2
@@ -43,6 +43,7 @@ files:
43
43
  - example/oekaki_sample7.rb
44
44
  - example/oekaki_sample8.rb
45
45
  - example/oekaki_sample9.rb
46
+ - example/turtle_c_curve.rb
46
47
  - lib/oekaki.rb
47
48
  homepage: http://obelisk.hatenablog.com/entry/2016/12/15/172026
48
49
  licenses: