Here's the code; very sloppy and lazy!
PFont f;
Card[] a;
int numcards = 20;
void setup(){
size(650, 400);
rectMode(CENTER);
f = createFont("Arial",16,true);
textFont(f);
a = new Card[numcards];
for(int i = 0; i < numcards; i++){
a[i] = new Card(i*30 + 15, 60, i+1);
}
}
void draw(){
for(int i = 0; i < numcards; i++){
a[i].update();
}
selectionSort();
}
void selectionSort(){
for(int i = 0; i < numcards; i++){
int m = 0;
int j;
for(j = i; j < numcards; j++){
if(a[j].num > a[m].num){
m = i;
}
}
switchcards(i, j);
}
}
void switchcards(int i, int j){
Card a = new Card(a[i]);
Card b = new Card(a[j]);
for(int k = a.y; k <= a.y + 200; k++){
a.y = k;
b.y = k;
}
int w = a.x;
int v = b.x;
boolean usefulvariable = false;
if(w > v){
usefulvariable = true;
}
for(int k = 0; k <= abs(w-v); k++){
if(usefulvariable){
a.x = w - k;
b.x = v + k;
}else{
a.x = w + k;
b.x = v - k;
}
}
a[i] = b;
a[j] = a;
}
class Card{
int x;
int y;
int num;
Card(int num_){
num = num_;
}
Card(int x_, int y_, int num_){
x = x_;
y = y_;
num = num_;
}
Card(Card c){
this.x = c.x;
this.y = c.y;
this.num = c.num;
}
void update(){
fill(255, 180, 60);
stroke(0);
rect(x, y, 28, 50);
fill(0);
text("" + num, x-10, y);
}
}