// ******************配列****************** int [] a = {2,3,5,7,9,4,8,1,6,0}; for(int i = 0; i< 10; i++){ println(a[i]); //下の黒画面にデータとして出力する関数です } // ******************テキスト版バブルソート****************** int [] a = {2,3,5,7,9,4,8,1,6,0}; for(int i = 0; i< 10; i++){ println(a[i]); } print("++++++++++++++++****\n"); for(int i = 0; i < a.length-1; 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; } } } for(int i = 0; i< 10; i++){ println(a[i]); } // ******************関数を使って5つの円を描く****************** void setup(){ size(600,200); noLoop(); } void draw(){ for(int i = 0; i < 5; i++){ drawcircle(i); } } void drawcircle(int i){ ellipse(100 + 100 * i, 100, 60, 60); } // ******************関数を使ったテキスト版バブルソート****************** int [] a = {2,3,5,7,9,4,8,1,6,0}; void setup(){ noLoop(); } void draw(){ for(int i = 0; i< 10; i++){ println(a[i]); } print("++++++++++++++++++++++\n"); for(int i = 0; i < a.length-1; i++){ bubble(i); //iラウンド目のバブルソートを行っています } for(int i = 0; i< 10; i++){ println(a[i]); } } 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つの電荷のつくる電場のシミュレーション****************** float Q1_f=50*20000,Q2_f=-25*20000; void setup(){ size(800,800); noLoop(); } void draw(){ float x,y; float r1,r2; //arrow(10,200,30,40); fill(255,255,0); ellipse(280, 400, 15, 15); ellipse(520, 400, 15, 15); line(0,400,800,400); line(400,0,400,800); for(int i = 0; i < 20; i++){ for(int j = 0; j < 20; j++){ if((40*i == 280 && 40*j == 400) || (40*i == 520 && 40*j == 400)) continue; r1 = sqrt((float)(pow((40*i-280),2)+pow((40*j-400),2))); r2 = sqrt((float)(pow((40*i-520),2)+pow((40*j-400),2))); x = Q1_f*((float)(40*i-280)/(r1*r1*r1)) + Q2_f*((float)(40*i-520)/(r2*r2*r2)); y = Q1_f*((float)(40*j-400)/(r1*r1*r1)) + Q2_f*((float)(40*j-400)/(r2*r2*r2)); //println(x,y); if(x*x+y*y>35*35){ x = 35*x/sqrt(x*x+y*y); y = 35*y/sqrt(x*x+y*y); } arrow(40*i,40*j,(int)(40*i+x),(int)(40*j+y)); } } } void arrow(int x1, int y1, int x2, int y2) { stroke(255,0,0); line(x1, y1, x2, y2); pushMatrix(); translate(x2, y2); float a = atan2(x1-x2, y2-y1); rotate(a); line(0, 0, -5, -5); line(0, 0, 5, -5); popMatrix(); }