I’m in! I will be using my V2 with a 60 led strand until my V3 with sensor board comes… then my daughter may get my V2 I’m hoping to get her interesting in art/programming.
On how to approach this sort of thing: The art of making software is less about coding, and more about looking at a problem and breaking it down into smaller problems that you can solve elegantly.
In this case, we want to light a random pixel for some period of time – certainly for more than one frame. This means, to start with, we need a random number!
The random()
function is a great way to get a random pixel index to use. But since random()
returns a different random number every time, we can’t just call it on every frame. That’ll just flash different random pixels and look like static. We need a way to generate a number and save it for a while.
There are (at least) two general ways to do this. The usual method involves storing the values we want and retrieving them at render time. If you want to light more than a single pixel though, the amount of storage required goes up. Enough pixels and you’ll wind up out of memory.
The alternative requires the storage of only a single value, no matter how many pixels you may eventually want to light. (Hint: This technique is used by games with “procedural worlds”, and also usually involves a bit of xor, which should make the xorcerers happy. ) Big props if you can solve it this way!
Thank you, that’s exactly the sort of discussion I was figuring we’d have: how to approach the task, so people see how to break it down and figure out the pieces.
What does time() do? I see it in some examples in the BeforeRender like
t = time(0.5)
at first I thought it was like a delay but that doesn’t make sense and the PB docs don’t mention it or I am just missing it.
I found some info here Slow Down Render
You missed it. It’s on the page under…
Waveform Functions
time(interval
)
A sawtooth waveform between 0.0 and 1.0 that loops about every 65.536*interval
seconds. e.g. use .015 for an approximately 1 second.
It’s not a delay, it’s a slant up straight down wave “sawtooth” means it’s:
/|/|/|
And if you put 1 as the interval, it’ll take 65.536 seconds to do one climb from zero, hit 1, and drop straight back to zero, and start over.
For those wondering about when beforeRender gets called… beforeRender(delta) Question explains… if you have 3 pixels…
the order is beforeRender(delta), render[0], render[1], render[2] and then repeat for infinity. The delta in the beforeRender(delta) is the amount of time since the last beforeRender was called.
I’d describe it:
BeforeRender is called
Then Render (or Render2D or Render3D if they exist) is called, which loops thru all of the Pixels 0…pixelcount-1 (so X pixels, it goes thru 0,1,…X-1)
Then Start over… So beforeRender, Render, and again.
These two are basically the 2-stroke engine of patterns. (I’ll come back to this analogy in the future)
Prime the pump with BeforeRender, set your variables that any given “frame” of animation will consist of… Then render the frame, going thru each pixel, which may and likely will require computations, some of which are personal to that pixel (# in pixel count, aka index) and Mapping (pixels location in 2D or 3D space, usually but not always, the map could be anything, we’ll eventually come back to this, months from now… ). This pushes the pixels out the door, and then you start over.
So in context of the current Task:
Decide which pixel should light, how long, if it’s twinkling, etc… These need to be random, right?
Pumping the pump: BeforeRender
Then we display this info (Render),
and go back (BeforeRender) and see if we’re done, and if so, pick new random things and start over.
Make sure to comment your code generously
I’m in I fully expect ZRanger1 to utilize the center column of rule 30.
Do we have a function that gives a random value between min and max ? I see that random(x) is between 0 and x… I was thinking about using clamp around that but that would not be random it would be mostly min or max…
I feel like I am burning the cobwebs out of my brain… what is that burning smell!?
If random(X) does 0…X, then random(max-min)+min will do that.
Is there an “acceptable” way to make a delay? Since we are only outputting one pixel I think mine looks like noise because it is going to fast. Though shrinking the fading speed is not helping. So it’s possible I have other issues
Another question. How are we to get help when we don’t know what is wrong? It would be cool if someone could look at our “attempt” and tell you what is wrong without telling you the solution to the assignment. Does that make any sense? I am getting an “execution steps exhausted”… I think my PB is tired of weak programming
Does random(max-min)+min work for values of max and min that are less than 1?
I figure that people can post partial solutions if they get stuck… It’ll help everyone to see where folks get stuck.
IMO, posting a litte code and asking for help is great! The object here is for everybody to get better. For folks a little further along the path, having to come up with good, simple explanations for why “this” and not “that” helps them improve their skills and understanding too.
I consider myself a relatively awful teacher – @jeff and @scruffynerf, among others, are much better – but still, most of my IRL work lately involves designing things, then explaining them to people at sometimes vastly different levels of technical knowledge. It’s a skill well worth practicing.
It’s absolutely a skill, and teaching often helps you get better at it, especially if requires you to break it down and see it anew. I have the sort of brain (and always have, since I learned to code from a book and occasional RadioShack visits to type on a store TRS-80) where I can visualize code in my head. But that also requires understanding the pattern(s) and how to code.
All of these skills are intertwined…
I won’t teach you to code, there are many better teachers and videos and books. But a way to see how to see the task at hand, and ways to solve it, that’s helpful for all of us.
There are many ways to solve this task. I intentionally left it vague. And funny enough, a single random pixel is much harder than just randomly lighting a bunch of pixels, then lighting a new bunch, that’s a super trivial task, making static is both easy and “not art”. Focusing on a single one forces you to examine the elements in detail, and not shotgun it.
I’m gong to say that you should try some examples and answer this for yourself. Also negative numbers? (Which shouldn’t be possible if Max is bigger than Min, meaning you might need to be sure it never is…)
And if random with small values, doesn’t work as expected, how could you work around that? Hint: If random(1), aka between 0…1 works, you have a random percentage.