Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int count = 1000;
- boolean showVals = false;
- boolean hideFrames = true;
- Line[] lines = new Line[count];
- float stWg;
- final double decrFact = 1.247330950103979;
- double gapDivider = decrFact;
- boolean notShuffled = true;
- boolean notSorted = false;
- boolean notFinished = false;
- int iShuf=0;
- int gap=count;
- int randpos;
- int k=0;
- int framesHidden=1;
- void setup() {
- size(1500, 200);
- background(0);
- colorMode(HSB);
- fill(0);
- //frameRate(1);
- stWg=(width)/count+2;
- strokeWeight(stWg);
- int index=0;
- for (int i=0; i<count; i++) {
- lines[index] = new Line();
- lines[index].pos = i;
- lines[index].val = i;
- lines[index++].display();
- }
- }
- void draw() {
- if (hideFrames) {
- framesHidden=round(frameRate)/2+1;
- }
- for (int ind=0; ind<framesHidden; ind++) {
- if (notShuffled) {
- randpos = round(random(count-1));
- lines[iShuf].swap(lines[randpos]);
- iShuf++;
- if (iShuf>=count) {
- notShuffled=false;
- notSorted=true;
- }
- }
- if (notSorted) {
- if (k+gap<count) {
- if (lines[k].val>lines[k+gap].val) {
- lines[k].swap(lines[k+gap]);
- }
- k++;
- } else {
- k=0;
- gap/=gapDivider;
- //println(gap);
- }
- if (gap==0) {
- notSorted=false;
- notFinished=true;
- }
- }
- for (Line it : lines) {
- it.display();
- if (notShuffled) {
- if (it.val==iShuf) {
- it.display(0);
- }
- if (it.val==randpos) {
- it.display(64);
- }
- }
- if (notSorted) {
- if (it.pos==k) {
- it.display(0);
- }
- if (it.pos==k+gap) {
- it.display(64);
- }
- }
- }
- }
- }
- class Line {
- int pos;
- int val;
- void display() {
- float H=map(val, 0, count, 0, 255);
- stroke(H, 255, 255);
- H = map(pos, 0, count, stWg/2, width+stWg/2);
- line(H, 0, H, height);
- if (showVals) {
- fill(0);
- textSize(stWg*3/5);
- text(val, H-stWg/2, (height+stWg/3)/2);
- }
- }
- void display(float col) {
- stroke(col);
- strokeWeight(frameRate*stWg);
- float H = map(pos, 0, count, stWg/2, width+stWg/2);
- line(H, 0, H, height);
- strokeWeight(stWg);
- if (showVals) {
- float N=map(val, 0, count, 0, 255);
- fill(N, 255, 255);
- textSize(stWg*3/5);
- text(val, H-stWg/2, (height+stWg/3)/2);
- }
- }
- void swap(Line drug) {
- int temp = drug.val;
- drug.val = val;
- val = temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement