Question about the new pattern Blinky Eyes 2D

So I downloaded this to try it out on the 8x8x8 cube but when I go to load the code it’s giving me a “no valid render function found”. I don’t really know enough about coding (I’m currently crash coursing though trying to figure it out), but was hoping for some insight as to what’s missing.

Like I know it NEEDS a render function, but not sure where to insert it?

1 Like

Hi @Shakes999!

This commonly happens when the pixel map you have loaded is for a different number of dimensions than the pattern is written for. If you have a 8x8x8 cube, you probably have a 3D map loaded - each pixel provides an X, Y, and Z coordinate. This Blinky Eyes 2D pattern was only written with a render2d() function, meaning it was designed for 2D flat displays.

Let’s see what we can do to project your 3D cube down into 2D space.

The simplest is probably to ignore one dimension entirely. I expect we’ll see the pattern on two of the 6 sides. To see it better, I’ve configured @GeekMomProjects’s wonderfully documented code to only show 1 eye.

var neyes = 1             // Show 1 or 2 eyes on the display

Now, let’s just try ignoring Z. To do this, I’ll provide a 3D renderer that only passes through X and Y.

// Add this outside other functions. I like it right above render2D().
export function render3D(index, x, y, z) {
  render2D(index, x, y)
}

Awesome, “looking” good. (I hate myself, couldn’t resist).

You can pass a different subset of the dimensions to target other sides, or filter out one of the two sides:

export function render3D(index, x, y, z) {
  if (z < .5) {
    render2D(index, x, y)
  } else {
    rgb(0, 0, 0)
  }
}

Rendering it on all 6 sides is a bit trickier. If that’s what you’re after, take a stab at it yourself and maybe come back and ask for some more help if you get stuck!

3 Likes

Cool! This helps a lot because I’ve noticed this has happened with a few of the 2D patterns I’ve tried on the cube and it felt random if the pattern would work or not. This has explained why I kept running in to it and a bit how to fix it!

I’m gonna give it a shot and see what I can come up with on the cube!

1 Like

Hey its working! Just adding the 3D rendering bit got it functional! Just need some tweaks! Coding understanding is growing a bit!

1 Like

Glad you got it working, and thank you, @jeff Jeff, for the excellent explanation. I’m not sure off the top of my head how I’d go about replicating the pattern on multiple surfaces, but I think that the easiest thing to do would be to create a buffer the size of one side and draw the pattern into the buffer. On a cube, each element in the buffer would map to 6 physical pixels - one on each side. If you figure out that mapping algorithmically, then in the Render2D() function, you just copy the appropriate pixel from the buffer to the pixel array. Again, haven’t tried it, but seems like the easiest approach to me. And now that I think about it, maybe that’s the way I should have implemented the code for more than one eye. It would be generalizable that way.

1 Like

@GeekMomProjects, great pattern, with lovely, clear code! Here’s a super turbo hack render3D() function to get it to display on all 6 faces of a walled cube. Doing a full-on 3D eye for a volumetric cube is um, a little more work.

// walled cube version - this takes advantage of the variable 'v' in the original 2D renderer
// which is always set to some value if a pixel is drawn.  We don't use the value, we just 
// use the fact that a pixel wasn't drawn on one of the faces to tell us to try rendering the
// others.
var v;
export function render3D(index,x,y,z) {
  render2D(index,x,z);
  if (v == 0) render2D(index,x,y);
  if (v == 0) render2D(index,y,z);
}
5 Likes

I have to admit it took me a couple of minutes to see how that worked, but now I get it. That’s super clever!

2 Likes