Hi! I am making a code for drawing a graph. I am receiving data(int) in an IntList form, and something is not going right.
It is supposed to get data like
- First, enter the title.
- Enter the number of rows.
- Then enter all of your data. (only one-digit numbers, no space, only the amount of rows that you entered in 2)
but in 3, it keeps printing strange numbers that keep changing. It is driving me crazy.
If you have some free time, please help me solve this problem. Or if you have an alternative for getting numbers, please advise me.
I need your help badly… The source code is on the bottom.
void setup(){
background(0);
size(1000, 1000);
textSize(30);
text("*GraphSaver Beta Instructions*\n\nPress the white button on the right top to end program.\n\n1.First enter the title.\n2.Then enter the number of rows.\n3.Then enter all of your data.\n4.A graph will be made.press enter to save and delete to erase it. \n\nWhen you finish reading click the screen.", 20, 30);
arr = new IntList();
}
int num=0;
String title = "";
IntList arr;
void draw(){
square(950, 0, 50);
textSize(30);
if(keynum==0)text(title, 100, 100);
if(keynum==1 && num != 0){
text(num-48, 100, 100);
}
/*
if(keynum==2){
for(int i = 0; i < arr.size(); i++){
arr.sub(i, 48);
text(arr.get(i), 100, 100);
}
}*/
int multi = 80;
int plus = 150;
}
}
void mousePressed(){//End process
background(0);
if(mouseX > 950 && mouseY < 50){
fill(200, 11, 22);
square(950, 0, 50);
delay(5000);
print("END");
}
}
void mouseMoved(){
if(mouseX > 950 && mouseY < 50){
fill(200, 11, 22);
square(950, 0, 50);
}
else {
fill(255);
square(950, 0, 50);
}
}
int imsi=0;//temp
int keynum=0;//how nany times key has been pressed-0:title, 1: number of rows, 2 : data
void keyPressed(){//input
background(0);
if(key == ENTER){keynum++;return;}
if(keynum == 0)title += key;
if(keynum == 1){
num = key;
}
if (keynum == 2) {
arr.append(key - 48);
imsi++;
println(arr);
}
}
plus, I will put this code together with the code below to make a whole program. Just in case the answering person wants it, I’ll post it together.
void setup(){
background(0);
size(4000, 4000);
textSize(30);
arr = new IntList();
arr.append(8);
arr.append(2);
arr.append(3);
arr.append(4);
arr.append(5);
arr.append(9);
arr.append(6);
arr.append(7);
arr.append(1);
}
int num=9;
String title = "Untitled #1";
IntList arr;
void draw(){
/* for(int i = 0; i < 3; i++){
print(" ", arr.get(i));
}
*/
int multi = 80;
int plus = 150;
textSize(50);
text(title, 250, 70);
textSize(30);
stroke(255);
line(100, 100, 100, arr.max()* multi + 50 + 100);
line(100, arr.max()* multi + 50 + 100, 100 + num * 120 + 150, arr.max()* multi + 50 + 100);
for(int i = 0; i < num; i++){
rect(plus, arr.max()* multi + 50 + 100 - arr.get(i) * 80, 100, arr.get(i) * 80);
fill(1);
text(arr.get(i), 40 + plus, arr.max()* multi + 100);
fill(255);
textSize(20);
text(i + 1, 40 + plus, arr.max()* multi + 190);
textSize(30);
plus += 150;
}
}