Advertisement
S0lll0s

Processing Sort Tester

Aug 2nd, 2013
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. int num = 500;
  2. int step = 500;
  3.  
  4. int[] values = new int[ num ];
  5. int left = 0;
  6.  
  7. void setup() {
  8.   size( num, num );
  9.   for ( int i = 0; i < num; i++ )
  10.     values[i] = 0;
  11.    
  12.   for ( int i = 0; i < num; i++ ) {
  13.     int r = int( random( 0, num ) );
  14.     if ( values[r] == 0 ) {
  15.       values[r] = i;
  16.     } else {
  17.       i--;
  18.       continue;
  19.     }
  20.   }
  21. }
  22.  
  23. void draw() {
  24.   background( 180 );
  25.  
  26.   for ( int i = 0; i < num; i++ )
  27.     point( i, values[i] );
  28.    
  29.   if ( left > 0 ) {
  30.     sortOnce();
  31.     left--;
  32.   }
  33. }
  34.  
  35. void sortOnce() {
  36.   int x = 0;
  37.   while ( true ) {
  38.     if ( values[x] < values[x+1] ) {
  39.       x++;
  40.       if ( x == num )
  41.         break;
  42.       continue;
  43.     }
  44.     int t = values[x+1];
  45.     values[x+1] = values[x];
  46.     values[x] = t;
  47.     break;
  48.   }
  49.   // sort values one step
  50. }
  51.  
  52. void keyPressed() {
  53.   if ( key == ' ' ) {
  54.     left += step;
  55.   }
  56.   if ( key == 's' ) {
  57.     saveFrame("pic####.png");
  58.   }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement