当方プログラム初心者の学生です。
現在prosessingを用いてプログラムの勉強をしているのですが、ボタン等を作成し
import controlP5.*;
ControlP5 cp5;
String filenameA = null;
String filenameB = null;
void setup(){
size(300,200);
cp5 = new ControlP5(this);
cp5.addButton("100")
.setLabel("100")
.setPosition(50,50)
.setSize(60,30);
cp5.addButton("1000")
.setLabel("1000")
.setPosition(120,50)
.setSize(60,30);
cp5.addButton("exit")
.setLabel("exit")
.setPosition(50,90)
.setSize(130,30);
}
void draw(){
}
のような感じでボタンを作ればいいのはわかるのですが、文字の表示だけでなく、そこからプログラムの切り替えようとするとやり方がわかりません
2つのプログラムは
/bubble100/
int a[]= new int[100];
color []b = new color [500];
int count=0;
void setup(){
size(700,300);
frameRate(30);
set_data();
set_color();
}
void draw(){
int j;
bubble(count);
background(255);
for(j=0;j<a.length;j++){
fill(b[a[j]]);
noStroke();
rect(30+5*j,300-a[j],5,a[j]);
}
count++;
if(count==a.length){
set_data();
count=0;
}
}
void bubble(int i){
int j, tmp;
for(j=a.length-2;j>=i;j--){
if(a[j+1]<a[j]){
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
}
}
void set_data(){
int i;
for(i=0;i<a.length;i++){
a[i]= (int)random(300);
}
}
void set_color(){
int i;
for(i=0;i<500;i++){
b[i]=color((int)random(255),(int)random(255),(int)random(255));
}
}
と
/bubble1000/
int a[]= new int[1000];
color []b = new color [600];
int count=0;
void setup(){
size(1000,300);
frameRate(200);
set_data();
set_color();
}
void draw(){
int j;
bubble(count);
background(255);
//stroke(random(255),random(255),random(255));
for(j=0;j<a.length;j++){
stroke(b[a[j]]);
line(30+j,300,30+j,300-a[j]/2);
}
count++;
if(count==a.length){
set_data();
count=0;
}
}
void bubble(int i){
int j, tmp;
for(j=a.length-2;j>=i;j--){
if(a[j+1]<a[j]){
tmp=a[j];
a[j]=a[j+1];
a[j+1]=tmp;
}
}
}
void set_data(){
int i;
for(i=0;i<a.length;i++){
a[i]= (int)random(600);
}
}
void set_color(){
int i;
for(i=0;i<600;i++){
b[i]=color((int)random(255),(int)random(255),(int)random(255));
}
}
です
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/10 05:23
2019/07/10 05:47
2019/07/10 12:48
2019/07/12 08:23