Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created March 2, 2015 11:44
Show Gist options
  • Save keijiro/180cb6f42e4f799d8444 to your computer and use it in GitHub Desktop.
Save keijiro/180cb6f42e4f799d8444 to your computer and use it in GitHub Desktop.
Shows a pseudorandom number sequence and the 2,3 Halton sequence.
int box_size = 256;
float Halton(int i, int base)
{
float x = 1.0f / base;
float v = 0.0f;
while (i > 0)
{
v += x * (i % base);
i = floor(i / base);
x /= base;
}
return v;
}
void setup()
{
size(box_size * 2 + 16, box_size + 20);
background(100);
noStroke();
}
void draw()
{
if (frameCount > 200) return;
fill(255);
for (int i = frameCount * 10; i < (frameCount + 1) * 10; i++)
{
ellipse(random(box_size), random(box_size), 4, 4);
ellipse(Halton(i, 2) * box_size + box_size + 16, Halton(i, 3) * box_size, 4, 4);
}
fill(0);
rect(box_size, 0, 16, box_size);
rect(0, box_size, width, 20);
fill(255);
textSize(14);
text("random()", 2, height - 5);
text("Halton Sequence", box_size + 16 + 2, height - 5);
// saveFrame();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment