Advertisement
A-Sin

Untitled

Jan 16th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. int count = 1000;
  2. boolean showVals = false;
  3. boolean hideFrames = true;
  4.  
  5.  
  6. Line[] lines = new Line[count];
  7. float stWg;
  8. final double decrFact = 1.247330950103979;
  9. double gapDivider = decrFact;
  10. boolean notShuffled = true;
  11. boolean notSorted = false;
  12. boolean notFinished = false;
  13.  
  14. int iShuf=0;
  15. int gap=count;
  16. int randpos;
  17. int k=0;
  18. int framesHidden=1;
  19.  
  20. void setup() {
  21.   size(1500, 200);
  22.   background(0);
  23.   colorMode(HSB);
  24.   fill(0);
  25.   //frameRate(1);
  26.   stWg=(width)/count+2;
  27.   strokeWeight(stWg);
  28.  
  29.   int index=0;
  30.   for (int i=0; i<count; i++) {
  31.     lines[index] = new Line();
  32.     lines[index].pos = i;
  33.     lines[index].val = i;
  34.     lines[index++].display();
  35.   }
  36. }
  37.  
  38. void draw() {
  39.   if (hideFrames) {
  40.     framesHidden=round(frameRate)/2+1;
  41.   }
  42.   for (int ind=0; ind<framesHidden; ind++) {  
  43.     if (notShuffled) {    
  44.       randpos = round(random(count-1));
  45.       lines[iShuf].swap(lines[randpos]);      
  46.       iShuf++;
  47.       if (iShuf>=count) {
  48.         notShuffled=false;
  49.         notSorted=true;
  50.       }
  51.     }
  52.     if (notSorted) {
  53.       if (k+gap<count) {
  54.         if (lines[k].val>lines[k+gap].val) {            
  55.           lines[k].swap(lines[k+gap]);
  56.         }          
  57.         k++;
  58.       } else {
  59.         k=0;
  60.         gap/=gapDivider;
  61.         //println(gap);
  62.       }
  63.       if (gap==0) {
  64.         notSorted=false;
  65.         notFinished=true;
  66.       }
  67.     }
  68.  
  69.     for (Line it : lines) {
  70.       it.display();
  71.       if (notShuffled) {
  72.         if (it.val==iShuf) {
  73.           it.display(0);
  74.         }
  75.         if (it.val==randpos) {
  76.           it.display(64);
  77.         }
  78.       }
  79.       if (notSorted) {
  80.         if (it.pos==k) {
  81.           it.display(0);
  82.         }
  83.         if (it.pos==k+gap) {
  84.           it.display(64);
  85.         }
  86.       }
  87.     }
  88.   }
  89. }
  90. class Line {
  91.   int pos;
  92.   int val;
  93.  
  94.   void display() {
  95.     float H=map(val, 0, count, 0, 255);
  96.     stroke(H, 255, 255);    
  97.     H = map(pos, 0, count, stWg/2, width+stWg/2);
  98.     line(H, 0, H, height);
  99.     if (showVals) {
  100.       fill(0);
  101.       textSize(stWg*3/5);
  102.       text(val, H-stWg/2, (height+stWg/3)/2);
  103.     }
  104.   }
  105.   void display(float col) {
  106.     stroke(col);
  107.     strokeWeight(frameRate*stWg);
  108.     float H = map(pos, 0, count, stWg/2, width+stWg/2);
  109.     line(H, 0, H, height);
  110.     strokeWeight(stWg);
  111.     if (showVals) {
  112.       float N=map(val, 0, count, 0, 255);
  113.       fill(N, 255, 255);
  114.       textSize(stWg*3/5);
  115.       text(val, H-stWg/2, (height+stWg/3)/2);
  116.     }
  117.   }
  118.   void swap(Line drug) {
  119.     int temp = drug.val;
  120.     drug.val = val;
  121.     val = temp;
  122.   }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement