March 21, 2016
Evolution of a small random walker

Hi everyone! Long time no post :) Recently, I’ve started going through my copy of Nature of Code again, and working through, well, not everything, but some bits. One of the first things the book talks about is random walkers and random walkers controlled by probabilities. So, I dove into p5.js, trying to relearn javascript while doing something hopefully interesting.

(the structure of this post: I will write up stuff, link to a bl.ocks javascript animation and post screenshots. There is a github link at the end of the post where all the code will live. All the js links are completely randomized and might require a few refreshes to get pleasing color combinations)

So, what about a line-based random walker - something with a grid-like background maybe, with lines of fixed width, that will always create squares if it loops in on itself. My first attempt went well, but I made one crucial mistake in calculating the lengths of diagonals. Still, the results were pretty cool:

random walker with errors in calculations/click for animation

Screenshots:

imageimage

Well, at least that error was easily found and fixed. Despite really liking the results, I went ahead towards what I was actually aiming to make. The “grid based” random walker ended up being interesting but… not enough:

“grid-based” random walker

Screenshots:

image

Maybe making multiple walkers and giving them highly-saturated, mostly-transparent colors will make for an interesting result? As it turns out, yes, yes it will. The end result of this was something that reminded me of city metro line maps and Mini-Metro.

Metro lines

Screenshots:

image

Aaaaand… I thought I was done. I was done, right? Start with a simple idea, pursue it a bit and whee pretty results. I had something that was nice to look at, produced pretty images, and seemed… done. At least, I thought so. marienna, however, disagreed.

- “Why can’t you make the area fill up, as the lines start forming triangles?” - “well, um, it’s not what I had in mind when I started this” - “You’re wrong. You should make it with triangles that fill with color”

I did not really intend to go back to it, but she was right, there was more to do with this - the grid was inelegant and required stupid, unnecessary calculations, and if I switched to actually having a proper grid that stored colors of lines that passed through, it would make filling the area much easier.

So, what was wrong with the previous versions? If you look at the first example, the problem is obvious there - instead of actually having a proper grid, I only had line lengths and was “randomly” (ish) selecting angles, using polar transformations to calculate where the next line segment will end.

To make this better, I instead opted to have a grid, an actual 2-dimensional array that stored colors for each grid point. Calculating the new endpoint of the line segment is then as simple as rounding the cos() and sin() of the selected angle, which gives an integer in the [-1, 1] range, then adding those to the current grid position, only multiplying by the side of the grid square after that.

This… might have gotten confusing. To make this obvious to myself and to make completely sure that all calculations were correct, I made a few intermediary versions. The first one was to make sure everything works well with the grid:

Visible grid

Screenshot:

image Afterwards, I needed to make sure that the colors were stored correctly inside the grid. The “bubble train” effect was pretty nice:

Bubbles!

Screenshot:

image

Ok. DONE. All the prep was there, it was time to fill out the triangles. Again, marienna and I did not completely agree. She wanted the fully-opaque, hypnotic, chaotic, version:

Triangles! Chaos!

Screenshots:

imageimage

The hypnotic chaos that causes my eyes to unfocus and start seeing the triangles in 3d was nice, but if you know anything about me, you know I’m all about the soft pastels. Going back to something like 20% opacity for the colors produced something that made me extremely happy:

Pastel joy

Screenshots:

imageimage

And, while I was sure I was done after the mini-metro-like, now I am pretty certain that there’s a lot more work to do here. Some of the things I am thinking about/planning:

- instead of just randomly(ish) selecting an angle, actually apply random forces to the walkers, then normalize and snap to grid. This will allow me to later maybe calculate line density at points in the grid, and make points with high densities act as repulsors, or somesuch

- find a good set/several good sets of colors that work well together instead of randomizing them every time.

- make it possible to add arbitrary border lines that will force the walkers back. Make the walkers “push through” these borders for short periods of time, in order to create a more central structure, with more elaborate branching on the outside.

Finally, if this was interesting and you want to see the code, you can find it on github.

April 21, 2015
insomniacstumblings:
“I made a thing. A seascape thing in processing
”
I haven’t really been here in a long while - a lack of time and energy to actually do any angry cooking has been chronic in the last period. But expect more from me here nowadays....

insomniacstumblings:

I made a thing. A seascape thing in processing

I haven’t really been here in a long while - a lack of time and energy to actually do any angry cooking has been chronic in the last period. But expect more from me here nowadays. Food, processing, a whole load of things for your eyes. Here’s a thing I made this weekend, waves in processing. I’ll write up more about it here, soon. Promise. For sure.

December 8, 2013
Christmas caramels, for one (or for bribing everyone at the office into liking you)

You’d not believe me but, it is actually winter here. For reals. We don’t have any snow, or wind or rain or any of that bullshit, just ice and almost no sunlight. And what cures winter blues better than some obesity and diabetes? NOTHING. So follow along in making these caramels that will warm your insides as you struggle along through this winter. They could also make great christmas presents, if I had any friends. Maybe you have some, so feel free to give these to them (don’t mention obesity or diabetes, you don’t want to scare them away). Or maybe you work somewhere and can bring the excessive amount of sweets there and make everyone think you are not a horrible person who despises them on a daily basis.

So. Caramel. Dealing with caramels is a bullshit exercise in patience. And then there’s some patience too. And fucked up conversions between imperial (seriously? imperial? and fahrenheit? you people should all be sterilized so you can’t breed) and metric, as well as some precision. Yeah, I said precision. Sorry ‘bout that, no “a thimble of milk and a sprinkle of fairy dust” here, no “approximately 200 degrees” crap - we have to be precise because chemistry.

What’s the deal with caramels? Aren’t they just molten sugar + butter? Turns out… not really. Who’d have thunk it? They are also all about preparation and being efficient in your workspace. So, before you do anything, go to your kitchen. Prepare one thick-bottomed soup pan thing (I am still uncomfortable calling the soup things “pans.” English is dumb and needs more words for things. Like soup pans.), a candy thermometer (no, you can’t go without one. Don’t be a fucking cheapskate and buy one.), one medium-sized loaf pan to pour the caramels in, a smaller pan and a bowl for melting butter (or a double boiler, if you’re all fancy and shit) and some wax paper. Line the pan with wax paper, start your double boiler on low heat and get all the ingredients out. Speaking of, you’ll need:
- 400g sugar
- 250g corn syrup, I’m using Lyle’s Golden Syrup because it is awesome and comes in sexy metal cylinders.
- 100g butter for melting
- 4dl heavy cream. Don’t get anything light or non-fat, get the heaviest, fattiest cream you can still pour.
- 50g butter, at room temperature and cubed, that we will save until the end.
- a bit of salt. This is really up to your preference.
- a few drops of vanilla extract
image
Look at that fucking corn syrup. This is everything horrible about sweets in one single cup.
image
Shit, it pours as if it were an industrial grease or something.
image

Ok, with everything prepared, start melting the 100g of butter and add the vanilla extract and some salt here. paaaatiently melt it up, and once it is completely melty, add the heavy cream and keep warm. Not hot, not cold, but just right and warm (I leave the double boiler on the stove set to the minimum possible and just do the other stuff until I need the butter mixture). If you want to add flavors to your caramels, this is where you do it - you can melt in some chocolate or pumpkin puree with the butter, boil a bit of chilli in it or maybe add aniseed or cinnamon. Or just do them right, without any of that crap.
Now comes the patience and the stinky, burney part. Pour the sugar and the corn syrup into a pan. Do NOT mix or stir. Put on medium-high heat and just… wait. Seriously, there is nothing you can do. Mixing will only do… things to the structure of your caramels, and leave hard, crystalized spots. Do you WANT crystals in your caramels? Well I don’t. So just be patient and wait until it all melts into brown goo
imageimage

Hey
Hey
Hey
Hey
Hey
Listen
Hey
Is it done yet?
You’ll probably see a nice light-golden, bubbly mix, the smell of which will make your eyes water and you’ll think “well, I’m done here!”
You’re making a GRAVE mistake!
To get a sexy, awesome, mouth-watering caramel taste, we want the sugar to be very close to burning. Aim for a dark-brown/reddish mix, like here.
image
Is it at the desired color yet? Yes? then it’s time for the most awkward part of the thing - pouring in the butter and the heavy cream without burning yourself. I mean, it’s not like you’re going to lose a finger or three - just be careful. Don’t come crying to me if you end up needing to have an eye removed because of scalding caramel. Also, BEFORE you do this, make sure your thermometer and a heat-resistant whisk or spatula are on hand. Maybe count yourself down from 3, gather up some courage and pour the butter in. Ignore the bubbling and the molten sugar spraying out of the pan. That’s completely normal. Now, quickly whisk and insert the candy thermometer inside. You’ll get this bubbling mass of poop:
image

Now comes the even more boring waiting part. For our caramels to be the exact consistency we want, we want them to hit somewhere between 121 and 122 degrees Celsius. Any higher, and you’ll have a much, much harder candy than a caramel should be. Less and you’ll end up with something you can only eat with a spoon. Note, however, that this *does* depend on the amount of fat you have in there - if you’re trying out shit with more butter or chocolate or something else fatty, experiment with adjusting the target temperature to something slightly higher.

As soon as the mix reaches the target temperature, take it off the stove, add the 50g cubed butter you prepared (you did prepare that, right? It’s up there in the section about “preparation”) and mix vigorously until it melts in. Pour the caramel mix carefully into the loaf pan and leave, uncovered, to cool for a couple of hours. This is the time to sprinkle it with fancy flakes of sea salt, if you’re into that kind of a thing.
image

If you did it right, this will not be enough to make it non-sticky and non-runny - we want our caramels to be chewy and sticky and runny. So, in preparation for serving/cutting up, cover the pan and refrigerate overnight (or however long you want, but for 2-3 hours minimum). You can take it out and cut up into small pieces after that
imageimage

Of course, since you’re a fucking masochist (proven by you reading all the way down to this part), this won’t be enough misery for you, so here’s a fun exercise - get some wax paper and try to individually hand-wrap each piece of caramel while preserving it’s shape and look. I gave up after about 2 hours, when I noticed my tears were melting holes in the remaining candies. Just imagine, after you get them out of the fridge, in the middle of a night, a few days from now so that you can sit in your underwear and stuff yourself with candies while watching reruns of some shitty reality tv show, you will have the pleasure of unwrapping each piece before you eat it. Then, for advanced-level misery, you can stack the wrappers on top of each other and count out how many you’ve eaten each day. Isn’t that the best idea ever?
image

“Hey,” some of you might ask, “what’s so christmasy about these caramels of yours, Ivan?”
Fuck you.

November 3, 2013
Comfort lentils

I was planning to do a nice pumpkin soup and some pumpkin-flavored salted caramels this weekend, but the rain today lead to a rainy-day inside, with a soundtrack provided by the Deftones. And what’s a cold, rainy November day requires some comfort food. Now, I don’t know what you consider a comfort food, but if you’re anything like people in Norway, it’s something completely insane, like brown cheese and jam. Ech.

For me, the comfort food of choice for cold, wet, sad days is a lentil soup/broth-type thing. It is super-simple and looks like vomit, but it is wonderful and healthy. It also keeps well, so making a lot of it leads to days and days of reheatable, wonderful, comforting goop. And once you’re sick of the texture, you can reheat it, take a blender to it and have some nice brownish pottage thing.

Things! We need things. With the exception of lentils, everything on this list should already be in your kitchen.
- Olive oil. A tablespoon or so
- Lentils. I like using approximately one cup of brown lentils for each 1/2l of soup. You can use green too, but skip out on the yellows or reds for this occasion. You want the lentils to not melt while the soup is cooking and the red and yellow ones tend to be… a bit melty.
- 1-2 medium-sized carrots. They’ll add some nice sweetness to the soup.
- A stalk or two of celery.
- A teaspoon or five of cumin. The more cumin you use, the more it will taste like cumin. The more you know…
- A shitload of shallots. You can use a largeish onion but, well, shallots. Because.
- Garlic to taste. As established previously, I like using a lot of it. It’s not like I have anyone to speak to or be intimate with.
- Spices! Sea salt, freshly ground pepper, green shit and, if you feel experimental, some ginger.
- Vegetable broth. 1/2l per cup of lentils or a bit more.
image

Wash the greens, cube the celery, slice one carrot, just peel the other one, chop up the onions. PREPARATION: DONE. What? It’s not a hard meal to make. Just hit things with your knife. Take at least one clove of garlic and leave it whole, and mince up the rest. Make two small cubes of ginger for the cooking. We’ll mince some ginger into the finished thing later too.
image

Heat a large saucepan/soup pan on the stove and dry-fry the cumin seeds for a minute or two. Take out half of them for later. Maybe eat two. Or a handful. Apply some photoshop filters to the photo to make it not look horrible.
image

Add oil to the remaining cuminses place on medium heat and toss in the shallots and the sliced carrots. Stir around for 2-3 minutes, until the shallots start going transparent/goldenish.
image

Throw everything else in, except for the salt. Adding salt before the lentils are cooked will probably lead to your soup turning into mushy goop. So don’t do it. Just don’t.
image

Now, bring the heat up to high, wait for the mixture to boil and then lower the heat down to a low, low simmer. Leave for an hour or so. Since it’s raining, it’s the perfect time to start your Gilmore Girls re-watch. Maybe think a bit about how putting in the celery so early will cause it to melt into weird, grayish ooze, or how you might have preferred the carrots to stay a bit crunchier.
Try to do something about it but then decide that it’s too gray for that.
Try and get up to make some tea or coffee but decide you don’t have the energy.
Rant on the internet about how Dean is a fucking douchebag and how Jess was a much better boyfriend to Rory and then disappear mid-rant because, well, almost nobody else cares. Fuckin asshole Dean. Hell, even Veronica/Piz is less horrible than Dean/Rory. gfdassadadf

Hey. That hour lasted approximately an INFINITY of minutes. But at least now the soup should be done! I was right, it does look like, well, pretty much like someone took a giant SHIT inside your soup pan. But it’s oh-so delicious and comforting. Grate some ginger in there, maybe throw in some dill on top, salt to taste and EAT. Refrigerate whatever you don’t eat and heat up whenever the rain falls again.
image