~ecs/scrapple

c9ead4931f6951d40a8a393c6ffd50d4fd8b29ab — Ember Sawady 4 months ago 2ca6453 master
Add variable monitor output as well

Only tested at a resolution of 10, can't be bothered to make the
distance between pixels configurable and it wouldn't really work at
higher resolutions anyways.
2 files changed, 81 insertions(+), 6 deletions(-)

M README.md
M mkjson
M README.md => README.md +17 -1
@@ 5,19 5,28 @@

**Abandon all hope, ye who enter here.**

https://p.d2evs.net/3417454307.webm

## How?

In Scratch, blocks are highlighted while they're run. Naturally, the only
reasonable thing to do is to use that highlighting as a pixel in a display.
reasonable thing to do is to use that highlighting as a pixel in a display. In
addition, variables can be programmatically hidden and shown, which is basically
the same thing as them being pixels.

Each pixel is of the form:

```scratch
when I receive [$x,$y] {
    show variable [x,y]
    wait until [pixel x,y of the current frame] == 0
    hide variable [x,y]
}
```

With each variable [x,y] initially hidden and placed at (x * n, y * n) on the
canvas.

The driver is morally equivalent to:

```


@@ 47,3 56,10 @@ provide your own video) curl. `make` dumps an sb3 at `build/project.sb3`.
`make RES=...` to change the resolution, 10 is the default.  `make OFFSET=...`
to change the offset, 50 is the default. `make FPS=...` to change the FPS, 10 is
the default. After changing the resolution, you'll need to `make clean`.

## Performance

It's not great. I suggest using TurboWarp, enabling turbo mode, using the small
canvas, zooming out all the way, and shrinking your browser window as much as
possible. With all that and the default fps/resolution, I get ~3 dropped frames
on my T420 with nothing else running.

M mkjson => mkjson +64 -5
@@ 4,11 4,40 @@ offset=$2
xres="$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv build/badapple.mkv | cut -d',' -f2)"
yres="$(ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv build/badapple.mkv | cut -d',' -f3)"

print_pixelvar() {
	cat <<EOF
				"variable-$1,$2": ["$1,$2", " "],
EOF
}

print_pixelmonitor() {
	cat <<EOF
		{
			"id": "variable-$1,$2",
			"mode": "large",
			"opcode": "data_variable",
			"params": {
				"VARIABLE": "$1,$2"
			},
			"spriteName": null,
			"value": 0,
			"width": 0,
			"height": 0,
			"x": $(($1 * 33)),
			"y": $(($2 * 33)),
			"visible": false,
			"sliderMin": 0,
			"sliderMax": 0,
			"isDiscrete": true
		},
EOF
}

print_pixel() {
	cat <<EOF
				"receive-broadcast-$1,$2": {
					"opcode": "event_whenbroadcastreceived",
					"next": "wait-$1,$2",
					"next": "show-$1,$2",
					"parent": null,
					"inputs": {},
					"fields": {


@@ 22,10 51,24 @@ print_pixel() {
					"x": $(($1 * offset)),
					"y": $(($2 * offset * yres / xres))
				},
				"show-$1,$2": {
					"opcode": "data_showvariable",
					"next": "wait-$1,$2",
					"parent": "receive-broadcast-$1,$2*",
					"inputs": {},
					"fields": {
						"VARIABLE": [
							"$1,$2",
							"variable-$1,$2"
						]
					},
					"shadow": false,
					"topLevel": false
				},
				"wait-$1,$2": {
					"opcode": "control_wait_until",
					"next": null,
					"parent": "receive-broadcast-$1,$2",
					"next": "hide-$1,$2",
					"parent": "show-$1,$2",
					"inputs": {
						"CONDITION": [
							2,


@@ 117,6 160,20 @@ print_pixel() {
					"shadow": false,
					"topLevel": false
				},
				"hide-$1,$2": {
					"opcode": "data_hidevariable",
					"next": null,
					"parent": "wait-$1,$2",
					"inputs": {},
					"fields": {
						"VARIABLE": [
							"$1,$2",
							"variable-$1,$2"
						]
					},
					"shadow": false,
					"topLevel": false
				},
EOF
}



@@ 149,6 206,7 @@ cat <<EOF
			"isStage": true,
			"name": "Stage",
			"variables": {
$(for_pixel print_pixelvar)
				"variable-dropped": ["Frames dropped:", 0],
				"variable-f": ["f", 0],
				"variable-i": ["i", 0],


@@ 182,7 240,7 @@ $(cat decoder.json | sed "s/@FPS@/$3/")
					"x": 0,
					"y": $((height * offset * yres / xres - 15)),
					"width": $((width * offset + 650)),
					"height": 150,
					"height": 210,
					"minimized": false,
					"text": ""
				}


@@ 221,6 279,7 @@ $(cat decoder.json | sed "s/@FPS@/$3/")
		}
	],
	"monitors": [
$(for_pixel print_pixelmonitor)
		{
			"id": "variable-dropped",
			"mode": "default",


@@ 233,7 292,7 @@ $(cat decoder.json | sed "s/@FPS@/$3/")
			"width": 0,
			"height": 0,
			"x": 0,
			"y": 0,
			"y": 336,
			"visible": true,
			"sliderMin": 0,
			"sliderMax": 0,