Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Generates a list of width * height integers in order, shuffles the list,
- then iterates through the list to fill in all x,y positions on the screen
- "randomly" without having to track which points have already been filled.
- Will be useful technique for selecting "random" points from pixel arrays.
- To do:
- - Draw more than one point per frame.
- - Reset the list when screen filled and repeat.
- - "Zoom in", reduce list dimensions and use rect() instead of point() to
- draw "points" on the screen.
- */
- // Dimensions of the list.
- int w = 20;
- int h = 20;
- // Quick lookup for total size of list.
- int list_size = w*h;
- // "Screen muliplier"
- int sm = 20;
- // List index incrementor.
- int inc = 0;
- // Mini-loop (e.g. five at a time) incrementor.
- // Careful this mini-loop doesn't case an array out of bounds error.
- int miniloop = 20;
- // Quick lookup for total colour range.
- int hue_max = 6;
- // Color incrementor.
- int hue = 0;
- // Placeholder for current x, y and list index in the loop.
- int x, y, index;
- // List of integers.
- IntList pos;
- void settings() {
- size(w * sm, h * sm);
- noSmooth();
- }
- void setup() {
- // Create, fill and shuffle the contents of the list of integers.
- fillList();
- noStroke();
- frameRate(60);
- colorMode(HSB,hue_max);
- background(0,3,6);
- hue++;
- incFill();
- }
- void draw() {
- // If we've interated through the list, handle it.
- if (inc >= list_size) {
- inc = 0;
- fillList();
- incFill();
- }
- // X at a time to speed things up.
- for (int i=0; i < miniloop; i++) {
- // Offsets!
- // Get current index's value from the list.
- index = pos.get(inc);
- // Extract the x position.
- x = index % w;
- // Extract the y position.
- y = int(index / w);
- // Draw the "point", multiplied to "zoom in" on the screen.
- rect(x * sm, y * sm, sm, sm);
- // Increment the current index.
- inc++;
- }
- //saveFrame("frames/randomrgb-####.tga");
- if (frameCount >= 120) {
- exit();
- }
- }
- void fillList() {
- pos = new IntList();
- for (int i=0; i < list_size; i++) {pos.append(i);}
- pos.shuffle();
- pos.shuffle();
- }
- void incFill() {
- // If we've interated through the hue list, restart it.
- if (hue >= hue_max) {
- hue = 0;
- }
- fill(hue,3,6);
- hue++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement