Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int num = 500;
- int step = 500;
- int[] values = new int[ num ];
- int left = 0;
- void setup() {
- size( num, num );
- for ( int i = 0; i < num; i++ )
- values[i] = 0;
- for ( int i = 0; i < num; i++ ) {
- int r = int( random( 0, num ) );
- if ( values[r] == 0 ) {
- values[r] = i;
- } else {
- i--;
- continue;
- }
- }
- }
- void draw() {
- background( 180 );
- for ( int i = 0; i < num; i++ )
- point( i, values[i] );
- if ( left > 0 ) {
- sortOnce();
- left--;
- }
- }
- void sortOnce() {
- int x = 0;
- while ( true ) {
- if ( values[x] < values[x+1] ) {
- x++;
- if ( x == num )
- break;
- continue;
- }
- int t = values[x+1];
- values[x+1] = values[x];
- values[x] = t;
- break;
- }
- // sort values one step
- }
- void keyPressed() {
- if ( key == ' ' ) {
- left += step;
- }
- if ( key == 's' ) {
- saveFrame("pic####.png");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement