// ******************ウインドウ表示版バブルソート****************** int [] a = {2,3,5,7,9,4,8,1,6,0}; int count = 0; //何ラウンド目かをカウント void setup() { size(250, 250); frameRate(1); //1秒間に1回表示する } void draw() { bubble(count); background(255); fill(0); // character color for (int j = 0; j < a.length; j++) { text(a[j], 30+20*j, height/2); } count++; } void bubble(int i){ for (int j = a.length-2; j>=i; j--) { if(a[j+1] < a[j]){ int tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp; } } } // ******************ウインドウ表示版バブルソート(2)****************** int [] a = new int [10]; color [] b = new color [20]; int count = 0; void setup() { size(250, 250); frameRate(1); set_data(); set_color(); //background(255); } void draw() { bubble(count); background(255); for (int j = 0; j < a.length; j++) { fill(b[a[j]]); rect(30+20*j,220-10*a[j],20,a[j]*10); } count++; print(count); if(count==a.length){ set_data(); count = 0; } } void bubble(int i){ for (int j = a.length-2; j>=i; j--) { if(a[j+1] < a[j]){ int tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp; } } } void set_data(){ for(int i = 0; i < a.length; i++){ a[i] = (int)random(20); } } void set_color(){ for(int i = 0; i < 20; i++){ b[i] = color((int)random(255),(int)random(255),(int)random(255)); } }