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,479 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
3
+ /*
4
+ Part of the Processing project - http://processing.org
5
+
6
+ Copyright (c) 2015 The Processing Foundation
7
+
8
+ This library is free software; you can redistribute it and/or
9
+ modify it under the terms of the GNU Lesser General Public
10
+ License as published by the Free Software Foundation, version 2.1.
11
+
12
+ This library is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ Lesser General Public License for more details.
16
+
17
+ You should have received a copy of the GNU Lesser General
18
+ Public License along with this library; if not, write to the
19
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
+ Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ package processing.core;
24
+
25
+
26
+ /**
27
+ * Surface that's not really visible. Used for PDF and friends, or as a base
28
+ * class for other drawing surfaces. It includes the standard rendering loop.
29
+ */
30
+ public class PSurfaceNone implements PSurface {
31
+
32
+ /**
33
+ *
34
+ */
35
+ protected PApplet sketch;
36
+
37
+ /**
38
+ *
39
+ */
40
+ protected PGraphics graphics;
41
+
42
+ /**
43
+ *
44
+ */
45
+ protected Thread thread;
46
+
47
+ /**
48
+ *
49
+ */
50
+ protected boolean paused;
51
+
52
+ /**
53
+ *
54
+ */
55
+ protected Object pauseObject = new Object();
56
+
57
+ /**
58
+ *
59
+ */
60
+ protected float frameRateTarget = 60;
61
+
62
+ /**
63
+ *
64
+ */
65
+ protected long frameRatePeriod = 1000000000L / 60L;
66
+
67
+ /**
68
+ *
69
+ * @param graphics
70
+ */
71
+ public PSurfaceNone(PGraphics graphics) {
72
+ this.graphics = graphics;
73
+ }
74
+
75
+ /**
76
+ *
77
+ * @param sketch
78
+ */
79
+ @Override
80
+ public void initOffscreen(PApplet sketch) {
81
+ this.sketch = sketch;
82
+
83
+ setSize(sketch.sketchWidth(), sketch.sketchHeight());
84
+ }
85
+
86
+
87
+ // public Component initComponent(PApplet sketch) {
88
+ // return null;
89
+ // }
90
+
91
+ /**
92
+ *
93
+ * @param sketch
94
+ */
95
+
96
+
97
+ @Override
98
+ public void initFrame(PApplet sketch) {/*, int backgroundColor,
99
+ int deviceIndex, boolean fullScreen,
100
+ boolean spanDisplays) {*/
101
+ //this.sketch = sketch;
102
+ throw new IllegalStateException("initFrame() not available with " +
103
+ getClass().getSimpleName());
104
+ }
105
+
106
+
107
+ public Object getNative() {
108
+ return null;
109
+ }
110
+
111
+
112
+ /** Set the window (and dock, or whatever necessary) title.
113
+ * @param title */
114
+ @Override
115
+ public void setTitle(String title) {
116
+ // You're in a utopian PSurface implementation where titles don't exist.
117
+ }
118
+
119
+ /**
120
+ *
121
+ * @param image
122
+ */
123
+ @Override
124
+ public void setIcon(PImage image) {
125
+ // I ain't visible, man.
126
+ }
127
+
128
+
129
+ /** Show or hide the window.
130
+ * @param visible */
131
+ @Override
132
+ public void setVisible(boolean visible) {
133
+ // I'm always invisible. You can't catch me.
134
+ }
135
+
136
+
137
+ /** Set true if we want to resize things (default is not resizable)
138
+ * @param resizable */
139
+ @Override
140
+ public void setResizable(boolean resizable) {
141
+ // I don't need size to know my worth.
142
+ }
143
+
144
+ /**
145
+ *
146
+ * @param location
147
+ * @param editorLocation
148
+ */
149
+ @Override
150
+ public void placeWindow(int[] location, int[] editorLocation) { }
151
+
152
+ /**
153
+ *
154
+ * @param stopColor
155
+ */
156
+ @Override
157
+ public void placePresent(int stopColor) { }
158
+
159
+ /**
160
+ *
161
+ */
162
+ @Override
163
+ public void setupExternalMessages() { }
164
+
165
+
166
+ @Override
167
+ public void setAlwaysOnTop(boolean always) { }
168
+
169
+
170
+ //
171
+
172
+ /**
173
+ *
174
+ * @param x
175
+ * @param y
176
+ */
177
+
178
+
179
+ @Override
180
+ public void setLocation(int x, int y) {
181
+ // I'm everywhere, because I'm nowhere.
182
+ }
183
+
184
+ /**
185
+ *
186
+ * @param wide
187
+ * @param high
188
+ */
189
+ @Override
190
+ public void setSize(int wide, int high) {
191
+ if (PApplet.DEBUG) {
192
+ //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
193
+ new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
194
+ }
195
+
196
+ //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
197
+ if (wide == sketch.width && high == sketch.height) {
198
+ if (PApplet.DEBUG) {
199
+ new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
200
+ }
201
+ return; // unchanged, don't rebuild everything
202
+ }
203
+
204
+ //throw new RuntimeException("implement me, see readme.md");
205
+ sketch.width = wide;
206
+ sketch.height = high;
207
+
208
+ // set PGraphics variables for width/height/pixelWidth/pixelHeight
209
+ graphics.setSize(wide, high);
210
+ }
211
+
212
+
213
+ // public void initImage(PGraphics graphics) {
214
+ // // TODO Auto-generated method stub
215
+ //
216
+ // }
217
+
218
+ // public Component getComponent() {
219
+ // return null;
220
+ // }
221
+
222
+
223
+ // public void setSmooth(int level) {
224
+ // // TODO Auto-generated method stub
225
+ // }
226
+
227
+ // void requestFocus() {
228
+ // }
229
+
230
+ // public void blit() {
231
+ // // TODO Auto-generated method stub
232
+ // }
233
+
234
+ /**
235
+ *
236
+ * @param kind
237
+ */
238
+
239
+ public void setCursor(int kind) { }
240
+
241
+ /**
242
+ *
243
+ * @param image
244
+ * @param hotspotX
245
+ * @param hotspotY
246
+ */
247
+ public void setCursor(PImage image, int hotspotX, int hotspotY) { }
248
+
249
+ /**
250
+ *
251
+ */
252
+ public void showCursor() { }
253
+
254
+ /**
255
+ *
256
+ */
257
+ public void hideCursor() { }
258
+
259
+
260
+ //
261
+
262
+ /**
263
+ *
264
+ * @return
265
+ */
266
+
267
+
268
+ public Thread createThread() {
269
+ return new AnimationThread();
270
+ }
271
+
272
+
273
+ public void startThread() {
274
+ if (thread == null) {
275
+ thread = createThread();
276
+ thread.start();
277
+ } else {
278
+ throw new IllegalStateException("Thread already started in " +
279
+ getClass().getSimpleName());
280
+ }
281
+ }
282
+
283
+
284
+ public boolean stopThread() {
285
+ if (thread == null) {
286
+ return false;
287
+ }
288
+ thread = null;
289
+ return true;
290
+ }
291
+
292
+ /**
293
+ *
294
+ * @return
295
+ */
296
+ public boolean isStopped() {
297
+ return thread == null || !thread.isAlive();
298
+ }
299
+
300
+
301
+ // sets a flag to pause the thread when ready
302
+ public void pauseThread() {
303
+ PApplet.debug("PApplet.run() paused, calling object wait...");
304
+ paused = true;
305
+ }
306
+
307
+
308
+ // halts the animation thread if the pause flag is set
309
+
310
+ /**
311
+ *
312
+ */
313
+ protected void checkPause() {
314
+ if (paused) {
315
+ synchronized (pauseObject) {
316
+ try {
317
+ pauseObject.wait();
318
+ // PApplet.debug("out of wait");
319
+ } catch (InterruptedException e) {
320
+ // waiting for this interrupt on a start() (resume) call
321
+ }
322
+ }
323
+ }
324
+ // PApplet.debug("done with pause");
325
+ }
326
+
327
+ /**
328
+ *
329
+ */
330
+ public void resumeThread() {
331
+ paused = false;
332
+ synchronized (pauseObject) {
333
+ pauseObject.notifyAll(); // wake up the animation thread
334
+ }
335
+ }
336
+
337
+ /**
338
+ *
339
+ * @param fps
340
+ */
341
+ public void setFrameRate(float fps) {
342
+ frameRateTarget = fps;
343
+ frameRatePeriod = (long) (1000000000.0 / frameRateTarget);
344
+ //g.setFrameRate(fps);
345
+ }
346
+
347
+ /**
348
+ *
349
+ */
350
+ public class AnimationThread extends Thread {
351
+
352
+ /**
353
+ *
354
+ */
355
+ public AnimationThread() {
356
+ super("Animation Thread");
357
+ }
358
+
359
+ // broken out so it can be overridden by Danger et al
360
+
361
+ /**
362
+ *
363
+ */
364
+ public void callDraw() {
365
+ sketch.handleDraw();
366
+ }
367
+
368
+ /**
369
+ * Main method for the primary animation thread.
370
+ * <A HREF="http://java.sun.com/products/jfc/tsc/articles/painting/">Painting in AWT and Swing</A>
371
+ */
372
+ @Override
373
+ public void run() { // not good to make this synchronized, locks things up
374
+ long beforeTime = System.nanoTime();
375
+ long overSleepTime = 0L;
376
+
377
+ int noDelays = 0;
378
+ // Number of frames with a delay of 0 ms before the
379
+ // animation thread yields to other running threads.
380
+ final int NO_DELAYS_PER_YIELD = 15;
381
+
382
+ /*
383
+ // If size un-initialized, might be a Canvas. Call setSize() here since
384
+ // we now have a parent object that this Canvas can use as a peer.
385
+ if (graphics.image == null) {
386
+ // System.out.format("it's null, sketchW/H already set to %d %d%n", sketchWidth, sketchHeight);
387
+ try {
388
+ EventQueue.invokeAndWait(new Runnable() {
389
+ public void run() {
390
+ setSize(sketchWidth, sketchHeight);
391
+ }
392
+ });
393
+ } catch (InterruptedException ie) {
394
+ ie.printStackTrace();
395
+ } catch (InvocationTargetException ite) {
396
+ ite.printStackTrace();
397
+ }
398
+ // System.out.format(" but now, sketchW/H changed to %d %d%n", sketchWidth, sketchHeight);
399
+ }
400
+ */
401
+
402
+ // un-pause the sketch and get rolling
403
+ sketch.start();
404
+
405
+ while ((Thread.currentThread() == thread) && !sketch.finished) {
406
+ checkPause();
407
+
408
+ // Don't resize the renderer from the EDT (i.e. from a ComponentEvent),
409
+ // otherwise it may attempt a resize mid-render.
410
+ // Dimension currentSize = canvas.getSize();
411
+ // if (currentSize.width != sketchWidth || currentSize.height != sketchHeight) {
412
+ // System.err.format("need to resize from %s to %d, %d%n", currentSize, sketchWidth, sketchHeight);
413
+ // }
414
+
415
+ // render a single frame
416
+ // try {
417
+ // EventQueue.invokeAndWait(new Runnable() {
418
+ // public void run() {
419
+ // System.out.println("calling draw, finished = " + sketch.finished);
420
+ //System.out.println("calling draw, looping = " + sketch.looping + ", frameCount = " + sketch.frameCount);
421
+ callDraw();
422
+
423
+ // EventQueue.invokeLater(new Runnable() {
424
+ // public void run() {
425
+ // if (sketch.frameCount == 1) {
426
+ // requestFocus();
427
+ // }
428
+ // }
429
+ // });
430
+
431
+ // }
432
+ // });
433
+ // } catch (InterruptedException ie) {
434
+ // ie.printStackTrace();
435
+ // } catch (InvocationTargetException ite) {
436
+ // ite.getTargetException().printStackTrace();
437
+ // }
438
+
439
+ // wait for update & paint to happen before drawing next frame
440
+ // this is necessary since the drawing is sometimes in a
441
+ // separate thread, meaning that the next frame will start
442
+ // before the update/paint is completed
443
+
444
+ long afterTime = System.nanoTime();
445
+ long timeDiff = afterTime - beforeTime;
446
+ //System.out.println("time diff is " + timeDiff);
447
+ long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime;
448
+
449
+ if (sleepTime > 0) { // some time left in this cycle
450
+ try {
451
+ Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L));
452
+ noDelays = 0; // Got some sleep, not delaying anymore
453
+ } catch (InterruptedException ex) { }
454
+
455
+ overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
456
+
457
+ } else { // sleepTime <= 0; the frame took longer than the period
458
+ overSleepTime = 0L;
459
+ noDelays++;
460
+
461
+ if (noDelays > NO_DELAYS_PER_YIELD) {
462
+ Thread.yield(); // give another thread a chance to run
463
+ noDelays = 0;
464
+ }
465
+ }
466
+
467
+ beforeTime = System.nanoTime();
468
+ }
469
+
470
+ sketch.dispose(); // call to shutdown libs?
471
+
472
+ // If the user called the exit() function, the window should close,
473
+ // rather than the sketch just halting.
474
+ if (sketch.exitCalled) {
475
+ sketch.exitActual();
476
+ }
477
+ }
478
+ }
479
+ }