shoes 4.0.0.pre2 → 4.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +32 -21
  3. metadata +18 -337
  4. data/CHANGELOG +0 -84
  5. data/Gemfile +0 -24
  6. data/Guardfile +0 -11
  7. data/Rakefile +0 -14
  8. data/app.yaml +0 -60
  9. data/benchmark/app_clear.rb +0 -21
  10. data/benchmark/clear.rb +0 -69
  11. data/benchmark/memory/text_dispose.rb +0 -9
  12. data/benchmark/para_creator.rb +0 -9
  13. data/benchmark/paras.rb +0 -52
  14. data/benchmark/urls.rb +0 -40
  15. data/bin/ruby-shoes +0 -6
  16. data/bin/shoes-guard +0 -8
  17. data/bin/shoes-stub +0 -59
  18. data/ext/install/Rakefile +0 -29
  19. data/ext/install/shoes.bat +0 -9
  20. data/lib/shoes.rb +0 -5
  21. data/lib/shoes/ui/cli.rb +0 -102
  22. data/lib/shoes/ui/help.rb +0 -535
  23. data/lib/shoes/ui/manual.rb +0 -6
  24. data/lib/shoes/version.rb +0 -3
  25. data/manifests/common.rb +0 -34
  26. data/manifests/shoes.rb +0 -44
  27. data/samples/Gemfile +0 -3
  28. data/samples/Gemfile.lock +0 -35
  29. data/samples/README +0 -97
  30. data/samples/boom.rb +0 -239
  31. data/samples/class-book-adjusted.rb +0 -45
  32. data/samples/class-book.rb +0 -43
  33. data/samples/class-book.yaml +0 -387
  34. data/samples/clicky.rb +0 -24
  35. data/samples/cy.png +0 -0
  36. data/samples/expert-definr.rb +0 -23
  37. data/samples/expert-funnies.rb +0 -60
  38. data/samples/expert-game-of-life-adjusted.rb +0 -249
  39. data/samples/expert-game-of-life.rb +0 -243
  40. data/samples/expert-irb-adjusted.rb +0 -110
  41. data/samples/expert-irb.rb +0 -112
  42. data/samples/expert-minesweeper-adjusted.rb +0 -272
  43. data/samples/expert-minesweeper.rb +0 -267
  44. data/samples/expert-othello-adjusted.rb +0 -325
  45. data/samples/expert-othello.rb +0 -318
  46. data/samples/expert-pong.rb +0 -62
  47. data/samples/expert-snake.rb +0 -78
  48. data/samples/expert-tankspank.rb +0 -385
  49. data/samples/flow.rb +0 -63
  50. data/samples/good-arc.rb +0 -45
  51. data/samples/good-clock.rb +0 -51
  52. data/samples/good-displace.rb +0 -98
  53. data/samples/good-follow.rb +0 -26
  54. data/samples/good-potato-chopping.rb +0 -22
  55. data/samples/good-reminder.rb +0 -174
  56. data/samples/good-vjot.rb +0 -58
  57. data/samples/gray.rb +0 -11
  58. data/samples/loogink.png +0 -0
  59. data/samples/nks_booklist.rb +0 -24
  60. data/samples/nks_breadsticks.rb +0 -7
  61. data/samples/nks_dancing_circle.rb +0 -13
  62. data/samples/nks_dictionary.rb +0 -23
  63. data/samples/nks_edit_box.rb +0 -4
  64. data/samples/nks_edit_line.rb +0 -6
  65. data/samples/nks_notes.rb +0 -16
  66. data/samples/nks_poem.rb +0 -22
  67. data/samples/nks_self.rb +0 -6
  68. data/samples/nks_text_sizes.rb +0 -10
  69. data/samples/nks_trurl.rb +0 -5
  70. data/samples/original-manual-adjusted.rb +0 -475
  71. data/samples/original-manual.rb +0 -472
  72. data/samples/packaging/package_me.rb +0 -6
  73. data/samples/potato_chopping/1258_s001.gif +0 -0
  74. data/samples/potato_chopping/1258_s002.gif +0 -0
  75. data/samples/potato_chopping/1258_s003.gif +0 -0
  76. data/samples/potato_chopping/1258_s004.gif +0 -0
  77. data/samples/potato_chopping/1258_s005.gif +0 -0
  78. data/samples/potato_chopping/1258_s006.gif +0 -0
  79. data/samples/potato_chopping/1258_s007.gif +0 -0
  80. data/samples/potato_chopping/1258_s008.gif +0 -0
  81. data/samples/potato_chopping/1258_s009.gif +0 -0
  82. data/samples/potato_chopping/1258_s010.gif +0 -0
  83. data/samples/potato_chopping/1258_s011.gif +0 -0
  84. data/samples/potato_chopping/1258_s012.gif +0 -0
  85. data/samples/potato_chopping/1258_s013.gif +0 -0
  86. data/samples/potato_chopping/1258_s014.gif +0 -0
  87. data/samples/potato_chopping/1258_s015.gif +0 -0
  88. data/samples/potato_chopping/1258_s016.gif +0 -0
  89. data/samples/potato_chopping/1258_s017.gif +0 -0
  90. data/samples/potato_chopping/1258_s018.gif +0 -0
  91. data/samples/potato_chopping/1258_s019.gif +0 -0
  92. data/samples/potato_chopping/1258_s020.gif +0 -0
  93. data/samples/potato_chopping/1258_s021.gif +0 -0
  94. data/samples/potato_chopping/1258_s022.gif +0 -0
  95. data/samples/potato_chopping/1258_s023.gif +0 -0
  96. data/samples/potato_chopping/1258_s024.gif +0 -0
  97. data/samples/potato_chopping/1258_s025.gif +0 -0
  98. data/samples/potato_chopping/1258_s026.gif +0 -0
  99. data/samples/potato_chopping/1258_s027.gif +0 -0
  100. data/samples/potato_chopping/1258_s028.gif +0 -0
  101. data/samples/potato_chopping/1258_s029.gif +0 -0
  102. data/samples/potato_chopping/1258_s030.gif +0 -0
  103. data/samples/potato_chopping/1258_s031.gif +0 -0
  104. data/samples/potato_chopping/1258_s032.gif +0 -0
  105. data/samples/potato_chopping/1258_s033.gif +0 -0
  106. data/samples/potato_chopping/1258_s034.gif +0 -0
  107. data/samples/potato_chopping/1258_s035.gif +0 -0
  108. data/samples/potato_chopping/1258_s036.gif +0 -0
  109. data/samples/potato_chopping/1258_s037.gif +0 -0
  110. data/samples/potato_chopping/1258_s038.gif +0 -0
  111. data/samples/potato_chopping/1258_s039.gif +0 -0
  112. data/samples/potato_chopping/1258_s040.gif +0 -0
  113. data/samples/potato_chopping/1258_s041.gif +0 -0
  114. data/samples/potato_chopping/1258_s042.gif +0 -0
  115. data/samples/potato_chopping/1258_s043.gif +0 -0
  116. data/samples/potato_chopping/1258_s044.gif +0 -0
  117. data/samples/potato_chopping/1258_s045.gif +0 -0
  118. data/samples/potato_chopping/1258_s046.gif +0 -0
  119. data/samples/potato_chopping/1258_s047.gif +0 -0
  120. data/samples/potato_chopping/1258_s048.gif +0 -0
  121. data/samples/potato_chopping/1258_s049.gif +0 -0
  122. data/samples/potato_chopping/1258_s050.gif +0 -0
  123. data/samples/potato_chopping/1258_s051.gif +0 -0
  124. data/samples/potato_chopping/1258_s052.gif +0 -0
  125. data/samples/potato_chopping/1258_s053.gif +0 -0
  126. data/samples/potato_chopping/1258_s054.gif +0 -0
  127. data/samples/potato_chopping/1258_s055.gif +0 -0
  128. data/samples/potato_chopping/1258_s056.gif +0 -0
  129. data/samples/potato_chopping/1258_s057.gif +0 -0
  130. data/samples/potato_chopping/1258_s058.gif +0 -0
  131. data/samples/potato_chopping/1258_s059.gif +0 -0
  132. data/samples/present.rb +0 -27
  133. data/samples/progress.rb +0 -10
  134. data/samples/sample1.rb +0 -30
  135. data/samples/sample12.rb +0 -21
  136. data/samples/sample13.rb +0 -13
  137. data/samples/sample14.rb +0 -64
  138. data/samples/sample15.rb +0 -18
  139. data/samples/sample16.rb +0 -10
  140. data/samples/sample17.rb +0 -10
  141. data/samples/sample2.rb +0 -14
  142. data/samples/sample21.rb +0 -5
  143. data/samples/sample23.rb +0 -8
  144. data/samples/sample24.rb +0 -21
  145. data/samples/sample27.rb +0 -18
  146. data/samples/sample3.rb +0 -14
  147. data/samples/sample31.rb +0 -22
  148. data/samples/sample34.rb +0 -27
  149. data/samples/sample35.rb +0 -32
  150. data/samples/sample37.rb +0 -8
  151. data/samples/sample4.rb +0 -7
  152. data/samples/sample42.rb +0 -14
  153. data/samples/sample45.rb +0 -11
  154. data/samples/sample56.rb +0 -10
  155. data/samples/sample6.rb +0 -9
  156. data/samples/sample7.rb +0 -3
  157. data/samples/sample8.rb +0 -7
  158. data/samples/sample9.rb +0 -10
  159. data/samples/simple-accordion.rb +0 -75
  160. data/samples/simple-anim-shapes.rb +0 -17
  161. data/samples/simple-anim-text.rb +0 -13
  162. data/samples/simple-animate.rb +0 -12
  163. data/samples/simple-arc.rb +0 -23
  164. data/samples/simple-bounce.rb +0 -24
  165. data/samples/simple-brightness-transitions.rb +0 -8
  166. data/samples/simple-button-animate.rb +0 -16
  167. data/samples/simple-calc-2.rb +0 -34
  168. data/samples/simple-calc.rb +0 -70
  169. data/samples/simple-color-selector.rb +0 -10
  170. data/samples/simple-color-transitions.rb +0 -11
  171. data/samples/simple-control-sizes.rb +0 -24
  172. data/samples/simple-curve.rb +0 -26
  173. data/samples/simple-dialogs-outside.rb +0 -12
  174. data/samples/simple-dialogs.rb +0 -32
  175. data/samples/simple-displace.rb +0 -15
  176. data/samples/simple-downloader.rb +0 -27
  177. data/samples/simple-draw.rb +0 -13
  178. data/samples/simple-editor.rb +0 -28
  179. data/samples/simple-face.rb +0 -14
  180. data/samples/simple-flow-wrap.rb +0 -11
  181. data/samples/simple-font.rb +0 -17
  182. data/samples/simple-form.rb +0 -29
  183. data/samples/simple-form.shy +0 -0
  184. data/samples/simple-fullscreen.rb +0 -4
  185. data/samples/simple-guess-game.rb +0 -28
  186. data/samples/simple-keypress.rb +0 -14
  187. data/samples/simple-manual.rb +0 -2
  188. data/samples/simple-mask.rb +0 -21
  189. data/samples/simple-menu.rb +0 -47
  190. data/samples/simple-mouse-follow.rb +0 -8
  191. data/samples/simple-move.rb +0 -13
  192. data/samples/simple-oval.rb +0 -3
  193. data/samples/simple-sample-executor.rb +0 -6
  194. data/samples/simple-shoes-intro.rb +0 -22
  195. data/samples/simple-slide.rb +0 -56
  196. data/samples/simple-sound.rb +0 -30
  197. data/samples/simple-sphere.rb +0 -28
  198. data/samples/simple-stripes.rb +0 -8
  199. data/samples/simple-tictactoe.rb +0 -238
  200. data/samples/simple-timer.rb +0 -15
  201. data/samples/simple-video.rb +0 -13
  202. data/samples/simple-visibility.rb +0 -11
  203. data/samples/simple-widget.rb +0 -9
  204. data/samples/sounds/102719__sarge4267__explosion.mp3 +0 -0
  205. data/samples/sounds/145622__andybrannan__train-fog-horn-long-wyomming.aiff +0 -0
  206. data/samples/sounds/46492__phreaksaccount__shields1.ogg +0 -0
  207. data/samples/sounds/61847__simon-rue__boink-v3.wav +0 -0
  208. data/samples/swt-raw.rb +0 -20
  209. data/samples/troll.rb +0 -22
  210. data/shoes.gemspec +0 -29
  211. data/snapshots/sample1.png +0 -0
  212. data/snapshots/sample10.png +0 -0
  213. data/snapshots/sample11.png +0 -0
  214. data/snapshots/sample12.png +0 -0
  215. data/snapshots/sample13.png +0 -0
  216. data/snapshots/sample14.png +0 -0
  217. data/snapshots/sample15.png +0 -0
  218. data/snapshots/sample16.png +0 -0
  219. data/snapshots/sample17.png +0 -0
  220. data/snapshots/sample18.png +0 -0
  221. data/snapshots/sample19.png +0 -0
  222. data/snapshots/sample2.png +0 -0
  223. data/snapshots/sample20.png +0 -0
  224. data/snapshots/sample21.png +0 -0
  225. data/snapshots/sample22.png +0 -0
  226. data/snapshots/sample23.png +0 -0
  227. data/snapshots/sample24.png +0 -0
  228. data/snapshots/sample27.png +0 -0
  229. data/snapshots/sample28.png +0 -0
  230. data/snapshots/sample29.png +0 -0
  231. data/snapshots/sample3.png +0 -0
  232. data/snapshots/sample30.png +0 -0
  233. data/snapshots/sample31.png +0 -0
  234. data/snapshots/sample34.png +0 -0
  235. data/snapshots/sample35.png +0 -0
  236. data/snapshots/sample36.png +0 -0
  237. data/snapshots/sample37.png +0 -0
  238. data/snapshots/sample4.png +0 -0
  239. data/snapshots/sample42.png +0 -0
  240. data/snapshots/sample44.png +0 -0
  241. data/snapshots/sample45.png +0 -0
  242. data/snapshots/sample46.png +0 -0
  243. data/snapshots/sample5.png +0 -0
  244. data/snapshots/sample56.png +0 -0
  245. data/snapshots/sample6.png +0 -0
  246. data/snapshots/sample7.png +0 -0
  247. data/snapshots/sample8.png +0 -0
  248. data/snapshots/sample9.png +0 -0
  249. data/snapshots/sample99.png +0 -0
  250. data/static/PKGBUILD +0 -47
  251. data/static/Shoes.icns +0 -0
  252. data/static/avatar.png +0 -0
  253. data/static/code_highlighter.js +0 -188
  254. data/static/code_highlighter_ruby.js +0 -26
  255. data/static/downloading.png +0 -0
  256. data/static/icon-debug.png +0 -0
  257. data/static/icon-error.png +0 -0
  258. data/static/icon-info.png +0 -0
  259. data/static/icon-warn.png +0 -0
  260. data/static/listbox_button1.png +0 -0
  261. data/static/listbox_button2.png +0 -0
  262. data/static/man-app.png +0 -0
  263. data/static/man-builds.png +0 -0
  264. data/static/man-builds1.png +0 -0
  265. data/static/man-editor-notepad.png +0 -0
  266. data/static/man-editor-osx.png +0 -0
  267. data/static/man-ele-background.png +0 -0
  268. data/static/man-ele-border.png +0 -0
  269. data/static/man-ele-button.png +0 -0
  270. data/static/man-ele-check.png +0 -0
  271. data/static/man-ele-editbox.png +0 -0
  272. data/static/man-ele-editline.png +0 -0
  273. data/static/man-ele-image.png +0 -0
  274. data/static/man-ele-listbox.png +0 -0
  275. data/static/man-ele-progress.png +0 -0
  276. data/static/man-ele-radio.png +0 -0
  277. data/static/man-ele-shape.png +0 -0
  278. data/static/man-ele-textblock.png +0 -0
  279. data/static/man-ele-video.png +0 -0
  280. data/static/man-intro-dmg.png +0 -0
  281. data/static/man-intro-exe.png +0 -0
  282. data/static/man-look-tiger.png +0 -0
  283. data/static/man-look-ubuntu.png +0 -0
  284. data/static/man-look-vista.png +0 -0
  285. data/static/man-run-osx.png +0 -0
  286. data/static/man-run-vista.png +0 -0
  287. data/static/man-run-xp.png +0 -0
  288. data/static/man-shot1.png +0 -0
  289. data/static/manual-en.txt +0 -3531
  290. data/static/manual-ja.txt +0 -2829
  291. data/static/manual.css +0 -184
  292. data/static/menu-corner1.png +0 -0
  293. data/static/menu-corner2.png +0 -0
  294. data/static/menu-gray.png +0 -0
  295. data/static/menu-left.png +0 -0
  296. data/static/menu-right.png +0 -0
  297. data/static/menu-top.png +0 -0
  298. data/static/shoes-dmg.jpg +0 -0
  299. data/static/shoes-icon-blue.png +0 -0
  300. data/static/shoes-icon-brown.png +0 -0
  301. data/static/shoes-icon.png +0 -0
  302. data/static/shoes-manual-apps.gif +0 -0
  303. data/static/shoes-manual-apps.png +0 -0
  304. data/static/shoes_main_window.png +0 -0
  305. data/static/stripe.png +0 -0
  306. data/static/tutor-back.png +0 -0
  307. data/tasks/changelog.rb +0 -92
  308. data/tasks/gem.rb +0 -38
  309. data/tasks/rspec.rb +0 -106
  310. data/tasks/sample.rb +0 -66
  311. data/tasks/yard.rb +0 -13
data/samples/clicky.rb DELETED
@@ -1,24 +0,0 @@
1
- Shoes.app do
2
- @elements = []
3
- @elements << arc(0, 0,
4
- 100, 100,
5
- 0,
6
- Shoes::TWO_PI - Shoes::HALF_PI)
7
- @elements << rect(100, 100, 100, 100)
8
- @elements << para("text", left: 200)
9
- @elements << para(link("link") { |*args| alert(args.inspect) })
10
- @elements << button("Ok")
11
- @elements << check
12
- @elements << image(File.expand_path("~/source/shoes4/static/shoes-icon.png"))
13
- @elements << stack(width: 100, height: 100) do
14
- background green
15
- para "text"
16
- end
17
-
18
-
19
- @elements.each do |e|
20
- e.style(:click => Proc.new do |*args|
21
- alert args.inspect
22
- end)
23
- end
24
- end
data/samples/cy.png DELETED
Binary file
@@ -1,23 +0,0 @@
1
- Shoes.app title: "Dictionary, powered by Definr", width: 370, height: 320 do
2
- stack do
3
- background red, height: 60
4
- flow margin: 20 do
5
- caption "Define: ", stroke: white
6
- @lookup = edit_line
7
- button "Go" do
8
- download "http://definr.com/definr/show/#{@lookup.text}" do |dl|
9
- doc = dl.response.body.gsub('&nbsp;', ' ').
10
- gsub(%r!(</a>|<br />|<a href.+?>)!, '').
11
- gsub(%r!\(http://.+?\)!, '').strip
12
- title, doc = doc.split(/\n+/, 2)
13
- @deft.replace title
14
- @defn.replace doc
15
- end
16
- end
17
- end
18
- stack margin: 20 do
19
- @deft = subtitle "", margin: 10
20
- @defn = para ""
21
- end
22
- end
23
- end
@@ -1,60 +0,0 @@
1
- # This example tries Nokogiri (used in Shoes 4), but falls back to
2
- # Hpricot for Shoes 3 compatibility
3
- begin
4
- require 'nokogiri'
5
- rescue Exception => e
6
- require 'hpricot'
7
- end
8
-
9
- class Comic
10
- attr_reader :rss, :title
11
-
12
- def initialize(body)
13
- @rss = defined?(Nokogiri) ? Nokogiri::XML(body) : Hpricot(body)
14
- @title = @rss.at("//channel/title").inner_text
15
- end
16
-
17
- def items
18
- @rss.search("//channel/item")
19
- end
20
-
21
- def latest_image
22
- @rss.search("//channel/item").first.inner_html.scan(/src="([^"]+\.\w+)"/).first
23
- end
24
- end
25
-
26
- Shoes.app width: 800, height: 600 do
27
- background "#555"
28
-
29
- @title = "Web Funnies"
30
- @feeds = [
31
- "http://xkcd.com/rss.xml",
32
- # No longer contains images
33
- #"http://feedproxy.google.com/DilbertDailyStrip?format=xml",
34
- "http://www.smbc-comics.com/rss.php",
35
- "http://www.daybydaycartoon.com/index.xml",
36
- "http://www.questionablecontent.net/QCRSS.xml",
37
- "http://indexed.blogspot.com/feeds/posts/default?alt=rss"
38
- ]
39
-
40
- stack margin: 10 do
41
- title strong(@title), align: "center", stroke: "#DFA", margin: 0
42
- para "(loaded from RSS feeds)", align: "center", stroke: "#DFA",
43
- margin: 0
44
-
45
- @feeds.each do |feed|
46
- download feed do |dl|
47
- stack width: "100%", margin: 10, border: 1 do
48
- # Fall back to Shoes 3 syntax if necessary
49
- body = dl.respond_to?(:read) ? dl.read : dl.response.body
50
- c = Comic.new body
51
- stack margin_right: gutter do
52
- background "#333", curve: 4
53
- caption c.title, stroke: "#CD9", margin: 4
54
- end
55
- image c.latest_image.first, margin: 8
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,249 +0,0 @@
1
- # Simple Game of Life with Shoes
2
- # by fuksito
3
- # vitaliy@yanchuk.me
4
-
5
-
6
- class Cell
7
- WIDTH = 15
8
- attr_accessor :live, :next_state, :y, :x, :neighbours, :live_neighbours, :app, :shoes_cell
9
-
10
- def initialize(y, x, app, world)
11
- @live = false
12
- @next_state = false
13
- @y = y
14
- @x = x
15
- @app = app
16
- @world = world
17
- @shoes_cell = @app.rect(left: WIDTH * y, top: WIDTH * x, width: WIDTH)
18
- @shoes_cell.click{ toggle_state }
19
- end
20
-
21
- def live?
22
- @live
23
- end
24
-
25
- def dead?
26
- !@live
27
- end
28
-
29
- def die!
30
- @next_state = false
31
- @world.changed_cells.push(self)
32
- end
33
-
34
- def alive!
35
- @next_state = true
36
- @world.changed_cells.push(self)
37
- end
38
-
39
- def toggle_state
40
- @next_state = !@live
41
- set_next_state
42
- draw
43
- end
44
-
45
- def set_next_state
46
- if @live = @next_state
47
- @world.live_cells.push(self)
48
- else
49
- cell_index = @world.live_cells.index(self)
50
- if cell_index
51
- @world.live_cells.delete_at(cell_index)
52
- end
53
- end
54
- end
55
-
56
- def draw
57
- fill = live? ? '#000000' : '#ffffff'
58
-
59
- # TODO: Stop needing to be so cautious once #651 resolves our perf woes
60
- if @shoes_cell.fill.hex != fill
61
- @shoes_cell.style(fill: fill)
62
- end
63
- end
64
-
65
- def iterate
66
- live_cells_count = @neighbours.count{|c| c.live? }
67
- if live?
68
- if live_cells_count < 2 || live_cells_count > 3
69
- die!
70
- end
71
- else
72
- if live_cells_count == 3
73
- alive!
74
- end
75
- end
76
- end
77
- end
78
-
79
- class World
80
- attr_accessor :board, :width, :height, :live_cells, :changed_cells
81
-
82
- def initialize(width, height, app)
83
- @board = []
84
- @width = width
85
- @height = height
86
- @app = app
87
- @live_cells = []
88
- @changed_cells = []
89
- create_board
90
- end
91
-
92
- def create_board
93
- @height.times do |y|
94
- @board[y] = []
95
- @width.times do |x|
96
- @board[y][x] = Cell.new(y, x, @app, self)
97
- end
98
- end
99
- cells.each do |cell|
100
- cell.neighbours = cell_neighbours(cell.y, cell.x)
101
- end
102
- draw
103
- end
104
-
105
- def cells
106
- @cells ||= @board.flatten
107
- end
108
-
109
- def actual_cells
110
- (@live_cells.map(&:neighbours).flatten + @live_cells).uniq
111
- end
112
-
113
- def draw
114
- cells.each{|c| c.draw }
115
- end
116
-
117
- def tick
118
- @changed_cells = []
119
- actual_cells.each{|c| c.iterate }.each{|c| c.set_next_state }
120
- @changed_cells.each{|c| c.draw }
121
- end
122
-
123
- def clear
124
- live_cells.each do |cell|
125
- cell.live = false
126
- cell.next_state = false
127
- cell.draw
128
- end
129
- end
130
-
131
- def cell_neighbours(y,x)
132
- result = []
133
- top_row = y - 1
134
- left_col = x - 1
135
- right_col = x + 1
136
- bottom_row = y + 1
137
-
138
- if top_row >= 0 && left_col >= 0
139
- result << @board[y-1][x-1]
140
- end
141
-
142
- if top_row >= 0
143
- result << @board[y-1][x]
144
- end
145
-
146
- if top_row >= 0 && right_col < @width
147
- result << @board[y-1][x+1]
148
- end
149
-
150
- if left_col >= 0
151
- result << @board[y][x-1]
152
- end
153
-
154
- if right_col < @width
155
- result << @board[y][x+1]
156
- end
157
-
158
- if bottom_row < @height && left_col >= 0
159
- result << @board[y+1][x-1]
160
- end
161
-
162
- if bottom_row < @height
163
- result << @board[y+1][x]
164
- end
165
-
166
- if bottom_row < @height && right_col < @width
167
- result << @board[y+1][x+1]
168
- end
169
-
170
- result.compact
171
- end
172
-
173
- def add_specie(*cells)
174
- cells.each do |y,x|
175
- @board[y][x].toggle_state
176
- end
177
- end
178
-
179
- def add_glinder
180
- add_specie [4,2], [4,3], [4,4], [3,4], [2,3]
181
- end
182
-
183
- def add_spaceship
184
- add_specie [12,3], [12,6], [13,7], [14,3], [14,7], [15,4], [15,5], [15,6], [15,7]
185
- end
186
-
187
- def add_diehard
188
- add_specie [18,12], [12,13], [13,13], [13,14], [17,14], [18,14], [19,14]
189
- end
190
- end
191
-
192
- Shoes.app(title: "The Game of Life", width: 800, height: 620, resizable: false) do
193
- background white
194
- @animate = false
195
- stack(margin: 10) do |board_holder|
196
- @new_world = World.new(40, 40, self)
197
- animate(10) do |frame|
198
- if @animate
199
- @new_world.tick
200
- end
201
- end
202
- end
203
-
204
- def play
205
- @animate = true
206
- @run_button.hide
207
- @stop_button.show
208
- end
209
-
210
- def stop
211
- @animate = false
212
- @stop_button.hide
213
- @run_button.show
214
- end
215
-
216
- def clear
217
- stop
218
- @new_world.clear
219
- end
220
-
221
- stack(displace_left: 650) do
222
- @run_button = button('Run', width: 100){ play }
223
- @stop_button = button('Stop', width: 100){ stop }
224
- @stop_button.hide
225
- end
226
-
227
- stack(displace_left: 650) do
228
- button('Clear', width: 100) do
229
- clear
230
- end
231
-
232
- para "Species"
233
- button('Glinder', width: 100) do
234
- clear
235
- @new_world.add_glinder
236
- end
237
-
238
- button('Spaceship', width: 100) do
239
- clear
240
- @new_world.add_spaceship
241
- end
242
-
243
- button('Diehard', width: 100) do
244
- clear
245
- @new_world.add_diehard
246
- end
247
- end
248
-
249
- end
@@ -1,243 +0,0 @@
1
- # Simple Game of Life with Shoes
2
- # by fuksito
3
- # vitaliy@yanchuk.me
4
-
5
-
6
- class Cell
7
- WIDTH = 15
8
- attr_accessor :live, :next_state, :y, :x, :neighbours, :live_neighbours, :app, :shoes_cell
9
-
10
- def initialize(y, x, app, world)
11
- @live = false
12
- @next_state = false
13
- @y = y
14
- @x = x
15
- @app = app
16
- @world = world
17
- @shoes_cell = @app.rect(left: WIDTH * y, top: WIDTH * x, width: WIDTH)
18
- @shoes_cell.click{ toggle_state }
19
- end
20
-
21
- def live?
22
- @live
23
- end
24
-
25
- def dead?
26
- !@live
27
- end
28
-
29
- def die!
30
- @next_state = false
31
- @world.changed_cells.push(self)
32
- end
33
-
34
- def alive!
35
- @next_state = true
36
- @world.changed_cells.push(self)
37
- end
38
-
39
- def toggle_state
40
- @next_state = !@live
41
- set_next_state
42
- draw
43
- end
44
-
45
- def set_next_state
46
- if @live = @next_state
47
- @world.live_cells.push(self)
48
- else
49
- cell_index = @world.live_cells.index(self)
50
- if cell_index
51
- @world.live_cells.delete_at(cell_index)
52
- end
53
- end
54
- end
55
-
56
- def draw
57
- @shoes_cell.style(fill: live? ? '#000' : '#fff')
58
- end
59
-
60
- def iterate
61
- live_cells_count = @neighbours.count{|c| c.live? }
62
- if live?
63
- if live_cells_count < 2 || live_cells_count > 3
64
- die!
65
- end
66
- else
67
- if live_cells_count == 3
68
- alive!
69
- end
70
- end
71
- end
72
- end
73
-
74
- class World
75
- attr_accessor :board, :width, :height, :live_cells, :changed_cells
76
-
77
- def initialize(width, height, app)
78
- @board = []
79
- @width = width
80
- @height = height
81
- @app = app
82
- @live_cells = []
83
- @changed_cells = []
84
- create_board
85
- end
86
-
87
- def create_board
88
- @height.times do |y|
89
- @board[y] = []
90
- @width.times do |x|
91
- @board[y][x] = Cell.new(y, x, @app, self)
92
- end
93
- end
94
- cells.each do |cell|
95
- cell.neighbours = cell_neighbours(cell.y, cell.x)
96
- end
97
- draw
98
- end
99
-
100
- def cells
101
- @cells ||= @board.flatten
102
- end
103
-
104
- def actual_cells
105
- (@live_cells.map(&:neighbours).flatten + @live_cells).uniq
106
- end
107
-
108
- def draw
109
- cells.each{|c| c.draw }
110
- end
111
-
112
- def tick
113
- @changed_cells = []
114
- actual_cells.each{|c| c.iterate }.each{|c| c.set_next_state }
115
- @changed_cells.each{|c| c.draw }
116
- end
117
-
118
- def clear
119
- live_cells.each do |cell|
120
- cell.live = false
121
- cell.next_state = false
122
- cell.draw
123
- end
124
- end
125
-
126
- def cell_neighbours(y,x)
127
- result = []
128
- top_row = y - 1
129
- left_col = x - 1
130
- right_col = x + 1
131
- bottom_row = y + 1
132
-
133
- if top_row >= 0 && left_col >= 0
134
- result << @board[y-1][x-1]
135
- end
136
-
137
- if top_row >= 0
138
- result << @board[y-1][x]
139
- end
140
-
141
- if top_row >= 0 && right_col < @width
142
- result << @board[y-1][x+1]
143
- end
144
-
145
- if left_col >= 0
146
- result << @board[y][x-1]
147
- end
148
-
149
- if right_col < @width
150
- result << @board[y][x+1]
151
- end
152
-
153
- if bottom_row < @height && left_col >= 0
154
- result << @board[y+1][x-1]
155
- end
156
-
157
- if bottom_row < @height
158
- result << @board[y+1][x]
159
- end
160
-
161
- if bottom_row < @height && right_col < @width
162
- result << @board[y+1][x+1]
163
- end
164
-
165
- result.compact
166
- end
167
-
168
- def add_specie(*cells)
169
- cells.each do |y,x|
170
- @board[y][x].toggle_state
171
- end
172
- end
173
-
174
- def add_glinder
175
- add_specie [4,2], [4,3], [4,4], [3,4], [2,3]
176
- end
177
-
178
- def add_spaceship
179
- add_specie [12,3], [12,6], [13,7], [14,3], [14,7], [15,4], [15,5], [15,6], [15,7]
180
- end
181
-
182
- def add_diehard
183
- add_specie [18,12], [12,13], [13,13], [13,14], [17,14], [18,14], [19,14]
184
- end
185
- end
186
-
187
- Shoes.app(title: "The Game of Life", width: 800, height: 620, resizable: false) do
188
- background white
189
- @animate = false
190
- stack(margin: 10) do |board_holder|
191
- @new_world = World.new(40, 40, self)
192
- animate(10) do |frame|
193
- if @animate
194
- @new_world.tick
195
- end
196
- end
197
- end
198
-
199
- def play
200
- @animate = true
201
- @run_button.style(displace_top: -100)
202
- @stop_button.style(displace_top: 0)
203
- end
204
-
205
- def stop
206
- @animate = false
207
- @stop_button.style(displace_top: -100)
208
- @run_button.style(displace_top: 0)
209
- end
210
-
211
- def clear
212
- stop
213
- @new_world.clear
214
- end
215
-
216
- flow(displace_left: 650) do
217
- @run_button = button('Run', displace_top: 0, width: 100){ play }
218
- @stop_button = button('Stop', displace_top: -100, displace_left: -100, width: 100){ stop }
219
- end
220
-
221
- stack(displace_left: 650) do
222
- button('Clear', width: 100) do
223
- clear
224
- end
225
-
226
- para "Species"
227
- button('Glinder', width: 100) do
228
- clear
229
- @new_world.add_glinder
230
- end
231
-
232
- button('Spaceship', width: 100) do
233
- clear
234
- @new_world.add_spaceship
235
- end
236
-
237
- button('Diehard', width: 100) do
238
- clear
239
- @new_world.add_diehard
240
- end
241
- end
242
-
243
- end