Steve · 5 answers · 2mo

Tell me about something you're particularly proud of accomplishing.

https://github.com/inhahe/scribbles3

I used to draw doodles when I was younger where I'd draw a randomly curved line that crosses over itself and eventually meets itself to form a closed loop, and then I'd color in every other section. For many years I wanted to make a programmatic analogue of it, but I couldn't quite figure out how. Then I realized I could use Bezier curves, by making the end of one curve in-line with the beginning of the next curve. So how to make a loop? I actually just put a bunch of random dots on the screen and then connected them all in order with the first connecting to the last. But I still had a problem: how would the program know when a curve went over the same pixel more than once? If it didn't know that, it would color in that line incorrectly (it works line-by-line, stopping and going whenever it encounters part of a curve). Well, I solved that by inverting the value of a pixel every time a curve went over it. Then I would color the lines based on that virtual screen of on or off pixels. That meant I couldn't use a library for my Bezier curves, I had to implement it myself. But then I had the problem of curves traveling for several pixels horizontally at a time, I didn't want to invert the filling once per pixel in that case, so I just inverted it when it changed direction to up or down. But then I had another problem: It had to know when a curve traveled horizontally (the direction in which it fills stuff in line by line) and then curved back in the same direction it came from, because otherwise it would only invert it once when it should invert it twice/zero times. I solved that problem by having it remember when a curve came off a horizontal part in the same direction it went onto it vs in the other direction and inverting or not inverting a pixel accordingly. Then it was still incorrectly coloring the line on which the loop met back up with itself, which I solved but I don't remember how, it was related to the previous problem.

I also made it change over time, by plotting Bezier curves over which the points of the spatial Bezier curves themselves would move. It can even seamlessly loop (depending on what options you give it--there are a lot of options I added over time) by connecting the Bezier curves in the time dimension in a loop the same way the spatial ones are connected. In that case, the same class is used for both the time-based curves and the space-based curves. In the case where it doesn't loop, the 'get next point' function is part of a class that automatically adds a new curve every time the previous one is exhausted.

Fragsturztaube uses Markdown for formatting

*italic text* for italic text

**bold text** for bold text

[link](https://example.com) for link