You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
import numpy as _np
|
|
import math as _m
|
|
|
|
_FLOAT=0; _GATHER=1; _LINES=2; _LFADE=3; _EXPAND=4; _ELLIPSE=5
|
|
|
|
def onSetupParameters(scriptOp): pass
|
|
|
|
def onCook(scriptOp):
|
|
try:
|
|
_do_render(scriptOp)
|
|
except Exception as e:
|
|
import traceback; traceback.print_exc()
|
|
|
|
def _do_render(scriptOp):
|
|
from PIL import Image, ImageDraw
|
|
import sys
|
|
#PIL_PATH = r'C:\Users\user\AppData\Roaming\Python\Python311\site-packages'
|
|
PIL_PATH=r'C:\Users\tech\AppData\Local\Programs\Python\Python311\site-packages'
|
|
|
|
if PIL_PATH not in sys.path:
|
|
sys.path.insert(0, PIL_PATH)
|
|
|
|
root = op('/project1/deep_sound')
|
|
W = int(root.par.Resw.val); H = int(root.par.Resh.val)
|
|
|
|
st = root.fetch('state_dict', None) or {}
|
|
ast = int(round(st.get('appState', _FLOAT)))
|
|
cd = root.fetch('circle_dots', [])
|
|
segs = root.fetch('line_segs', [])
|
|
|
|
img = Image.new('RGBA', (W, H), (0, 0, 0, 0))
|
|
|
|
if ast in (_LINES, _LFADE) and segs and cd:
|
|
draw = ImageDraw.Draw(img)
|
|
for seg in segs:
|
|
fi = seg.get('from_idx', 0); ti = seg.get('to_idx', 0)
|
|
prog = float(seg.get('progress', 0.))
|
|
if prog <= 0 or fi >= len(cd) or ti >= len(cd): continue
|
|
x0 = cd[fi]['x']; y0 = cd[fi]['y']
|
|
x1 = cd[ti]['x']; y1 = cd[ti]['y']
|
|
# Interpolate endpoint by progress
|
|
ex = x0 + (x1 - x0) * prog
|
|
ey = y0 + (y1 - y0) * prog
|
|
draw.line([(x0, y0), (ex, ey)], fill=(255, 255, 255, 255), width=2)
|
|
|
|
arr = _np.ascontiguousarray(_np.flipud(_np.array(img, dtype=_np.float32) / 255.))
|
|
scriptOp.copyNumpyArray(arr)
|
|
|