Random recursive function that stays near the initial value

29 Views Asked by At

I am working on a procedural CG scene and have populated a starry sky with particles of random size. My goal is to make the stars twinkle - in this case, by varying their size and/or alpha channels. The limitation of the software is that the only variables I can store per-particle are current size and current alpha - no initial states are preserved between frames. I can assign a function to each of these channels which effectively iterates over time: alpha = f(alpha);, size = g(size);

Another small detail, frames are integers only.

I am not experienced in this topic, but it is simple enough to create something pseudo-random, my first draft was f(x) = tan(sin(f(x-1) + tan(f(x-1))));

Graph of the above function. I cannot attest to its effectiveness, but it is a start.

This is all good, and after some tweaking can probably produce good-enough results, but there is one problem. I need my function to stay within a certain range of my initial value. So, if the initial size of the star was i, I would like it to stay within the (i-r, i+r) interval. So a big/bright star would stay big bright with some variation, and so would a small/dim star.

I am a little stumped. I would certainly appreciate a working example, but I would be very interested in learning how you would approach this problem in the first place, and what knowledge would be relevant. Thank you in advance.