Here’s my own Python Mode remix using a class
Hint for keeping hint()'s text() name & coords and its current state:
EDIT: update (v2.0)
- Click at canvas’ bottom -> toggles sphere()/box()
- Click mouseButton CENTER -> toggles noLoop()/loop()
- Click mouseButton RIGHT -> toggles rotateY()'s clockwise/counter-clockwise
"""
Hint 3D Settings (v2.0.3) [Python Mode Remix w/ Class]
by Hamoid (2018-Oct-11)
mod GoToLoop (2019-Nov-19)
Discourse.Processing.org/t/program-to-test-hint-with-transparency/4361/4
"""
W, H = 1200, 600
H3 = H/3
HINTS, OFFSET = 5, 20
BOX_SIZE, SPHERE_SIZE, ROT_STEP = 180, 90, 5e-3
BG, FG, TXT_COL = -1, 0x64FF2814, 0
FPS, MSG = 'FPS: %2.f - Frames: %.5d', '%d: %s'
PAUSED = 'Paused: %s - Frame: %d - Millis: %d'
CLOCKWISE, SPHERE_SHAPE = 'Clockwise:', '%d: Sphere: %s'
TIP = '<- use the mouse to toggle hint settings'
TIP_X, TIP_Y = 200, OFFSET * 3
SHAPE_TIP = 'click here to toggle shape'
SHAPE_X, SHAPE_Y = W >> 1, H - OFFSET
HINTS_RANGE = tuple(range(HINTS))
COORDS_RANGE = tuple(range(-H3, H3 + 1, H3))
TITLES = (
'DEPTH_TEST: ', 'DEPTH_SORT: ', 'DEPTH_MASK: ',
'OPTIMIZED_STROKE: ', 'STROKE_PERSPECTIVE: ' )
ONS = (
ENABLE_DEPTH_TEST, ENABLE_DEPTH_SORT, ENABLE_DEPTH_MASK,
ENABLE_OPTIMIZED_STROKE, ENABLE_STROKE_PERSPECTIVE )
OFFS = (
DISABLE_DEPTH_TEST, DISABLE_DEPTH_SORT, DISABLE_DEPTH_MASK,
DISABLE_OPTIMIZED_STROKE, DISABLE_STROKE_PERSPECTIVE )
useSphere, clockwise = False, 1
def setup():
size(W, H, P3D)
global hints
hints = tuple(
Hint(TITLES[i], ONS[i], OFFS[i], y = i*OFFSET + OFFSET)
for i in HINTS_RANGE )
for idx, h in enumerate(hints): print MSG % (idx, h)
print
def draw():
this.surface.title = FPS % (frameRate, frameCount)
background(BG)
fill(TXT_COL)
text(TIP, TIP_X, TIP_Y)
for h in hints: h.text()
with pushStyle():
textAlign(CENTER)
text(SHAPE_TIP, SHAPE_X, SHAPE_Y)
fill(FG)
translate(width >> 1, height >> 1)
rotateY(frameCount * clockwise * ROT_STEP)
for z in COORDS_RANGE:
for x in COORDS_RANGE:
with pushMatrix():
translate(x, 0, z)
sphere(SPHERE_SIZE) if useSphere else box(BOX_SIZE)
def mousePressed():
global useSphere, clockwise
isCenter = mouseButton == CENTER
this.looping ^= isCenter
if isCenter or not this.looping:
print PAUSED % (not this.looping, frameCount, millis())
return
if mouseButton == RIGHT:
clockwise *= -1
print CLOCKWISE, clockwise < 0
return
idx = mouseY // OFFSET
if 0 <= idx < HINTS:
h = hints[idx]
h.toggle()
h.hint()
print MSG % (idx, h)
elif mouseY >= SHAPE_Y - OFFSET:
useSphere ^= True
print SPHERE_SHAPE % (idx, useSphere)
else: print idx
class Hint:
def __init__(h, title, on, off, x=OFFSET, y=OFFSET, active=False):
h.title = title
h.on = on
h.off = off
h.x = x
h.y = y
h.active = active
h.hint()
def __str__(h, INFO='[ %s%s, x=%d, y=%d ]'):
return INFO % (h.title, h.active, h.x, h.y)
def toggle(h): h.active ^= True
def hint(h): hint(h.on if h.active else h.off)
def text(h): text(h.title + `h.active`, h.x, h.y)