diff --git a/py5_jar/src/main/java/py5/core/Sketch.java b/py5_jar/src/main/java/py5/core/Sketch.java index 6ebe0237..a21e96af 100644 --- a/py5_jar/src/main/java/py5/core/Sketch.java +++ b/py5_jar/src/main/java/py5/core/Sketch.java @@ -20,6 +20,7 @@ package py5.core; import java.io.File; +import java.util.Random; import processing.core.PApplet; import processing.core.PConstants; @@ -126,13 +127,25 @@ public void _resetSyncSketch() { if (savedStyle != null) { style(savedStyle); } + + // reset window settings frameRate(60); + cursor(ARROW); + noClip(); + + // reset 3D settings + if (g.is3D()) { + camera(); + perspective(); + } - // reset shaders + // reset shaders and other opengl only stuff if (g instanceof PGraphicsOpenGL) { resetShader(POINTS); resetShader(LINES); resetShader(TRIANGLES); + textureMode(IMAGE); + textureWrap(CLAMP); } // reset hints @@ -147,6 +160,20 @@ public void _resetSyncSketch() { hint(DISABLE_BUFFER_READING); hint(DISABLE_KEY_REPEAT); hint(ENABLE_ASYNC_SAVEFRAME); + + // in case user doesn't call background in setup + background(204); + + // reset random methods + osNoiseSeed = (long) (Math.random() * Long.MAX_VALUE); + noiseSeed((long) (Math.random() * Long.MAX_VALUE)); + noiseDetail(4, 0.5f); + + // reset detail settings + sphereDetail(30); + bezierDetail(20); + curveDetail(20); + curveTightness(0f); } @Override diff --git a/py5_resources/py5_module/py5/mixins/math.py b/py5_resources/py5_module/py5/mixins/math.py index 5aa91bee..7403e42f 100644 --- a/py5_resources/py5_module/py5/mixins/math.py +++ b/py5_resources/py5_module/py5/mixins/math.py @@ -45,6 +45,9 @@ class MathMixin: def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._instance = kwargs["instance"] + self._init_math_mixin() + + def _init_math_mixin(self): self._rng = np.random.default_rng() # *** BEGIN METHODS *** diff --git a/py5_resources/py5_module/py5_tools/live_coding/syncing.py b/py5_resources/py5_module/py5_tools/live_coding/syncing.py index 4ddcee51..55eb5a59 100644 --- a/py5_resources/py5_module/py5_tools/live_coding/syncing.py +++ b/py5_resources/py5_module/py5_tools/live_coding/syncing.py @@ -24,6 +24,7 @@ import zipfile from pathlib import Path +import numpy as np import stackprinter from .import_hook import activate_py5_live_coding_import_hook @@ -360,10 +361,12 @@ def post_setup_hook(self, s): def pre_draw_hook(self, s): if self.run_setup_again: s._instance._resetSyncSketch() + s._init_math_mixin() + s.stop_all_threads(wait=False) + UserFunctionWrapper.looping_state = ANIMATION_LOOPING UserFunctionWrapper.freeze_frame_count = None - # in case user doesn't call background in setup - s.background(204) + self.functions["setup"]() self.run_setup_again = False