Please Help!?!!!!!!!!
in
Programming Questions
•
1 year ago
This is based on the Brownian example. The code works the way I want except for one thing. I want the color of the line to change according to the different "strength" of the values in the range array. Higher values giving red lines and lower values giving blue lines with green as a middle value. Right now it draws as a green line with a blue tail. I'm confused by this and not sure how to get it to what i want.
int num = 648;
float[] range = {9.8,10.3,11.0,10.4,9.0,8.3,7.8,7.4,7.8,8.1,9.2,9.3};
float[] ax = new float[num];
float[] ay = new float[num];
void setup()
{
size(640, 360);
for(int i= 0; i < num; i++) {
ax[i] = width/2;
ay[i] = height/2;
}
frameRate(60);
}
void draw()
{
background(255);
// Shift all elements 1 place to the left
for(int i = 1; i < num; i++) {
ax[i-1] = ax[i];
ay[i-1] = ay[i];
}
// Put a new value at the end of the array
for (int i=0;i<range.length;i++){
float x=range[i];
float value =random(-x,x);
if(value !=x || value!=-x){
loop();
}
ax[num-1]+=value;
ay[num-1]+=value;
}
// Constrain all points to the screen
ax[num-1] = constrain(ax[num-1], 0, width);
ay[num-1] = constrain(ay[num-1], 0, height);
// Draw a line connecting the points
int c=0;
for(int i=1; i<num; i++) {
for(int v=0; range[c]>7 && range[c]<9 && v<1;v++){
stroke(255,0,0);
c++;
break;
}for(int v=0;range[c]>9 && range[c]<10.5 && v<1;v++){
stroke(0,255,0);
c++;
break;
}for(int v=0; range[c]>10.5 && range[c]<12 && v<1;v++){
stroke(0,0,255);
c++;
break;
}
strokeWeight(5);
line(ax[i-1], ay[i-1], ax[i], ay[i]);
}
}
int num = 648;
float[] range = {9.8,10.3,11.0,10.4,9.0,8.3,7.8,7.4,7.8,8.1,9.2,9.3};
float[] ax = new float[num];
float[] ay = new float[num];
void setup()
{
size(640, 360);
for(int i= 0; i < num; i++) {
ax[i] = width/2;
ay[i] = height/2;
}
frameRate(60);
}
void draw()
{
background(255);
// Shift all elements 1 place to the left
for(int i = 1; i < num; i++) {
ax[i-1] = ax[i];
ay[i-1] = ay[i];
}
// Put a new value at the end of the array
for (int i=0;i<range.length;i++){
float x=range[i];
float value =random(-x,x);
if(value !=x || value!=-x){
loop();
}
ax[num-1]+=value;
ay[num-1]+=value;
}
// Constrain all points to the screen
ax[num-1] = constrain(ax[num-1], 0, width);
ay[num-1] = constrain(ay[num-1], 0, height);
// Draw a line connecting the points
int c=0;
for(int i=1; i<num; i++) {
for(int v=0; range[c]>7 && range[c]<9 && v<1;v++){
stroke(255,0,0);
c++;
break;
}for(int v=0;range[c]>9 && range[c]<10.5 && v<1;v++){
stroke(0,255,0);
c++;
break;
}for(int v=0; range[c]>10.5 && range[c]<12 && v<1;v++){
stroke(0,0,255);
c++;
break;
}
strokeWeight(5);
line(ax[i-1], ay[i-1], ax[i], ay[i]);
}
}
1