Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slider value is not int anymore #24

Closed
suyuren opened this issue Sep 29, 2015 · 1 comment
Closed

Slider value is not int anymore #24

suyuren opened this issue Sep 29, 2015 · 1 comment

Comments

@suyuren
Copy link

suyuren commented Sep 29, 2015

I had created my project using controlp5's slider and it worked until May 2015. I opened it September 2015 and my slider doesn't work anymore. I figured it out it is because the value of the slider, year , is float but integer now.

I'm not sure why it happened. Maybe software update? I'm sure the code was working before because I made a video at the time.

Does anyone know how I can fix it?

Here is my code

import controlP5.*;
ControlP5 cp5;
int year = 1990;
String [][] csvIco;
String [][] csvGrower;
int csvIcoWidth=0, csvGrowerWidth=0;
PShape mapImg, beanImg;
PFont font1, font2;

void setup() {
size(1000, 800);
font1 = loadFont("Akkurat-12.vlw");
font2 = loadFont("Akkurat-48.vlw");
cp5 = new ControlP5(this);
cp5.addSlider("year")
.setRange(1990, 2009)
.setPosition(30, 200)
.setSize(5, 450)
.setColorValue(color(89, 5, 220))
.setColorActive(color(89, 5, 220))
.setColorForeground(color(89, 5, 220))
.setColorBackground(color(1, 239, 224))
.setColorLabel(color(1, 239, 224))
;
String linesIco[] = loadStrings("dataIcoPrice.csv");
String linesGrower[] = loadStrings("dataGrowerPrice.csv");
//calculate max width of csv file
for (int i=0; i < linesIco.length; i++) {
String [] chars=split(linesIco[i], ',');
if (chars.length>csvIcoWidth) {
csvIcoWidth=chars.length;
}
}

//create csv array based on # of rows and columns in csv file
csvIco = new String [linesIco.length][csvIcoWidth];

//parse values into 2d array
for (int i=0; i < linesIco.length; i++) {
String [] temp = new String [linesIco.length];
temp= split(linesIco[i], ',');
for (int j=0; j < temp.length; j++) {
csvIco[i][j]=temp[j];
}
}

for (int i=0; i < linesGrower.length; i++) {
String [] chars=split(linesGrower[i], ',');
if (chars.length>csvGrowerWidth) {
csvGrowerWidth=chars.length;
}
}

//create csv array based on # of rows and columns in csv file
csvGrower = new String [linesGrower.length][csvGrowerWidth];

//parse values into 2d array
for (int i=0; i < linesGrower.length; i++) {
String [] temp = new String [linesGrower.length];
temp= split(linesGrower[i], ',');
for (int j=0; j < temp.length; j++) {
csvGrower[i][j]=temp[j];
}
}
}

void draw() {
background(20);
textFont(font2);
textSize(21);
fill(1, 239, 224, 180);
text("Coffee Trading Price 1990-2009", 10, 20, 300, 200);
textFont(font1);
stroke(1, 239, 224, 120);
strokeWeight(2);
noFill();
ellipse(width/2, height/2, 400, 400);
text("$1", width/2-6, 195);
fill(3, 208, 147, 180);
beanImg = loadShape("bean.svg");
beanImg.disableStyle();
shape(beanImg, 10, 140, 15, 15);
text(csvGrower[7][0], 30, 152 );
fill(89, 5, 220, 180);
shape(beanImg, 10, 120, 15, 15);
text(csvGrower[12][0], 30, 132 );
fill(8, 148, 255, 180);
shape(beanImg, 10, 100, 15, 15);
text(csvGrower[36][0], 30, 112 );
fill(144, 0, 246, 180);
shape(beanImg, 10, 80, 15, 15);
text(csvGrower[42][0], 30, 92);
if (dist(mouseX, mouseY, width/2, height/2)<=400) {
coffeeName(year);
} else {
coffeeData(year);
}
fill(1, 239, 224, 180);
textFont(font2);
textSize(18);
text("Indicator Price", 30, 750);
textSize(12);
text("International Coffee Organization", 30, 770);
if ((mouseX>30)&&(mouseX<300)&&(mouseY>750)&&(mouseX<770)) {
float rIco = Float.parseFloat(csvIco[year-1989][5]);
fill(1, 239, 224, 20);
ellipse(width/2, height/2, 4_rIco, 4_rIco);
}
}

void coffeeData(int year) {
for (int i=1; i < 4; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
fill(3, 208, 147, 180);
rotate(-(i+1)_PI/30);
float r = Float.parseFloat(csvGrower[7+i][year-1988]);
arc(0, 0, 4_r, 4*r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[7+i][0] + ".svg");
shape(mapImg, 350, 0, 15, 15);
popMatrix();
}

for (int i=1; i < 20; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
fill(89, 5, 220, 180);
rotate((i-1)_PI/30);
float r = Float.parseFloat(csvGrower[12+i][year-1988]);
arc(0, 0, 4_r, 4*r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[12+i][0] + ".svg");
shape(mapImg, 350, 0, 15, 15);
popMatrix();
}

for (int i=1; i < 5; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
//fill(1, 239, 224, 180);
fill(8, 148, 255, 180);
rotate(20_PI/30+(i-1)_PI/30);
float r = Float.parseFloat(csvGrower[36+i][year-1988]);
arc(0, 0, 4_r, 4_r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[36+i][0] + ".svg");
mapImg.disableStyle();
shape(mapImg, 350, 0, 15, 15);
popMatrix();
}

for (int i=1; i < 15; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
fill(144, 0, 246, 180);
rotate(25_PI/30+(i-1)_PI/30);
float r = Float.parseFloat(csvGrower[42+i][year-1988]);
arc(0, 0, 4_r, 4_r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[42+i][0] + ".svg");
mapImg.disableStyle();
shape(mapImg, 350, 0, 15, 15);
popMatrix();
}
}

void coffeeName(int year) {
for (int i=1; i < 4; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
fill(3, 208, 147, 120);
rotate(-(i+1)_PI/30);
float r = Float.parseFloat(csvGrower[7+i][year-1988]);
arc(0, 0, 4_r, 4*r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[7+i][0] + ".svg");
fill(3, 208, 147, 180);
shape(mapImg, 250, 0, 15, 15);
text(csvGrower[7+i][0], 280, 10);
popMatrix();
}

for (int i=1; i < 20; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
fill(89, 5, 220, 120);
rotate((i-1)_PI/30);
float r = Float.parseFloat(csvGrower[12+i][year-1988]);
arc(0, 0, 4_r, 4*r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[12+i][0] + ".svg");
fill(89, 5, 220, 180);
shape(mapImg, 250, 0, 15, 15);
text(csvGrower[12+i][0], 280, 10);
popMatrix();
}

for (int i=1; i < 5; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
//fill(1, 239, 224, 180);
fill(8, 148, 255, 120);
rotate(20_PI/30+(i-1)_PI/30);
float r = Float.parseFloat(csvGrower[36+i][year-1988]);
arc(0, 0, 4_r, 4_r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[36+i][0] + ".svg");
mapImg.disableStyle();
fill(8, 148, 255, 180);
shape(mapImg, 250, 0, 15, 15);
text(csvGrower[36+i][0], 280, 10);
popMatrix();
}

for (int i=1; i < 15; i++) {
pushMatrix();
translate(width/2, height/2);
noStroke();
fill(144, 0, 246, 120);
rotate(25_PI/30+(i-1)_PI/30);
float r = Float.parseFloat(csvGrower[42+i][year-1988]);
arc(0, 0, 4_r, 4_r, 0, PI/100, PIE);
mapImg = loadShape(csvGrower[42+i][0] + ".svg");
mapImg.disableStyle();
fill(144, 0, 246, 180);
shape(mapImg, 250, 0, 15, 15);
text(csvGrower[42+i][0], 280, 10);
popMatrix();
}
}

@sojamo
Copy link
Owner

sojamo commented Sep 29, 2015

Hi, there is indeed an issue with the variable using the name year, I haven't checked but I assume current versions of PApplet are making internal use of a variable with name year hence there is a conflict and no response from the slider. If you rename variable year to for example yearValue, the slider responds as expected.

just a side note: the code you posted is very long and depends on external files and data. To identify the issue here is not very straight forward and one has to read through a lot of code that is not relevant to the problem. a workaround here is to create a minimal, complete and verifiable example (mcve)

@sojamo sojamo closed this as completed Oct 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants