Skip to content

Commit 22b37a0

Browse files
authored
Merge pull request #537 from hx2A/live-coding-more-stuff
Live coding - more bug fixes
2 parents 1274777 + 2fa8062 commit 22b37a0

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

py5_jar/src/main/java/py5/core/Sketch.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package py5.core;
2121

2222
import java.io.File;
23+
import java.util.Random;
2324

2425
import processing.core.PApplet;
2526
import processing.core.PConstants;
@@ -126,13 +127,25 @@ public void _resetSyncSketch() {
126127
if (savedStyle != null) {
127128
style(savedStyle);
128129
}
130+
131+
// reset window settings
129132
frameRate(60);
133+
cursor(ARROW);
134+
noClip();
135+
136+
// reset 3D settings
137+
if (g.is3D()) {
138+
camera();
139+
perspective();
140+
}
130141

131-
// reset shaders
142+
// reset shaders and other opengl only stuff
132143
if (g instanceof PGraphicsOpenGL) {
133144
resetShader(POINTS);
134145
resetShader(LINES);
135146
resetShader(TRIANGLES);
147+
textureMode(IMAGE);
148+
textureWrap(CLAMP);
136149
}
137150

138151
// reset hints
@@ -147,6 +160,20 @@ public void _resetSyncSketch() {
147160
hint(DISABLE_BUFFER_READING);
148161
hint(DISABLE_KEY_REPEAT);
149162
hint(ENABLE_ASYNC_SAVEFRAME);
163+
164+
// in case user doesn't call background in setup
165+
background(204);
166+
167+
// reset random methods
168+
osNoiseSeed = (long) (Math.random() * Long.MAX_VALUE);
169+
noiseSeed((long) (Math.random() * Long.MAX_VALUE));
170+
noiseDetail(4, 0.5f);
171+
172+
// reset detail settings
173+
sphereDetail(30);
174+
bezierDetail(20);
175+
curveDetail(20);
176+
curveTightness(0f);
150177
}
151178

152179
@Override

py5_resources/py5_module/py5/mixins/math.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class MathMixin:
4545
def __init__(self, *args, **kwargs):
4646
super().__init__(*args, **kwargs)
4747
self._instance = kwargs["instance"]
48+
self._init_math_mixin()
49+
50+
def _init_math_mixin(self):
4851
self._rng = np.random.default_rng()
4952

5053
# *** BEGIN METHODS ***

py5_resources/py5_module/py5_tools/live_coding/syncing.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import zipfile
2525
from pathlib import Path
2626

27+
import numpy as np
2728
import stackprinter
2829

2930
from .import_hook import activate_py5_live_coding_import_hook
@@ -360,10 +361,12 @@ def post_setup_hook(self, s):
360361
def pre_draw_hook(self, s):
361362
if self.run_setup_again:
362363
s._instance._resetSyncSketch()
364+
s._init_math_mixin()
365+
s.stop_all_threads(wait=False)
366+
363367
UserFunctionWrapper.looping_state = ANIMATION_LOOPING
364368
UserFunctionWrapper.freeze_frame_count = None
365-
# in case user doesn't call background in setup
366-
s.background(204)
369+
367370
self.functions["setup"]()
368371
self.run_setup_again = False
369372

0 commit comments

Comments
 (0)