 Hi, so I'm here obviously to talk to you about algorithmic light art Now I started a few years ago just doing the standard Arduino and a strip of neopixels Kind of desktop projects in order to kind of take some cool stuff to festivals and make my room a bit livelier And I'm incapable of stopping doing anything. So I kept escalating and I'm gonna take you through first a couple of pictures of things that I've made or have collaborated on So this is the first one. This is at an event called Rumpus in London a couple of years ago These are basically the standard RGB LEDs you get except on strings rather than on strip Which means you can drape them over places now you can get these just off Aliexpress and it's a very good way to kind of Make the installation 3d and make it fill a space Another one we've got here is these are The cores of these are custom PCBs which are pentagonal each of which has five LEDs on and they're arranged in a dodecahedron and I've done the geometry to Spherically to to map the coordinate. This has less of the lanterns in than I recalled But anyway, I've done the geometry to map them into spherical coordinate space So each of the lanterns has basically a very low res Projector in the center of it meaning we can do sort of animations on the outside of the icosahedron lanterns They are an absolute bear to set up. I have to tell you but they're very rewarding and This is one of my latest projects with my partner D who's over there. These are laser-cut Lanterns which we beveled and their frosted acrylic with patterns cut through them So you get a kind of mixture of hard and soft light and they project patterns onto the flat surfaces around them they a lot of what I found makes a project really kind of stand out is not the not the LEDs themselves, but the kind of the diffusion and The how sensitively they're built to work with the environment So when I started doing these I thought I just want to make light stuff and in the way that hobbies tend to it broke down into kind of two things which I didn't really enjoy doing which were power engineering and algorithm design neither of which I was particularly talented at but Hopefully I'll be able to talk you through some of the early mistakes I made to Help you know where to start So in terms of basic system architecture, and I'll just touch on this briefly You've either got microcontroller based system. This is your classic Arduino and a strip of Neopixels With nothing else in the system. It's very easy to get started with it features in a lot of the kind of Basic tutorials that you get when you're troubleshooting them There's very few things you need to worry about because it's just a sort of two-stage system. You can Tap this signal line with an oscilloscope or just Multimeter and listen to see if it's buzzing to see if you've got a bit stream going on the signal line One thing is if you want to have them reacting to real-world stimuli or if you want to do a lot of sort of Spatialization or on-the-fly generation of patterns you end up quickly running out of compute space or Compute capacity and memory space So the next thing up is in the most general terms putting a PC In line with a microcontroller so the PC is running the sort of control software that generates what each LED should be showing and it's sending then Frames to a microcontroller which does the real-time Rendering for the bit stream for the LEDs because Depending on your level of experience with this sort of thing it may be incredibly obvious But a PC can't do the precise timing that the LEDs require this gives you the advantage that you can like just plug a connect in via USB or you can sort of code in Python which after dealing with Endless hours of segfaults and array out of bound errors in C and C++ I found a great relief The next thing to think about when you are specking up a system is what type of LEDs you have So there's the basic RGB ones. These are the kind of stock art of fruit neopixel Type they've got three color channels. They take three bytes per pixel in the bit stream They're very good. They give really kind of rich bright colors They're very well documented, but they're quite bad at pastels and they're really really bad at atmospheric lighting because when you try and mix white each LED has a sort of up to 10 percent variance in It's response on the different channels and each of the channels is different with respect to all the other channels So when you try and mix white you end up with this kind of Each LED being a slightly different not white and it always makes me feel like I'm drunk at the dentist Which is not an experience. I really want At any time So I like to use RGBWs and these are quite quite simply They've just got a fourth channel, which is a white or a warm white LED and There's a simple algorithm for converting RGB to RGBW which is you take the minimum of the three channels You subtract that from those three channels and you assign it to the white channel And that gives you as much white as you want with the kind of higher precision of mixing in the other colors to get really nice sort of natural tones or pastels and even kind of Further down that line. You've got wwa pixels, which are not a wrestling league. They It's white warm white and amber or sometimes you get cool white neutral white warm white and amber and it's for mixing very precise kinds of natural lighting and I've always wanted to do a fire animation with them because I like doing fire animations more than I like doing anything else really And because they've got a much narrower color range and the same kind of signal Parameter space you get much much finer gradations in what colors you can use so you Yeah, I'm very excited, but I haven't actually done anything with them If you are building a system that's at all non-trivial I Recommend in the most strong possible terms that you set up a simulation so Open pixel control is one of the libraries that sends to Fade candy it runs very nicely on a pie and it comes with a bundled simulator So this means that when you're setting up the system You can first test what the computer thinks it should be doing separately from testing what the hardware is actually doing and that kind of separation kind of halves or better the inevitable debugging time so you can It's also very good for developing patterns because you don't need to sort of Set up the system make sure that the power is working crank your head back in your chair and look at the LEDs that are strung all over your living room and blind yourself endlessly trying to kind of tweak the exact fading from white through pink into blue of that edge of the pattern and Yes, I strongly recommend Going that route this of course if it's going to simulate where all the LEDs are it needs to know where they are so generally the way I go about this is like if One project I did this summer had hexagonal Strings of bunting that were tiered and so it's quite trivial in Python to say okay I've got this many LEDs and they're on a hexagon so each LED the the hexagons have this major diameter and This height so in Python I can Work out Where each LED is and you can then sort of estimate the swag in the strings so you can say okay, so it's this plus Some function of sign which I've forgotten because I'm incredibly socially anxious and don't talk on stage very much Anyway, I So yes, you you generate a JSON file which has a linear list of Point definitions and feed that to the simulator and it makes your life a lot easier now gamma correction this is Very the solution is very simple the reasoning is Unreasonably complicated so the way your eye perceives Differences in levels of brightness is non-linear a the same difference at bright Like ten lumen reduction in a bright light is barely noticeable and in a low light It's incredibly significant. So if you as the LEDs have a linear Response if you fade linearly like 255 244 253 then it will look like it accelerates and kind of plunges into blackness very suddenly at the end which is very kind of It just feels off if you've got something like a classic sparkle pattern It looks nice if they sort of taper gently into the background color so There is one right way to do this which is that precious gem in software and It's just to use a lookup table. So for example, you've got a 255 bite array and each the index of each bite is the Input value the effect of brightness you want to transmit and the contents of that Slot in the array is the brightness level you should set the LED to in order to get that brightness the Neopixels library examples have a Table you can crib from and example code. It's very simple now color schemes The best thing about RGB LEDs is that they are RGB the second best thing is that they are LEDs so We want to make glowing projects that people come up and complement us on and So this means they need to sort of stand out now. There's a bunch of different ways to Go about this and I've realized At this very moment that I've put them in a slightly unintuitive order. So I will need you to bear with me The first thing a lot of people think of is just picking random colors So it's very computationally simple. The algorithm is very intuitive You just for each pixel that you have for each channel that the pixel has you pick a Number between 0 and 255 with linear probability It's all right, I guess it kind of it gives you something that shows off the Capacity of the LEDs it gives you something which kind of shows off what you made but it's a bit kind of tacky and noisy and feels not put together as Expressed in mean format in the last two bullet points. This is a simulation of that Now this is the open pixel control simulator. I was talking to you about You can see like it looks a bit like Analog video noise and that's basically because that's what it is. It's kind of Yeah, it's pretty but we can we can do better than that so the next thing to do is to have a color you want them to be a bit like and For each pixel for each channel you pick A number on a Gaussian distribution around that channel's value in the target color so a very cheap way to do this if you're on a microcontroller is to pick a linear Linear probability pick a number from a range where the center of the range is the target color Do that several times and average them out And if you do it sort of three or four times then that Approximates a Gaussian distribution with very low kind of cycle cost That would have been a very good thing to put the code up on the slide, but I did not So you can have the mean color shift over time. So if you're using a palette Which I will be talking about in the next two slides then you can have it kind of Rather than having it a smooth gradient of the palette colors You can have them sort of near the palette colors and this gives it a much more kind of organic dynamic Feeling rather than just being a static display Things you can do with this is you can tweak over time or modulate or oscillate the standard deviation Which means that they get more and less like the central color over time this is an example of that and Like hopefully you can see I'm not sure how well that's showing up on the background, but it's kind of it feels themed and The theme is obviously like a psychedelic opium den, but that is weirdly nine times out of ten fairly safe place to start so like These these are all approximating the same color Which is the header color from my slides and they've got a sort of standard deviation of 32 I think so it's kind of off into pink and off into sort of peach and red and Yeah The next thing is pallets so Obviously a palette is a an array with a bunch of Color values in that typically fade One to the next so if you just display consecutive Values from the palette on a strip of LEDs you will get that nice sort of ubiquitous rainbow effect Pretty much all the libraries come with a couple of quite good pallets built in like They look really nice the one you will have seen is the rainbow one Which comes with pretty much everything because it's easy to make a rainbow and Another one you might have seen is there's a good sort of purple and indigo and orange one that comes with fast lead that I've seen a lot of kind of regional Burning Man events They look good, but everybody uses them and It's kind of a shame if you've made for example 40-foot motorized light up fire breathing anglerfish to just sort of slap a test card on the side and Even more importantly the people you really want to impress who are the other nerds Will think less of you for it rightly now The way I like to go is custom pallets, so This is obviously pallets which are Custom which you've defined yourself now when I first started doing these I would go into a paint program Choose a color I liked find a hex code feed it into a python script linearly interpolate between a bunch of hex codes that I want It was awful So I realized that the right way to do it and this is another one of those gems where there is one right way to do it is To open up like Photoshop or Gimp or MS Paint or whatever your jam is and paint a palette and This means you can kind of keep an eye to keeping the kind of luminance of the colors Approximately the same because if you if you have a color that goes a little bit darker or a little bit brighter That's way way more obvious on LEDs which are much brighter than it is on a Screen so use with caution You then save that as something Sensible like a PNG or a bitmap and you write a python script Which iterates over the first row so I tend to do mine sort of 20 by 2000 or 100 by 2000 and iterates over the first row gets the pixel color of each pixel And then writes that into a header file You can tweak it to result in the same or a custom size for the output header And you just use sort of string formatting to produce the header It's very simple The there is an example up on my github, but it's hidden in last-minute anxiety attack of a repository so I might Skip over that for now Here is an example of that you can see along the top is the palace. I've painted and You can also see the center of the canvas there is lagging a bit behind the edge so it looks like the colors are kind of Shrinking into the middle and so we've got an offset in the palette which is Linear different distance from the middle which is just Pythagoras and an offset which is how much time has passed and You kind of just add those together and it'll get you a gradient over the course over the Area of your canvas which is moving So I would now like to talk about how I go about building an algorithm over time because it's One of the least kind of Intuitive things I found about the whole business So the obvious thing to start with for me is a sparkle pattern because the sparkle pattern looks good on everything. It's quite Intuitively linear so The basic algorithm is you have a buffer which has the pixel colors Each frame you check to see whether the should be a sparkle this frame So you say sparkle chance is point zero two five and If a random number between zero and one is less than point zero two five you spawn a new sparkle and You pick a random pixel for it to be in you pick a color based on where you are in the palette or however, you're picking your color scheme and Then there's two basic ways of implementing this if you're on something where computing power is quite Limited or specifically something without a floating point unit you want to have Set the values directly in a pixel channel buffer and kind of reduce Down to a minimum of either zero or whatever background color you want each Channel in each pixel every frame. So At the beginning of each frame you just decrement all the values by two unless that takes it below zero or if you're on a PC and Or a feeling fancy you can just record the time the last sparkle time in each for each pixel and What color It was and then each Each frame for each pixel for each channel that channel is one over the elapsed time times The channel value of the original color. So it's basically an inverse square reduction or an inverse reduction over time this is a an Example of that implementation you can see that when a sparkle starts it's a very hard cut on and they're kind of fading if you keep your eye on one pixel you can see how they sort of fade into the background and a nice example of the kind of multiplying different size channels or different magnitude channels by the same Less than one value is you get slight chromatic shift as they fade which makes it feel Kind of again organic and rich in a way that the linear fade isn't But I don't really like the Hard flickering it feels kind of jarring in a way that if you're making kind of For example lighting for a space in which people are monged out routinely It's a bit much. It's a bit hectic. So I Like to do a low-pass filter, which a bunch of you will know about but for those of you who may not it basically It smooths out Higher frequency signals. So things that happen very fast don't get through and things that happen very slowly Don't get through now. Those of you who do know what a low-pass filter is. Please forgive how badly I butchered that explanation but Concretely what we do is we keep two buffers one with the Calculated value that we received in the last Example and one which is the display buffer So each frame the display buffer equals say naught point nine times itself plus naught point one times the Rendering buffer, which means that everything fades in and fades out smoothly For the cost of one floating point or two floating point multiplications per pixel per frame But channel per pixel per frame and This is good because it gives us a bunch of free stuff, which I'm always keen for it When you switch patterns It doesn't just jolt straight to something else It kind of linearly fades between the two and when you're turning it on and when you're turning it off it kind of fades in and fades out and Another thing you can do with this is you can modulate the mixing factor over time so you can make it more soft and smooth and more kind of Sharp and crisp on either with a slider or in response to The beat of the music or in response to some other thing a nice thing to do is to hook a connect up and to sort of just take the Average amount of movement in the space and when there's more more movement have their pattern be sort of hotter and more hectic And when there's less movement have it softer and slower Here is Simulation of that and you can see that it feels much kind of gentler Yep one downside of doing this kind of thing is I usually When I'm trying something out I will just bring it up on the screen for a couple of seconds to check how it looks and then I will hypnotize myself and Discover I have been staring at it for half an hour and my tea's gone cold and I'm late for work So another thing another reason I like the fancy Time fading rather than value fading algorithm for sparkle is it lets you control The flow of time within the program so you can instead of calling time directly you can just feed a value which represents the effective time and Each frame you take the value of say the potentiometer as Cast to zero to one and you multiply that by the actual Elapsed time since the last frame and you add that to the effective time Which means if the potentiometers at zero you add zero so time has stopped and if it's at four because Obviously I said zero to four not zero to one If it's at four then time is going four times as fast as it would have done This means that you can kind of if you just multiply the time value by that factor Then you end up shuttling backwards and forwards in time and that breaks a lot of things Unless you spend hours programming for it, which I will not so This is obviously a different layout This is the simulator for the icosahedron lanterns you saw at the start of the talk And this is you can see they're stopped now and this is going on a sort of 24-second period sine wave So it's a very kind of easy and very cheap once you're doing all the other algorithms way of Tweaking the kind of feel of an installation in real time Now once you've got the sparkle pattern Implemented you can try doing a bunch of different things like I said earlier that you can Combine the position in time and the position in space of each pixel to get a Point in the palette to sample You can instead of using the sparkle to generate differences in brightness use the sparkle to generate a Value that you either add to or subtract from the effective position in the palette So you can see this seems very kind of Smooth and normal when there's not much color change happening But when there's a sudden change it sort of shimmers and it makes it feel dynamic and reactive when it's actually just a kind of static algorithm Another thing you can do now I'm not going to go through the implementation of this because it was a nightmare and I don't want to but Instead of having a kind of linear buffer that says this one lot last sparkle at this time you have dynamically sized array which has spark events which have time and color and The time is used to generate Where on the string it is and where on the string it is is used to generate kind of how bright the LED should be of that color and So if it's before Before the position on the string. It's no no brightness and if it's after the position on the string. It's an inverse Decrease and each string has its own dynamically sized array and you can just you just run over all the events in that array and Add them all linearly to the point of the LED To to the color of the LED or you take the maximum One thing I discovered is it's very important when you're doing something with dynamic event spawning To check when the event is no longer having an effect and delete it because otherwise your program gets slower and slower And slower and you feel like you're dying and then eventually you figure out what's wrong so a Slightly more Straightforward algorithm, which now I think about it. It would have been a very good idea to do first is when I called the wobbler because It's based on a quite Intense evening I had with this album Both listening to it and staring intently at the album cover I'm not easy to live with really So it's kind of in this instance what I wanted was a radial arrangement of LEDs with a line Around them sort of wobbling with the colors smearing out so What we need to do is we need to break that down into steps we need so a radial arrangement we Generate that quite trivially in Python we feed it to the open pixel control Simulator then we want to circle halfway down the strands. Okay, so that's clearly a radius Which we can generate in two dimensions or three dimensions and we define the brightness of the LEDs by the Inversely to the distance from that radius on either side So now we've got circle and it's white because all the channels are the same Now we want the line to wobble so we modulate the radius with a sine wave based on Position in time plus strand index so we can I liked the three sine waves because it gives a kind of triskell Effect so you now have a line that wobbles which great good start and we now want to Have the colors split out which once the lines wobbling. It's very simple to add or subtract a value to the To two of the color channels or to multiply them by different factors So that the sine waves don't quite line up and it goes into an outer phase Which will hopefully be much clearer to look at than it was to here But we can see they're kind of falling in an outer phase And this is sort of a 10 meter diameter installation that you saw in the first slide with a picture that's over a dance floor and It's quite good, but it's It's a bit boring so The first thing I thought to do was to say okay, so we've we're modulating a bunch of things The chromatic aberration factors are remaining static So maybe modulate them on a sine wave as well And this is an idiom that I come across again and again in this kind of thing where it's just a case of adding enough Simple perturbations to the system to give the impression That it's much more complicated than it is so there's kind of a balancing point where you reach the limit of people's The average person's ability to pick factors out of a pattern and you go a little bit beyond that so like factors of The system keep leaping out and disappearing again But you don't go too far so that the system just seems chaotic and nonsensical and that kind of is the best point for giving people Like Crunchy is the only word I can think of which is not the word. I'm after intellectually kind of engaging experience with your psychedelic club lighting so I Really like the way this turned out because it kind of gives you a nice sort of negative space Hypnotized again a nice negative space rotating triskel in the middle that gets more rounded and more kind of Pointy over time, but it does spend a lot of time in white which is a lot more galling when you're talking about 320 LEDs than it is Talking about pixels on a screen because again these are RGB's because you can't get the RGB w's in strand format They have told me to stop asking So You end up with that weird dentisty white light kind of washing over the dance floor every three or four minutes and then suddenly everybody's Looks a lot less interesting so the next thing I wanted to do was to kind of Modulate the diameter so it kind of shoots out from the middle like you're being abducted by aliens and It wobbles about a bit and then it shoots back into the middle and when it's in the middle we can twiddle around or swap about the Chromatic aberration factors, which means it looks like it's a different set of shifting colors each time so That's how this one looks and We end up sort of with a very dynamic Quite immersive experience because it's shooting out over your head and it's Circling around you so it kind of draws you in in a way that just sort of sparkly lights do not which is sometimes what you're after and sometimes not and So the basic overall protocol Is to start by trying to imagine What you want them to look like either by coming up with it on your own or by ripping something off wholesale because as You've seen over the course of this last example when you rip something off wholesale with this kind of System by the time you've approximated it in software and then tweaked it so it doesn't look awful and then Kind of rendered it over a quite sparse LED arrangement it bears little to no resemblance to the thing you started out trying to rip off so You get a lot of leeway there you then kind of like with any software try and break it down into Intuitive stages like the the classic how to draw an owl picture draw two circles draw the rest of the owl and Then again try and find a balance between predictability and chaos now I Would now like to show you what I spent last winter doing which is by far the most Over-complicated thing I have ever done So this is the control system for the lighting for a geodesic dome and it's for it was for burning nest, but it was also taken to nowhere this year and it's something like 2000 LEDs and the This bit in the middle is a projection screen Which is projected on from above and the reason I decided to do this all from one piece of software which is Way more trouble than it was worth was because I wanted this kind of trick here where the LEDs are set from the screen So you don't need to generate a color scheme and you don't need to generate patterns You just need to find sort of VJ clips that work well Which was mostly because I was bored of writing patterns and I'd run out of ideas But I'd already been given funding for the project. So We've got here on the bunting you can see There's a smooth palette display and that's the palette that's kind of in the camps theme colors And you can swap between concentric or radial And it's quite nice a funny thing happened to me on the way to the psychedelic dance floor which was that I first wrote the video rendering pattern and I wrote the sparkle pattern and I tested it with the power distribution fine took it to the site somebody said I need to run workshops in here We need a less confusing lighting patterns. I thought ah, that's very simple I'll just write a smooth palette generation smooth palette renderer now This takes about five times as much power as either of the other patterns So the power supply blew up and I had to Amazon prime one out into the middle of Devon and So we were rigging for five days of a seven-day event, but it worked nearly flawlessly the next time and this is the Sparkle pattern you can see and you'll notice that has the low-pass filter. I was talking about earlier now The low-pass filter was very very important for setting it from the screen because When you've got a line moving across screen when you're rendering that over a sparse grid of bright LEDs that turns into a million tiny flashing very bright lights, which is not my jam and So the a quite aggressive low-pass filter means that whatever you put on the screen you end up with a kind of smooth pattern and I think That's about all I've got time for Thank you very much. Yes Now you mentioned it. I am taking questions. Does anybody have any questions? Yes Yeah So I have two actually one of them is Whether you have ever run into problems with gamma correction Essentially Being quantized and essentially losing your resolution as you're getting dark So when you have a relatively slow Fade to dark you would end up essentially with color steps as you're fading to dark. Yeah So the way I deal with that is I Do the gamma correction at the very last stage before transmitting the bit stream so when you're transmitting it you have 256 possible values and they map nearly uniquely to 256 other possible values and On one project I did I ended up generating a 1024 value gamma table and it wasn't enough better to be worth it. So Not really so And the other question is do you ever use? Well more perceptually uniform color spaces for interpolation and such so Cie xyz that for example Sorry, can you say that last bit again? So do you ever use other color spaces like Cie xyz? Yes, I Hsi is the one that makes most sense for this kind of thing because it's It's the intensity that's most obvious I use that sometimes but I think I'm now kind of used to generating those effects in RGB and It means if you're on a microcontroller, you need a sort of arm cortex rather than a 80 mega 32 you or whatever and it's I used to I've kind of stopped it to probably be a good idea to work in those spaces That's not a very satisfying answer. I'm sorry. Does anybody else have a question? Yes You mentioned RGBW and the warm and cool white What is cool versus warm white with which one is your preference? Okay, so cool white is Slightly towards the blue spectrum Neutral white is kind of as close to the middle as possible and warm white is sort of into the red orange So like these lights are slightly warm fluorescent light bulbs are slightly warm No incandescent light bulbs are slightly warm fluorescent light bulbs are slightly cool I really really like the warm white Like it's possible to write algorithms that map Perfectly using those by sort of Anticipating what Proportional channels they use and kind of dividing that into the Into the target value rather than just finding the minimum But I really like the way it kind of just shifts everything to be a bit warmer. Thank you and thanks for the talk That's absolutely fine anyone else Yes, I Really enjoyed your talk and then the installations look great I was wondering what the breakout boards look like for some of these installations because you got so many LEDs I kind of so the The biggest one at the end. I just do sort of The Octo WS 2811 breakout board for teensy is a standard available one that has two ethernet jacks which each of which has four pairs of signal and isolated ground and I broke that out to Ethernet switch front panel Which was a way more complicated way of doing it than was necessary or desirable the icosahedron ones Breakout that was kind of one of the first projects I did and the breakout board was just an enormous thing of strip board with Very fat solder traces down it to carry the power lines if You catch up with me later I'm camped over in accessible camping and we've got one of the little lanterns that you saw in the third slide With us if I can find an extension cable that is exactly one meter longer So I'll probably be hanging around there if you want to come talk to me about that later cool There's one more question over there. Hi It's a great talk. Thanks very much. It is much a comment I'd have thought that for your low-plus filter. You don't need floats You should be able to do everything with fixed point and integer master any Which could means you could do on the microcontroller. Yes true. I've Always left it too late. Okay, and I've never taken the time to figure out how to use a fixed point library But that is entirely accurate. Yes. Okay. I'll have a chat with you. Thank you. Yeah Cool Thank you very much. Oh, wait. Oh, no. Yeah Well, if okay, so I was wondering if you needed I'm Is this on ah, I guess we're done. Thank you very much. Thank you very much. Enjoy the rest of your festival