Download tasks/t23-dance-blob/environment/make-synthetic-oracle.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.88 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t23-dance-blob/environment/make-synthetic-oracle.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t23-dance-blob/environment/make-synthetic-oracle.py
-
curl -L -o make-synthetic-oracle.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t23-dance-blob/environment/make-synthetic-oracle.py
4.88 kB
| #!/usr/bin/env python3 | |
| """Synthetic stand-in oracle for calibrating the t23 rubric (NOT a Friction | |
| render — an approved Friction run replaces it, see tests/reference/README.md). | |
| Draws, in pure Python (no PIL/numpy), the dancing-blob loop measured from the | |
| AE_Dance-Blob reference: a row of dome-shaped smiley blobs on white that | |
| squash with the bottom pinned, spring back while the row hops half a spacing | |
| to the right, and cycle their shared fill hue once per hop. Streams PPM frames | |
| to ffmpeg -> 800x800 30 fps H.264. | |
| tools/make-synthetic-oracle.py out.mp4 [--static] [--cut] [--mono] [--no-face] [--translate] | |
| --static no motion at all (a still frame) | |
| --cut squash / hop as jump cuts instead of eased motion | |
| --mono one fixed colour (no hue cycle) | |
| --no-face blobs without eyes / mouth | |
| --translate bounce by moving the whole blob up and down (no squash) | |
| """ | |
| import colorsys | |
| import math | |
| import subprocess | |
| import sys | |
| W, H, FPS, DUR = 800, 800, 30, 6.0 | |
| N = int(round(DUR * FPS)) | |
| out = sys.argv[1] | |
| STATIC = "--static" in sys.argv | |
| CUT = "--cut" in sys.argv | |
| MONO = "--mono" in sys.argv | |
| NOFACE = "--no-face" in sys.argv | |
| TRANSLATE = "--translate" in sys.argv | |
| BASE_Y, REST_H, BLOB_W, SPACING = 471, 157, 188, 200 | |
| HOP, SQUASH, STEP = 0.475, 0.69, 100.0 | |
| SQUASH_FRAC = 16 / 28.5 # part of the hop spent squashing (measured) | |
| SCALE = 2 # render at 400x400 then let ffmpeg upscale (pure-python speed) | |
| def ease(u): | |
| u = max(0.0, min(1.0, u)) | |
| if CUT: | |
| return 1.0 if u >= 0.5 else 0.0 | |
| return 0.5 - 0.5 * math.cos(math.pi * u) | |
| def state(t): | |
| """height factor, row x-offset (px), hue (0-1) at time t.""" | |
| if STATIC: | |
| return 1.0, 0.0, 350 / 360.0 | |
| hop = int(t // HOP) | |
| u = (t - hop * HOP) / HOP | |
| if u < SQUASH_FRAC: | |
| hf = 1.0 - (1.0 - SQUASH) * ease(u / SQUASH_FRAC) | |
| dx = 0.0 | |
| else: | |
| v = (u - SQUASH_FRAC) / (1.0 - SQUASH_FRAC) | |
| hf = SQUASH + (1.0 - SQUASH) * ease(v) | |
| dx = STEP * ease(v) | |
| hue = 350 / 360.0 if MONO else ((350 + 360.0 * u) % 360) / 360.0 | |
| return hf, hop * STEP + dx, hue | |
| def frame(t): | |
| w, h = W // SCALE, H // SCALE | |
| px = bytearray(b"\xff\xff\xff" * (w * h)) | |
| hf, off, hue = state(t) | |
| r, g, b = colorsys.hsv_to_rgb(hue, 0.55, 1.0) | |
| col = (int(r * 255), int(g * 255), int(b * 255)) | |
| bh = REST_H * hf if not TRANSLATE else REST_H | |
| lift = (REST_H - REST_H * hf) if TRANSLATE else 0.0 | |
| base = BASE_Y - lift | |
| top = base - bh | |
| # blob centres: the row extends past both edges; wrap the offset on the spacing | |
| o = off % SPACING | |
| centres = [(-2 * SPACING + o + BLOB_W / 2 + 6) + i * SPACING for i in range(8)] | |
| for cx in centres: | |
| for yy in range(int(top), int(base) + 1): | |
| # dome: full width at the bottom 35 %, elliptical shoulder above | |
| f = (base - yy) / bh | |
| if f > 0.35: | |
| q = (f - 0.35) / 0.65 | |
| half = (BLOB_W / 2) * math.sqrt(max(0.0, 1 - q * q)) | |
| else: | |
| half = BLOB_W / 2 * (0.93 + 0.07 * (f / 0.35)) | |
| x0, x1 = int(cx - half), int(cx + half) | |
| ys = yy // SCALE | |
| if 0 <= ys < h: | |
| for xx in range(max(0, x0 // SCALE), min(w - 1, x1 // SCALE) + 1): | |
| i = 3 * (ys * w + xx) | |
| px[i], px[i + 1], px[i + 2] = col | |
| if not NOFACE: | |
| # eyes + smile in the lower half of the blob, dark | |
| ey = base - bh * 0.62 | |
| for ex in (cx - 24, cx + 24): | |
| for yy in range(int(ey - 9), int(ey + 9)): | |
| for xx in range(int(ex - 7), int(ex + 7)): | |
| if ((xx - ex) / 7.0) ** 2 + ((yy - ey) / 9.0) ** 2 <= 1: | |
| xs, ys = xx // SCALE, yy // SCALE | |
| if 0 <= xs < w and 0 <= ys < h: | |
| i = 3 * (ys * w + xs); px[i] = px[i + 1] = px[i + 2] = 40 | |
| my = base - bh * 0.42 | |
| for xx in range(int(cx - 26), int(cx + 26)): | |
| yy = my + 10 * (1 - ((xx - cx) / 26.0) ** 2) | |
| for dy in range(-3, 3): | |
| xs, ys = xx // SCALE, int(yy + dy) // SCALE | |
| if 0 <= xs < w and 0 <= ys < h: | |
| i = 3 * (ys * w + xs); px[i] = px[i + 1] = px[i + 2] = 40 | |
| return b"P6 %d %d 255\n" % (w, h) + bytes(px) | |
| ff = subprocess.Popen(["ffmpeg", "-nostdin", "-v", "error", "-y", "-f", "image2pipe", "-vcodec", "ppm", | |
| "-framerate", str(FPS), "-i", "-", "-vf", "scale=%d:%d:flags=neighbor,format=yuv420p" % (W, H), | |
| "-c:v", "libx264", "-preset", "veryfast", "-crf", "18", "-movflags", "+faststart", out], | |
| stdin=subprocess.PIPE) | |
| for n in range(N): | |
| ff.stdin.write(frame(n / FPS)) | |
| ff.stdin.close() | |
| sys.exit(ff.wait()) | |