Advertisement
ffpaladin

Buggy Processing Visual Sort for processing.js

Jul 22nd, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. // Buggy Sorting Code - for Processing.js
  2.  
  3. // defining the array
  4.  
  5. int cheesesticks [] = {21, 33, 44, 22 ,55 ,66 ,77, 33, 22, 11, 44, 33, 22, 11, 55 ,66, 5, 2, 100, 20};
  6.  
  7. // counters
  8. int i = -1;
  9. int j = 0;
  10.  
  11. // storing the minimum
  12. int min;
  13.  
  14.  
  15. // setup runs once
  16. void setup () {
  17.  
  18.   size (800,800);
  19.  
  20.   for (int k=0; k<20; k++)
  21.     println(cheesesticks[i]);
  22. }
  23.  
  24. // runs foreverrrrr! (not really)
  25.  
  26. void draw () {
  27.  
  28.   background(0);
  29.  
  30.   // only runs after j reaches 20  
  31.   if ((j == 20) && (i < 19)) {
  32.  
  33.      i++;
  34.      j=i+1;
  35.      min = cheesesticks[i];
  36.   }
  37.  
  38.   // runs as long as j is less than 20
  39.   if (j < 20) {
  40.  
  41.     if (cheesesticks[j] < min){
  42.       min = cheesesticks[j];
  43.       int temp = cheesesticks[i];
  44.       cheesesticks[i] = cheesesticks[j];
  45.       cheesesticks[j] = temp;
  46.     }
  47.     j++;
  48.   }
  49.  
  50.  
  51.   // Draws the state of the cheesesticks  
  52.   fill (0,0,255);
  53.  
  54.   for (int l=0; l<20; l++)
  55.   {
  56.     rect(0, l*20, cheesesticks[l]*5, 10);
  57.   }
  58.  
  59.   println("poop");
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement