BUBBLE
泡泡位置
照片:
程式碼:
int []a=new int[10];//Java's Array
//int []a={6,3,5,9,1,0,4,2,7,8};
//int []a={1,2,3,5,0,4,6,7,8,9};
//int []a={9,8,7,6,5,4,3,2,1,0};
void setup() {
size(500, 800);
for (int i=0; i<10; i++) {//random choose number
a[i]=int(random(10));//亂數決定數字
}
textSize(36);
textAlign(LEFT, TOP);
showArray(y);
}
int y=0;
void showArray(int y) {
for (int i=0; i<10; i++) {
fill(255);
rect(i*50, y, 50, 50);
fill(0);
text(a[i], i*50, y);
}//秀文字
}
void draw() {
}
void mousePressed() {
for (int i=0; i<10-1; i++) {//i從左到右 0 1 2 3 ... 8
if (a[i] > a[i+1]) {
int temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
fill(255, 0, 0, 128);
rect(i*50, y, 100, 50);
}//R紅G綠B藍A半透明Alpha
}
y+=50;
showArray(y);
}
//int []a={6,3,5,9,1,0,4,2,7,8};
//int []a={1,2,3,5,0,4,6,7,8,9};
//int []a={9,8,7,6,5,4,3,2,1,0};
void setup() {
size(500, 800);
for (int i=0; i<10; i++) {//random choose number
a[i]=int(random(10));//亂數決定數字
}
textSize(36);
textAlign(LEFT, TOP);
showArray(y);
}
int y=0;
void showArray(int y) {
for (int i=0; i<10; i++) {
fill(255);
rect(i*50, y, 50, 50);
fill(0);
text(a[i], i*50, y);
}//秀文字
}
void draw() {
}
void mousePressed() {
for (int i=0; i<10-1; i++) {//i從左到右 0 1 2 3 ... 8
if (a[i] > a[i+1]) {
int temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
fill(255, 0, 0, 128);
rect(i*50, y, 100, 50);
}//R紅G綠B藍A半透明Alpha
}
y+=50;
showArray(y);
}
-----------------------------------------------------------------------
Bubble位置及顏色變化
程式碼:
void setup() {//Lyto Different Color
size(300, 500);//下面300x300
colorMode(HSB);
}//300x300 分成 2x2, 每個圓 300/2
int ansX=2, ansY=3;
int N=5;//單邊有幾個大圓?
int H=255, S=255, B=255;//Hus色相/色調, Sat飽, Bright高度
void draw() {
background(0);///300x300 分成 2x2, 每個圓 300/2
int R=300/N, w=R/2;
for (int x=0; x<N; x++) {
for (int y=0; y<N; y++) {
if(x==ansX && y==ansY) fill(H+10, S-35, B-45);
else fill(H, S, B);
ellipse(0+w+x*R, 200+w+y*R, R, R);
}
}
}
void mousePressed(){
ansX = int(random(N)); ansY = int(random(N));
H+=16;
if(H>255)H=0;
}

沒有留言:
張貼留言