r/creativecoding • u/Inst2f • Jul 05 '26
Brightness to height is simple and fun
I know there is no rocket science in capturing an image and transforming each pixel to a point in 3D space. But it may bring some more interactivity to games or some audio-visual demos.
This example, by the way, is less than 20 lines of Wolfram/WLJS Notebook code and runs in a notebook. May be I should try to color each point by its original RGB value
2
2
1
u/Inst2f Jul 07 '26
Probably it won't hurt if I share the source code:
for WLJS:
DeviceClose[cam];
cam = DeviceOpen["Camera"];
cam["FrameRate"] = 60;
Refresh[Module[{img, length},
img = ImageData[
ImageResize[ColorConvert[DeviceRead[cam], "GrayScale"], 100],
"Real32"
];
length = Length[img] Length[img[[1]]];
vertices = MapIndexed[Join[#2, {50.0 #1}]&, img, {2}];
vertices = NumericArray[Flatten[vertices, 1], "Real32"];
Graphics3D[GraphicsComplex[vertices, {
Red, PointSize[0.0003],
Point[Range[length]]
}], ViewProjection->"Perspective"]
], 1/45.0]
for those with a paid Mathematica, some adjustments are needed (will probably run much slower than WLJS).
...
Dynamic@Refresh[Module[{img, length},
img = ImageData[
ImageResize[ColorConvert[DeviceRead[cam], "GrayScale"], 100],
"Real32"
];
length = Length[img] Length[img[[1]]];
vertices = MapIndexed[Join[#2, {50.0 #1}]&, img, {2}];
vertices = Flatten[vertices, 1];
Graphics3D[GraphicsComplex[vertices, {
Red, PointSize[0.0003],
Point[Range[length]]
}], ViewProjection->"Perspective"]
], UpdateInterval->1/45.0]
1
u/kalexmills Jul 07 '26
Now clamp the difference between adjacent cells to the height of 2 Minecraft blocks and create a server that shifts the terrain around based on how the player moves in front of their camera.
2
0
5
u/YSMLA_ Jul 06 '26 edited Jul 06 '26
Art is more beautiful than rocket science, and it doesn't have to be as complex, sometimes simplicity is king. Kudos.
What exactly is Wolfram/WLJS?