picrate 0.0.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +47 -0
  3. data/.mvn/extensions.xml +9 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  5. data/.travis.yml +10 -0
  6. data/CHANGELOG.md +4 -0
  7. data/LICENSE.md +165 -0
  8. data/README.md +51 -0
  9. data/Rakefile +59 -0
  10. data/bin/picrate +8 -0
  11. data/docs/.gitignore +6 -0
  12. data/docs/_config.yml +30 -0
  13. data/docs/_includes/footer.html +38 -0
  14. data/docs/_includes/head.html +16 -0
  15. data/docs/_includes/header.html +27 -0
  16. data/docs/_includes/icon-github.html +1 -0
  17. data/docs/_includes/icon-github.svg +1 -0
  18. data/docs/_includes/icon-twitter.html +1 -0
  19. data/docs/_includes/icon-twitter.svg +1 -0
  20. data/docs/_includes/navigation.html +24 -0
  21. data/docs/_layouts/default.html +20 -0
  22. data/docs/_layouts/page.html +14 -0
  23. data/docs/_layouts/post.html +15 -0
  24. data/docs/_posts/2018-05-06-getting_started.md +8 -0
  25. data/docs/_posts/2018-05-06-install_jruby.md +35 -0
  26. data/docs/_sass/_base.scss +206 -0
  27. data/docs/_sass/_layout.scss +242 -0
  28. data/docs/_sass/_syntax-highlighting.scss +71 -0
  29. data/docs/about.md +10 -0
  30. data/docs/css/main.scss +38 -0
  31. data/docs/favicon.ico +0 -0
  32. data/docs/feed.xml +30 -0
  33. data/docs/index.html +38 -0
  34. data/lib/picrate.rb +10 -0
  35. data/lib/picrate/app.rb +187 -0
  36. data/lib/picrate/creators/sketch_class.rb +57 -0
  37. data/lib/picrate/creators/sketch_factory.rb +12 -0
  38. data/lib/picrate/creators/sketch_writer.rb +21 -0
  39. data/lib/picrate/helper_methods.rb +214 -0
  40. data/lib/picrate/helpers/numeric.rb +9 -0
  41. data/lib/picrate/library.rb +69 -0
  42. data/lib/picrate/library_loader.rb +53 -0
  43. data/lib/picrate/native_folder.rb +35 -0
  44. data/lib/picrate/native_loader.rb +27 -0
  45. data/lib/picrate/runner.rb +81 -0
  46. data/lib/picrate/version.rb +4 -0
  47. data/library/boids/boids.rb +209 -0
  48. data/library/chooser/chooser.rb +19 -0
  49. data/library/control_panel/control_panel.rb +182 -0
  50. data/library/library_proxy/README.md +99 -0
  51. data/library/library_proxy/library_proxy.rb +14 -0
  52. data/library/slider/slider.rb +42 -0
  53. data/library/vector_utils/vector_utils.rb +69 -0
  54. data/library/video_event/video_event.rb +3 -0
  55. data/license.txt +508 -0
  56. data/picrate.gemspec +35 -0
  57. data/pom.rb +122 -0
  58. data/pom.xml +214 -0
  59. data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
  60. data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  61. data/src/main/java/monkstone/ColorUtil.java +115 -0
  62. data/src/main/java/monkstone/MathToolModule.java +236 -0
  63. data/src/main/java/monkstone/PicrateLibrary.java +47 -0
  64. data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
  65. data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
  66. data/src/main/java/monkstone/fastmath/package-info.java +6 -0
  67. data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
  68. data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
  69. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
  70. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
  71. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
  72. data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
  73. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
  74. data/src/main/java/monkstone/slider/Slider.java +67 -0
  75. data/src/main/java/monkstone/slider/SliderBar.java +277 -0
  76. data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
  77. data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
  78. data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
  79. data/src/main/java/monkstone/vecmath/JRender.java +56 -0
  80. data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
  81. data/src/main/java/monkstone/vecmath/package-info.java +20 -0
  82. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
  83. data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
  84. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
  85. data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
  86. data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
  87. data/src/main/java/monkstone/videoevent/package-info.java +20 -0
  88. data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
  89. data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
  90. data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
  91. data/src/main/java/processing/core/PApplet.java +17647 -0
  92. data/src/main/java/processing/core/PConstants.java +1033 -0
  93. data/src/main/java/processing/core/PFont.java +1250 -0
  94. data/src/main/java/processing/core/PGraphics.java +9614 -0
  95. data/src/main/java/processing/core/PImage.java +3608 -0
  96. data/src/main/java/processing/core/PMatrix.java +347 -0
  97. data/src/main/java/processing/core/PMatrix2D.java +694 -0
  98. data/src/main/java/processing/core/PMatrix3D.java +1153 -0
  99. data/src/main/java/processing/core/PShape.java +4332 -0
  100. data/src/main/java/processing/core/PShapeOBJ.java +544 -0
  101. data/src/main/java/processing/core/PShapeSVG.java +1987 -0
  102. data/src/main/java/processing/core/PStyle.java +208 -0
  103. data/src/main/java/processing/core/PSurface.java +242 -0
  104. data/src/main/java/processing/core/PSurfaceNone.java +479 -0
  105. data/src/main/java/processing/core/PVector.java +1140 -0
  106. data/src/main/java/processing/data/FloatDict.java +829 -0
  107. data/src/main/java/processing/data/FloatList.java +912 -0
  108. data/src/main/java/processing/data/IntDict.java +796 -0
  109. data/src/main/java/processing/data/IntList.java +913 -0
  110. data/src/main/java/processing/data/JSONArray.java +1260 -0
  111. data/src/main/java/processing/data/JSONObject.java +2282 -0
  112. data/src/main/java/processing/data/JSONTokener.java +435 -0
  113. data/src/main/java/processing/data/Sort.java +46 -0
  114. data/src/main/java/processing/data/StringDict.java +601 -0
  115. data/src/main/java/processing/data/StringList.java +775 -0
  116. data/src/main/java/processing/data/Table.java +4923 -0
  117. data/src/main/java/processing/data/TableRow.java +198 -0
  118. data/src/main/java/processing/data/XML.java +1149 -0
  119. data/src/main/java/processing/event/Event.java +108 -0
  120. data/src/main/java/processing/event/KeyEvent.java +70 -0
  121. data/src/main/java/processing/event/MouseEvent.java +149 -0
  122. data/src/main/java/processing/event/TouchEvent.java +57 -0
  123. data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
  124. data/src/main/java/processing/opengl/FontTexture.java +379 -0
  125. data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
  126. data/src/main/java/processing/opengl/LinePath.java +623 -0
  127. data/src/main/java/processing/opengl/LineStroker.java +685 -0
  128. data/src/main/java/processing/opengl/PGL.java +3366 -0
  129. data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
  130. data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
  131. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
  132. data/src/main/java/processing/opengl/PJOGL.java +1966 -0
  133. data/src/main/java/processing/opengl/PShader.java +1478 -0
  134. data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
  135. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
  136. data/src/main/java/processing/opengl/Texture.java +1670 -0
  137. data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
  138. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  139. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  140. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  141. data/src/main/java/processing/opengl/cursors/license.txt +27 -0
  142. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  143. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  144. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  145. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  146. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  147. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  148. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
  149. data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
  150. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  151. data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
  152. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  153. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  154. data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
  155. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  156. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
  158. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  159. data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
  160. data/src/main/resources/icon/icon-1024.png +0 -0
  161. data/src/main/resources/icon/icon-128.png +0 -0
  162. data/src/main/resources/icon/icon-16.png +0 -0
  163. data/src/main/resources/icon/icon-256.png +0 -0
  164. data/src/main/resources/icon/icon-32.png +0 -0
  165. data/src/main/resources/icon/icon-48.png +0 -0
  166. data/src/main/resources/icon/icon-512.png +0 -0
  167. data/src/main/resources/icon/icon-64.png +0 -0
  168. data/src/main/resources/license.txt +508 -0
  169. data/test/create_test.rb +68 -0
  170. data/test/deglut_spec_test.rb +24 -0
  171. data/test/helper_methods_test.rb +58 -0
  172. data/test/math_tool_test.rb +75 -0
  173. data/test/respond_to_test.rb +215 -0
  174. data/test/sketches/key_event.rb +37 -0
  175. data/test/sketches/library/my_library/my_library.rb +32 -0
  176. data/test/test_helper.rb +3 -0
  177. data/test/vecmath_spec_test.rb +522 -0
  178. data/vendors/Rakefile +127 -0
  179. metadata +289 -0
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Syntax highlighting styles
3
+ */
4
+ .highlight {
5
+ background: #fff;
6
+ @extend %vertical-rhythm;
7
+
8
+ .highlighter-rouge & {
9
+ background: #eef;
10
+ }
11
+
12
+ .c { color: #998; font-style: italic } // Comment
13
+ .err { color: #a61717; background-color: #e3d2d2 } // Error
14
+ .k { font-weight: bold } // Keyword
15
+ .o { font-weight: bold } // Operator
16
+ .cm { color: #998; font-style: italic } // Comment.Multiline
17
+ .cp { color: #999; font-weight: bold } // Comment.Preproc
18
+ .c1 { color: #998; font-style: italic } // Comment.Single
19
+ .cs { color: #999; font-weight: bold; font-style: italic } // Comment.Special
20
+ .gd { color: #000; background-color: #fdd } // Generic.Deleted
21
+ .gd .x { color: #000; background-color: #faa } // Generic.Deleted.Specific
22
+ .ge { font-style: italic } // Generic.Emph
23
+ .gr { color: #a00 } // Generic.Error
24
+ .gh { color: #999 } // Generic.Heading
25
+ .gi { color: #000; background-color: #dfd } // Generic.Inserted
26
+ .gi .x { color: #000; background-color: #afa } // Generic.Inserted.Specific
27
+ .go { color: #888 } // Generic.Output
28
+ .gp { color: #555 } // Generic.Prompt
29
+ .gs { font-weight: bold } // Generic.Strong
30
+ .gu { color: #aaa } // Generic.Subheading
31
+ .gt { color: #a00 } // Generic.Traceback
32
+ .kc { font-weight: bold } // Keyword.Constant
33
+ .kd { font-weight: bold } // Keyword.Declaration
34
+ .kp { font-weight: bold } // Keyword.Pseudo
35
+ .kr { font-weight: bold } // Keyword.Reserved
36
+ .kt { color: #458; font-weight: bold } // Keyword.Type
37
+ .m { color: #099 } // Literal.Number
38
+ .s { color: #d14 } // Literal.String
39
+ .na { color: #008080 } // Name.Attribute
40
+ .nb { color: #0086B3 } // Name.Builtin
41
+ .nc { color: #458; font-weight: bold } // Name.Class
42
+ .no { color: #008080 } // Name.Constant
43
+ .ni { color: #800080 } // Name.Entity
44
+ .ne { color: #900; font-weight: bold } // Name.Exception
45
+ .nf { color: #900; font-weight: bold } // Name.Function
46
+ .nn { color: #555 } // Name.Namespace
47
+ .nt { color: #000080 } // Name.Tag
48
+ .nv { color: #008080 } // Name.Variable
49
+ .ow { font-weight: bold } // Operator.Word
50
+ .w { color: #bbb } // Text.Whitespace
51
+ .mf { color: #099 } // Literal.Number.Float
52
+ .mh { color: #099 } // Literal.Number.Hex
53
+ .mi { color: #099 } // Literal.Number.Integer
54
+ .mo { color: #099 } // Literal.Number.Oct
55
+ .sb { color: #d14 } // Literal.String.Backtick
56
+ .sc { color: #d14 } // Literal.String.Char
57
+ .sd { color: #d14 } // Literal.String.Doc
58
+ .s2 { color: #d14 } // Literal.String.Double
59
+ .se { color: #d14 } // Literal.String.Escape
60
+ .sh { color: #d14 } // Literal.String.Heredoc
61
+ .si { color: #d14 } // Literal.String.Interpol
62
+ .sx { color: #d14 } // Literal.String.Other
63
+ .sr { color: #009926 } // Literal.String.Regex
64
+ .s1 { color: #d14 } // Literal.String.Single
65
+ .ss { color: #990073 } // Literal.String.Symbol
66
+ .bp { color: #999 } // Name.Builtin.Pseudo
67
+ .vc { color: #008080 } // Name.Variable.Class
68
+ .vg { color: #008080 } // Name.Variable.Global
69
+ .vi { color: #008080 } // Name.Variable.Instance
70
+ .il { color: #099 } // Literal.Number.Integer.Long
71
+ }
data/docs/about.md ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ layout: page
3
+ title: About
4
+ permalink: /about/
5
+ ---
6
+
7
+ PiCrate is an experimental ruby wrapper for processing for the raspberrypi (raspbian image), like the vanilla processing version this uses the 32 bit video drivers. I could be 64 bit drivers work, but is possible they don't play too well together (to use the 64 bit drivers uncomment them in Rakefile and gemspec and comment out the 32 bit drivers).
8
+
9
+ [jruby_art]: https://ruby-processing.github.io/index.html
10
+ [propane]:https://ruby-processing.github.io/propane/
@@ -0,0 +1,38 @@
1
+ ---
2
+ # Only the main Sass file needs front matter (the dashes are enough)
3
+ ---
4
+ @charset "utf-8";
5
+
6
+ // Our variables
7
+ $base-font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
8
+ $base-font-size: 16px;
9
+ $base-font-weight: 400;
10
+ $small-font-size: $base-font-size * 0.875;
11
+ $base-line-height: 1.5;
12
+
13
+ $spacing-unit: 30px;
14
+
15
+ $text-color: #111;
16
+ $background-color: #fdfdfd;
17
+ $brand-color: #2a7ae2;
18
+
19
+ $grey-color: #828282;
20
+ $grey-color-light: lighten($grey-color, 40%);
21
+ $grey-color-dark: darken($grey-color, 25%);
22
+
23
+ // Width of the content area
24
+ $content-width: 800px;
25
+
26
+ $on-palm: 600px;
27
+ $on-laptop: 800px;
28
+
29
+ // Minima also includes a mixin for defining media queries.
30
+ // Use media queries like this:
31
+ // @include media-query($on-palm) {
32
+ // .wrapper {
33
+ // padding-right: $spacing-unit / 2;
34
+ // padding-left: $spacing-unit / 2;
35
+ // }
36
+ // }
37
+
38
+ // Import partials from the `minima` theme.
data/docs/favicon.ico ADDED
Binary file
data/docs/feed.xml ADDED
@@ -0,0 +1,30 @@
1
+ ---
2
+ layout: null
3
+ ---
4
+ <?xml version="1.0" encoding="UTF-8"?>
5
+ <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
6
+ <channel>
7
+ <title>{{ site.title | xml_escape }}</title>
8
+ <description>{{ site.description | xml_escape }}</description>
9
+ <link>{{ site.github.url }}{{ site.baseurl }}/</link>
10
+ <atom:link href="{{ "/feed.xml" | prepend: site.baseurl | prepend: site.github.url }}" rel="self" type="application/rss+xml"/>
11
+ <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
12
+ <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
13
+ <generator>Jekyll v{{ jekyll.version }}</generator>
14
+ {% for post in site.posts limit:10 %}
15
+ <item>
16
+ <title>{{ post.title | xml_escape }}</title>
17
+ <description>{{ post.content | xml_escape }}</description>
18
+ <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
19
+ <link>{{ post.url | prepend: site.baseurl | prepend: site.github.url }}</link>
20
+ <guid isPermaLink="true">{{ post.url | prepend: site.baseurl | prepend: site.github.url }}</guid>
21
+ {% for tag in post.tags %}
22
+ <category>{{ tag | xml_escape }}</category>
23
+ {% endfor %}
24
+ {% for cat in post.categories %}
25
+ <category>{{ cat | xml_escape }}</category>
26
+ {% endfor %}
27
+ </item>
28
+ {% endfor %}
29
+ </channel>
30
+ </rss>
data/docs/index.html ADDED
@@ -0,0 +1,38 @@
1
+ ---
2
+ layout: default
3
+ ---
4
+ <section role="banner">
5
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
6
+ width="256px" height="256px" viewBox="10 10 200 200" style="enable-background:new 0 0 200 200;" xml:space="preserve" fill="#380E99">
7
+ <g>
8
+ <path d="M56.161,183.028l4.452-43.162l7.904,6.584L56,185.335L56.161,183.028z M70.823,152.055l19.61,39.046l-32.951,4.116
9
+ L70.823,152.055z M92.739,195.552v0.161V195.552l0.657-0.161v0.161l93.095,3.62l-126.703,0.496L92.739,195.552z M127.997,90.604
10
+ l-30.645,34.098l-27.186,17.137l-7.743-6.584l10.874-20.435l25.872-28.842l24.711-17.297l11.371,3.138L127.997,90.604z
11
+ M90.266,182.036l-18.122-36.082l25.375-16.144L90.266,182.036z M154.693,141.181l-61.129,48.271l8.24-59.306L154.693,141.181z
12
+ M158.152,144.479l38.06,51.569l-98.532-3.795L158.152,144.479z M130.638,94.546l22.734,43.015l-51.241-11.371L130.638,94.546z
13
+ M171.004,56.332l-34.111,11.035l-6.094-1.649L171.004,56.332z M132.945,90.604l7.576-19.281l42.183,6.758L132.945,90.604z
14
+ M134.922,94.546l53.875-14.494l-30.973,57.83L134.922,94.546z M194.234,76.257l-45.146-7.897l36.082-11.706L194.234,76.257z
15
+ M200,195.391l-39.213-53.218l33.943-63.609L200,195.391z"/>
16
+ </g>
17
+ </svg>
18
+ </section>
19
+
20
+ <div class="home">
21
+
22
+ <h1 class="page-heading">Articles</h1>
23
+ {% if page.description %}<meta name="description" content="{{ page.description }}">{% endif %}
24
+ <ul class="post-list">
25
+ {% for post in site.posts %}
26
+ <li>
27
+ <span class="post-meta">{{ post.date | date: "%b %-d, %Y" }}</span>
28
+
29
+ <h2>
30
+ <a class="post-link" href="{{ post.url | prepend: site.github.url }}">{{ post.title }}</a>
31
+ </h2>
32
+ </li>
33
+ {% endfor %}
34
+ </ul>
35
+
36
+ <p class="rss-subscribe">subscribe <a href="{{ "/feed.xml" | prepend: site.github.url }}">via RSS</a></p>
37
+
38
+ </div>
data/lib/picrate.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ require 'java'
3
+ unless defined? PICRATE_ROOT
4
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
5
+ PICRATE_ROOT = File.absolute_path(File.dirname(__dir__))
6
+ end
7
+ Dir["#{PICRATE_ROOT}/lib/*.jar"].each do |jar|
8
+ require jar
9
+ end
10
+ require_relative 'picrate/app'
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: false
2
+ require_relative 'helper_methods'
3
+ require_relative 'library_loader'
4
+
5
+ # A wrapper module for the processing App
6
+ module Processing
7
+ include_package 'processing.core' # imports the processing jar.
8
+ # Load vecmath, fastmath and mathtool modules
9
+ Java::Monkstone::PicrateLibrary.load(JRuby.runtime)
10
+ SKETCH_ROOT = File.absolute_path('.')
11
+
12
+ # A utility to facillitate rendering of Vec2D and Vec3D as vertex
13
+ module Render
14
+ java_import 'monkstone.vecmath.AppRender'
15
+ java_import 'monkstone.vecmath.ShapeRender'
16
+ end
17
+
18
+ # This class is the base class the user should inherit from when making
19
+ # their own sketch.
20
+ #
21
+ # i.e.
22
+ # require 'picrate'
23
+ #
24
+ # class MySketch < Processing::App
25
+ #
26
+ # def draw
27
+ # background rand(255)
28
+ # end
29
+ #
30
+ # end
31
+ #
32
+ # MySketch.new
33
+
34
+ # Watch the definition of these methods, to make sure
35
+ # that Processing is able to call them during events.
36
+ METHODS_TO_ALIAS ||= {
37
+ mouse_pressed: :mousePressed,
38
+ mouse_dragged: :mouseDragged,
39
+ mouse_clicked: :mouseClicked,
40
+ mouse_moved: :mouseMoved,
41
+ mouse_released: :mouseReleased,
42
+ key_pressed: :keyPressed,
43
+ key_released: :keyReleased,
44
+ key_typed: :keyTyped
45
+ }.freeze
46
+
47
+ class << self
48
+ attr_accessor :app
49
+ end
50
+
51
+ # All sketches extend this class
52
+ class App < PApplet
53
+ include Math, MathTool, HelperMethods, Render
54
+ # Alias some methods for familiarity for Shoes coders.
55
+ alias oval ellipse
56
+ alias stroke_width stroke_weight
57
+ alias rgb color
58
+ alias gray color
59
+ field_reader :surface
60
+
61
+ def sketch_class
62
+ self.class.sketch_class
63
+ end
64
+
65
+ # Keep track of what inherits from the Processing::App, because we're
66
+ # going to want to instantiate one.
67
+ def self.inherited(subclass)
68
+ super(subclass)
69
+ @sketch_class = subclass
70
+ end
71
+
72
+ # App should be instantiated with an optional list of options
73
+ # and array of arguments.
74
+ #
75
+ # App.new
76
+ #
77
+ class << self
78
+ # Handy getters and setters on the class go here:
79
+ attr_accessor :sketch_class, :library_loader, :title, :arguments, :options
80
+
81
+ def load_libraries(*args)
82
+ library_loader ||= LibraryLoader.new
83
+ library_loader.load_library(*args)
84
+ end
85
+ alias load_library load_libraries
86
+
87
+ def library_loaded?(library_name)
88
+ library_loader.library_loaded?(library_name)
89
+ end
90
+
91
+ def load_ruby_library(*args)
92
+ library_loader.load_ruby_library(*args)
93
+ end
94
+
95
+ def load_java_library(*args)
96
+ library_loader.load_java_library(*args)
97
+ end
98
+
99
+ # When certain special methods get added to the sketch, we need to let
100
+ # Processing call them by their expected Java names.
101
+ def method_added(method_name) #:nodoc:
102
+ return unless METHODS_TO_ALIAS.key?(method_name)
103
+ alias_method METHODS_TO_ALIAS[method_name], method_name
104
+ end
105
+ end
106
+
107
+ def library_loaded?(library_name)
108
+ self.class.library_loaded?(library_name)
109
+ end
110
+
111
+ def initialize(options = {}, arguments = [])
112
+ # Guard against invalid input.
113
+ proxy_java_fields
114
+ raise TypeError unless options.is_a?(Hash) && arguments.is_a?(Array)
115
+ # Set up the sketch.
116
+ super()
117
+ post_initialize(options)
118
+ Processing.app = self
119
+ @arguments = arguments
120
+ @options = options
121
+ run_picrate
122
+ end
123
+
124
+ def size(*args)
125
+ w, h, mode = *args
126
+ @width ||= w
127
+ @height ||= h
128
+ @render_mode ||= mode
129
+ import_opengl if /opengl/ =~ mode
130
+ super(*args)
131
+ end
132
+
133
+ def post_initialize(_args)
134
+ end
135
+
136
+ def sketch_title(title)
137
+ surface.set_title(title)
138
+ end
139
+
140
+ def data_path(dat)
141
+ dat_root = File.join(SKETCH_ROOT, 'data')
142
+ Dir.mkdir(dat_root) unless File.exist?(dat_root)
143
+ File.join(dat_root, dat)
144
+ end
145
+
146
+ private
147
+
148
+ def import_opengl
149
+ # Include processing opengl classes that we'd like to use:
150
+ %w[FontTexture FrameBuffer LinePath LineStroker PGL
151
+ PGraphics2D PGraphics3D PGraphicsOpenGL PShader
152
+ PShapeOpenGL Texture].each do |klass|
153
+ java_import "processing.opengl.#{klass}"
154
+ end
155
+ end
156
+
157
+ def proxy_java_fields
158
+ fields = %w[sketchPath key frameRate mousePressed keyPressed]
159
+ methods = fields.map { |field| java_class.declared_field(field) }
160
+ @declared_fields = Hash[fields.zip(methods)]
161
+ end
162
+
163
+ # When certain special methods get added to the sketch, we need to let
164
+ # Processing call them by their expected Java names.
165
+ def method_added(method_name) #:nodoc:
166
+ return unless METHODS_TO_ALIAS.key?(method_name)
167
+ alias_method METHODS_TO_ALIAS[method_name], method_name
168
+ end
169
+ end
170
+
171
+ # @HACK purists may prefer 'forwardable' to the use of Proxy
172
+ # Importing PConstants here to access the processing constants
173
+ module Proxy
174
+ include Math
175
+ include HelperMethods
176
+ include Java::ProcessingCore::PConstants
177
+
178
+ def respond_to_missing?(symbol, include_priv = false)
179
+ Processing.app.respond_to?(symbol, include_priv) || super
180
+ end
181
+
182
+ def method_missing(name, *args, &block)
183
+ return Processing.app.send(name, *args) if Processing.app.respond_to? name
184
+ super
185
+ end
186
+ end # Processing::Proxy
187
+ end # Processing
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: false
2
+
3
+ # the sketch class
4
+ class SketchClass
5
+ attr_reader :name, :width, :height, :mode
6
+
7
+ def initialize(name:, width: 150, height: 150, mode: nil)
8
+ @name, @width, @height, @mode = name, width, height, mode
9
+ end
10
+
11
+ def class_sketch
12
+ format('class %s < Processing::App', sketch_class)
13
+ end
14
+
15
+ def sketch_class
16
+ name.split('_').collect(&:capitalize).join
17
+ end
18
+
19
+ def sketch_new
20
+ format('%s.new', sketch_class)
21
+ end
22
+
23
+ def indent(line)
24
+ format(' %s', line)
25
+ end
26
+
27
+ def size
28
+ return format(' size %d, %d', width.to_i, height.to_i) unless mode
29
+ format(' size %d, %d, %s', width.to_i, height.to_i, mode.upcase)
30
+ end
31
+
32
+ def sketch_title
33
+ human = name.split('_').collect(&:capitalize).join(' ')
34
+ format(" sketch_title '%s'", human)
35
+ end
36
+
37
+ def method_lines(name, content = nil)
38
+ return [format(' def %s', name), '', ' end'] unless content
39
+ [format(' def %s', name), content, ' end', '']
40
+ end
41
+
42
+ def lines
43
+ lines = [
44
+ '#!/usr/bin/env jruby',
45
+ '# frozen_string_literal: false',
46
+ "require 'picrate'",
47
+ '',
48
+ class_sketch
49
+ ]
50
+ lines.concat method_lines('settings', size)
51
+ lines.concat method_lines('setup', sketch_title)
52
+ lines.concat method_lines('draw')
53
+ lines << 'end'
54
+ lines << ''
55
+ lines << sketch_new
56
+ end
57
+ end