the end of the end

At long last, I have something resembling a final project.

It's nothing like what I set out to make, however. After hours and hours of getting brightness tracking working for the light pen, trying to finagle both video tracking and serial buffer management in a single web application, and attempting to integrate that into my "veins" toy, I hit a brick wall. For whatever reason, I couldn't figure out how to make the jump from moving and resizing a cursor to also having that cursor disperse "veins" - the farthest I got was a moving and resizing cursor. See below.



So, I gave up. In the process of giving up, however, I saw something interesting in my webcam mirror - since the framerate of my webcam was embarrassingly slow, the LED would make light trails each frame when moved quickly enough. I was inspired.

I scrapped my current project, and instead began working on something entirely different. What I ended up with was pretty neat.

The first order of business was to create an interface that would "paint" light from the LED onto a digital canvas. I did this by grabbing every pixel that was bright enough, mapping their position from the captured video to the canvas, and re-drawing them. This created a sort of brushstroke-like effect.

Since the input was the light itself, I didn't need any sort of external modulation. With that in mind, I reworked my physical prop into something a little bit simpler. Instead of a pen, I just had the pen cap - with the FSR on one part of the exterior and the LED on another. The FSR is wired up to the LED, which is wired back to ground - so the Arduino itself is really only being used as a power source, but the harder I press the FSR, the brighter the LED. Sticking my pointer finger into the pen cap, and my thumb onto the FSR, I found more than a little satisfaction in the improved (and less cumbersome) interaction I had created. It felt natural to pinch and draw in the air, even if the responsiveness of the canvas was pretty terrible.

This was an interesting toy in and of itself, but it needed a few more features.
I added the following:
>Fullscreen toggle on F key
Self-explanatory. Press F, it goes fullscreen, press F again, it goes windowed.
>"Black" mode on B key
Pressing B causes the canvas to actually update itself each draw call, turning the entire canvas black before drawing the brushstroke. This creates an interesting effect not unlike the initial light-streak effect I noticed in the webcam in the first place, and has an animated quality to it that I like.
>Color-changing mode on C key
Pressing C will stop the LED from creating brushstrokes, and instead turn it into a color-picker. A small square in the top left serves as a reference. Lighting the LED and moving it around will actually cause the color picked to change. I did this by creating a cursor of sorts, then mapping it to hue and brightness values. The cursor is created by averaging the position of each "lit" pixel, whose x and y values are then mapped between 0 and 255 to determine the new picked color. When C is pressed again, the color is set, and new brushstrokes will be made in that color.



Full code here:
https://pastebin.com/uWyN9uj0

Comments

Popular posts from this blog

veins - a weird visual toy

Stupid Triangle Thing

Squeezy Circle