Author
Topic: Fun with Math (Read 4597 times)

Might as well post this here, see if Keith/X/someone else has a clever idea.

Given two inputs that are the X and Y coordinates of a location, write a function that produces a single boolean output that adheres, as best as possible, to the following criteria:

1) The output will be drawn to a bitmap display. False will draw white, true will draw red.2) Red pixels will be less common than white pixels, exact ratio is unimportant3) Red pixels will be _no closer_ than 8 pixels, but the ideal distance would be between 16 and 32.4) There is to be no randomization in determining the output or storage of previous results5) Most importantly, the resulting image should have the _appearance_ of random noise.

OK, I have a semblance of a solution, but I have no worked out the specifics. I'll try to explain my line of thinking.

Imagine your world is split up in a series of "streets" and "blocks". The width of a street and the width of a block is the minimum distance you want to have between points.

The first thing your function needs to determine is "am I currently on a street, or am I currently on a block?" If you are on a street, you are not going to draw a point at all, otherwise, you have the opportunity to draw a point, and the function will only determine one square within a block to be valid. So it's a two step function.

Think of it this way, your coordinate needs to generate a mega-X and a mega-Y. The first 8 positions are mega-X 1, the next 8 are megaX 2.. etc. etc.

So if your mega-X OR your mega-Y are even, then you are on a street. Another way of saying it is you are on a block if and only if your mega-X and mega-Y are odd.

So the first half determines if you are currently in a block, you need to determine which of the 64 squares within that block you are drawing your point in.

If you define your mega-X to be mX and your mega-Y to be mY, you can create some arbitrary equation like (pulling from your example:

((mX * mX + mY * mY + (int)Math.pow(mX * mY, 3)) % 64 == Z

What is Z? Z is the current point you are within the block If you look at the block as a subgrid. So the first point within the block is bX, bY

Going to go with a modulo of 67, it seems to have a reasonable distribution. After the superdivide by 8 I can see 1 diagonally adjacent super-cell and a handful of two-distant ones, but otherwise the average seems to be about 5 (works out to ~40 chunks or ~640 blocks).

Just curious, is there a reason you can't implement a PRNG with a fixed seed? That gives you a reproducible 'random' sequence. My_Rand(8, 40) for the distance, and My_Rand(0, 359) for the direction. As long as you don't change your hardcoded seed, the sequence should always be identical.