I am frustrated today because again I feel the lack of my codings skills limits my creativity. So I am wondering about software design. When animations become complex they are difficult to handle with „classic“ programming.
An example: It is about “multi-layer-animations” based on different noise arrays. First I calculate all the noises. Then I have a function for scaling, another one for shifting one noise (while mapping). Also I have different functions for merging the noise arrays – some additive, some averaging and so on.
The problem is – they are all too specific to easiely play with them. Sometimes the functions manipulate the noise array itself, sometimes they just maniplate the mapping. So I started with arrays of arrays to give them indexes – which makes the code pretty unreadable and debugging a nightmare.
I am dreaming of a more abstract description of what I want to happen. Which would it make easy to code thinks like Animation A means: calculate array 1, map, scale and shift it, calculate array 2, merge it with „layer“ 1, shift the result and add to layer 3… and so on – without the need to rewrite all the used functions for that specific usecase.
Next problem is how to apply a kind of a timline for scripting – run animation A for 10 seconds, fade it out with fading method 1, fade in animation 2 using method 2, … I mean I can make all that happen somehow for a short demo, but the code is just a mess full of hacks which I hardly understand myself the next day… all I see is spaghetti code.
Are there any good solutions to deal with those challenges? Is there any way to construct such an abstract description in C? Any recommendations what to read or which techniques to learn?
Thanks for any hint!
I find these kinds of abstractions work better in C++ than in C (it is possible to do in C - but requires more work, and sometimes, oddly enough, overhead).
But then you can have separate objects for each bit of animation, each tracking its own mapping and timing and then you can add and remove them at will.
Take a look at this (specifically the state of this repo at this particular point, I’ve futzed with it since and backed away from this approach slightly because I was going too far into the complexity weeds in a different
direction):
I agree with @Daniel_Garcia – as complexity increases, using OOP becomes more and more necessary. You could define a container for the entire animation, which contains each effect (or composites thereof) which could be transitioned either in and out individually or as composite groups…
I would imagine writing something like this:
Container container(new Effect1(), std::chrono::seconds(10));
container.TransitionTo(new Effect2(), std::chrono::seconds(1), new CrossfadeTransition(std::chrono::seconds(2)));
container.TransitionTo(new CompositeEffect(new Effect3(), new Effect1(), BlendType::Additive), std::chrono::seconds(10), new WipeTransition(Direction::LeftToRight, std::chrono::seconds(2)));
In this case, the container becomes a sort of state machine, and the effects follow the Composite pattern (where a group of effects implements the same “render” methods that the individuals do).
I started to run into these similar issues where I felt the coding was starting to limit my creativity. Very interested in DMX control of LED arrays. You could then move the crazy visual stuff onto the computer with a great VJ software, and simply output to an LED screen.
Upside is way more intuitive control. Downside is you need a computer to run animations, but I believe the microprocessor can be turned into a DMX receiver.
you will become better every day. i’m sure. what should i say? hehe. i’m limited every day. as example i am trying to make the “funky clouds” soundreactive with the spectrum shield since days. for you thats very easy… so, go on, you’re very creative and supergood, one of the best.
Thanks for your nice words, but oh no, my coding style is pretty much at advanced beginner level.
What is your specific problem with the shield? FunkyClouds contains everything you need, your specify the 4 pins and that is all. Where did you get stucked?