add graph
This commit is contained in:
parent
5d7d8371f9
commit
b09631435b
|
@ -253,9 +253,9 @@ public class Tacho extends Visualization {
|
|||
|
||||
public class Direction extends Visualization {
|
||||
int size;
|
||||
float angleoffset=0;
|
||||
|
||||
|
||||
public Direction(int px, int py, int psize,float pvmin, float pvmax, float pvlmin, float pvlmax) {
|
||||
public Direction(int px, int py, int psize,float pvmin, float pvmax, float pvlmin, float pvlmax, float pangleoffset) {
|
||||
super.valueMin=pvmin;
|
||||
super.valueMax=pvmax;
|
||||
super.posOrigin= new PVector(px,py); //center
|
||||
|
@ -263,6 +263,8 @@ public class Direction extends Visualization {
|
|||
|
||||
super.value2Min=pvlmin;
|
||||
super.value2Max=pvlmax;
|
||||
|
||||
this.angleoffset=pangleoffset;
|
||||
}
|
||||
|
||||
|
||||
|
@ -276,7 +278,7 @@ public class Direction extends Visualization {
|
|||
ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size);
|
||||
|
||||
stroke(super.cmain);
|
||||
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI);
|
||||
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI)+this.angleoffset;
|
||||
float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min));
|
||||
line(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize);
|
||||
|
||||
|
@ -285,9 +287,9 @@ public class Direction extends Visualization {
|
|||
|
||||
//text
|
||||
fill(super.ctext);
|
||||
text("d="+super.getFormattedValue(super.value),super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3);
|
||||
text(super.getFormattedValue(super.value),super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3);
|
||||
if (super.value2<super.value2Max){ //display only if in use
|
||||
text("l="+super.getFormattedValue(super.value2),super.posOrigin.x-super.getFormattedValue(super.value2).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3+super.textsize);
|
||||
text("l="+super.getFormattedValue(super.value2),super.posOrigin.x-("l="+super.getFormattedValue(super.value2)).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3+super.textsize);
|
||||
}
|
||||
|
||||
//Title
|
||||
|
@ -295,3 +297,94 @@ public class Direction extends Visualization {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public class GraphRoll extends Visualization {
|
||||
PVector size;
|
||||
float[] valuearray;
|
||||
float[] valueMinarray;
|
||||
float[] valueMaxarray;
|
||||
int arraypos;
|
||||
int recordevery=1; //minimum value =1, the higher the slower
|
||||
int recordevery_counter=0;
|
||||
|
||||
public GraphRoll(int px, int py, int psx, int psy,float pvmin, float pvmax,int precordevery) {
|
||||
super.valueMin=pvmin;
|
||||
super.valueMax=pvmax;
|
||||
super.posOrigin= new PVector(px,py); //center
|
||||
this.size = new PVector(psx,psy);
|
||||
|
||||
this.recordevery= precordevery;
|
||||
|
||||
this.valuearray = new float[psx]; //array size equals window width
|
||||
this.arraypos=0; //points to position to write to next (current value is at arraypos-1)
|
||||
this.valueMinarray = new float[psx];
|
||||
this.valueMaxarray = new float[psx];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void drawVis() {
|
||||
//update history
|
||||
this.recordevery_counter++;
|
||||
if (this.recordevery_counter>=this.recordevery){
|
||||
this.valuearray[this.arraypos]=super.getValueNormalized();
|
||||
this.arraypos++;
|
||||
this.arraypos%=this.valuearray.length;
|
||||
this.recordevery_counter=0;
|
||||
|
||||
if (super.showMinMax) {
|
||||
this.valueMinarray[this.arraypos]=super.getValueMinNormalized();
|
||||
this.valueMaxarray[this.arraypos]=super.getValueMaxNormalized();
|
||||
super.valueMinRecord=Float.NaN;
|
||||
super.valueMaxRecord=Float.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rectMode(CORNERS);
|
||||
textSize(super.textsize);
|
||||
|
||||
stroke(super.cborder);
|
||||
noFill();
|
||||
rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y-this.size.y);
|
||||
|
||||
noFill();
|
||||
int _cpos=this.arraypos;
|
||||
int _x=0; //position of _ya
|
||||
while (_cpos!=((this.arraypos-1+this.valuearray.length)%this.valuearray.length)) { //go trough all values starting at oldest value
|
||||
float _ya=this.valuearray[_cpos];
|
||||
float _yb=this.valuearray[(_cpos+1)%this.valuearray.length];
|
||||
|
||||
//float _yaMin=this.valueMinarray[_cpos];
|
||||
float _ybMin=this.valueMinarray[(_cpos+1)%this.valuearray.length];
|
||||
float _ybMax=this.valueMaxarray[(_cpos+1)%this.valuearray.length];
|
||||
|
||||
|
||||
if (super.showMinMax) {
|
||||
stroke(super.cmin);
|
||||
//line(super.posOrigin.x+_x,super.posOrigin.y-_yaMin*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_ybMin*this.size.y);
|
||||
line(super.posOrigin.x+_x+1,super.posOrigin.y-_ybMin*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y);
|
||||
stroke(super.cmax);
|
||||
line(super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_ybMax*this.size.y);
|
||||
}
|
||||
|
||||
stroke(super.cmain);
|
||||
line(super.posOrigin.x+_x,super.posOrigin.y-_ya*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y);
|
||||
|
||||
|
||||
|
||||
_x++;
|
||||
_cpos++;
|
||||
_cpos%=this.valuearray.length;
|
||||
}
|
||||
|
||||
//text
|
||||
fill(super.ctext);
|
||||
text(super.getFormattedValue(super.value), super.posOrigin.x+this.size.x-50, super.posOrigin.y+super.textsize*1.5);
|
||||
text(super.getFormattedValue(super.valueMin), super.posOrigin.x+this.size.x+1, super.posOrigin.y+super.textsize*0.5-1);
|
||||
text(super.getFormattedValue(super.valueMax), super.posOrigin.x+this.size.x+1, super.posOrigin.y-this.size.y+super.textsize*0.5-1);
|
||||
//Title
|
||||
text(super.title, super.posOrigin.x, super.posOrigin.y+super.textsize*1.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -253,9 +253,9 @@ public class Tacho extends Visualization {
|
|||
|
||||
public class Direction extends Visualization {
|
||||
int size;
|
||||
float angleoffset=0;
|
||||
|
||||
|
||||
public Direction(int px, int py, int psize,float pvmin, float pvmax, float pvlmin, float pvlmax) {
|
||||
public Direction(int px, int py, int psize,float pvmin, float pvmax, float pvlmin, float pvlmax, float pangleoffset) {
|
||||
super.valueMin=pvmin;
|
||||
super.valueMax=pvmax;
|
||||
super.posOrigin= new PVector(px,py); //center
|
||||
|
@ -263,6 +263,8 @@ public class Direction extends Visualization {
|
|||
|
||||
super.value2Min=pvlmin;
|
||||
super.value2Max=pvlmax;
|
||||
|
||||
this.angleoffset=pangleoffset;
|
||||
}
|
||||
|
||||
|
||||
|
@ -276,7 +278,7 @@ public class Direction extends Visualization {
|
|||
ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size);
|
||||
|
||||
stroke(super.cmain);
|
||||
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI);
|
||||
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI)+this.angleoffset;
|
||||
float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min));
|
||||
line(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize);
|
||||
|
||||
|
@ -285,9 +287,9 @@ public class Direction extends Visualization {
|
|||
|
||||
//text
|
||||
fill(super.ctext);
|
||||
text("d="+super.getFormattedValue(super.value),super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3);
|
||||
text(super.getFormattedValue(super.value),super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3);
|
||||
if (super.value2<super.value2Max){ //display only if in use
|
||||
text("l="+super.getFormattedValue(super.value2),super.posOrigin.x-super.getFormattedValue(super.value2).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3+super.textsize);
|
||||
text("l="+super.getFormattedValue(super.value2),super.posOrigin.x-("l="+super.getFormattedValue(super.value2)).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3+super.textsize);
|
||||
}
|
||||
|
||||
//Title
|
||||
|
@ -295,3 +297,94 @@ public class Direction extends Visualization {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public class GraphRoll extends Visualization {
|
||||
PVector size;
|
||||
float[] valuearray;
|
||||
float[] valueMinarray;
|
||||
float[] valueMaxarray;
|
||||
int arraypos;
|
||||
int recordevery=1; //minimum value =1, the higher the slower
|
||||
int recordevery_counter=0;
|
||||
|
||||
public GraphRoll(int px, int py, int psx, int psy,float pvmin, float pvmax,int precordevery) {
|
||||
super.valueMin=pvmin;
|
||||
super.valueMax=pvmax;
|
||||
super.posOrigin= new PVector(px,py); //center
|
||||
this.size = new PVector(psx,psy);
|
||||
|
||||
this.recordevery= precordevery;
|
||||
|
||||
this.valuearray = new float[psx]; //array size equals window width
|
||||
this.arraypos=0; //points to position to write to next (current value is at arraypos-1)
|
||||
this.valueMinarray = new float[psx];
|
||||
this.valueMaxarray = new float[psx];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void drawVis() {
|
||||
//update history
|
||||
this.recordevery_counter++;
|
||||
if (this.recordevery_counter>=this.recordevery){
|
||||
this.valuearray[this.arraypos]=super.getValueNormalized();
|
||||
this.arraypos++;
|
||||
this.arraypos%=this.valuearray.length;
|
||||
this.recordevery_counter=0;
|
||||
|
||||
if (super.showMinMax) {
|
||||
this.valueMinarray[this.arraypos]=super.getValueMinNormalized();
|
||||
this.valueMaxarray[this.arraypos]=super.getValueMaxNormalized();
|
||||
super.valueMinRecord=Float.NaN;
|
||||
super.valueMaxRecord=Float.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rectMode(CORNERS);
|
||||
textSize(super.textsize);
|
||||
|
||||
stroke(super.cborder);
|
||||
noFill();
|
||||
rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y-this.size.y);
|
||||
|
||||
noFill();
|
||||
int _cpos=this.arraypos;
|
||||
int _x=0; //position of _ya
|
||||
while (_cpos!=((this.arraypos-1+this.valuearray.length)%this.valuearray.length)) { //go trough all values starting at oldest value
|
||||
float _ya=this.valuearray[_cpos];
|
||||
float _yb=this.valuearray[(_cpos+1)%this.valuearray.length];
|
||||
|
||||
//float _yaMin=this.valueMinarray[_cpos];
|
||||
float _ybMin=this.valueMinarray[(_cpos+1)%this.valuearray.length];
|
||||
float _ybMax=this.valueMaxarray[(_cpos+1)%this.valuearray.length];
|
||||
|
||||
|
||||
if (super.showMinMax) {
|
||||
stroke(super.cmin);
|
||||
//line(super.posOrigin.x+_x,super.posOrigin.y-_yaMin*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_ybMin*this.size.y);
|
||||
line(super.posOrigin.x+_x+1,super.posOrigin.y-_ybMin*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y);
|
||||
stroke(super.cmax);
|
||||
line(super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_ybMax*this.size.y);
|
||||
}
|
||||
|
||||
stroke(super.cmain);
|
||||
line(super.posOrigin.x+_x,super.posOrigin.y-_ya*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y);
|
||||
|
||||
|
||||
|
||||
_x++;
|
||||
_cpos++;
|
||||
_cpos%=this.valuearray.length;
|
||||
}
|
||||
|
||||
//text
|
||||
fill(super.ctext);
|
||||
text(super.getFormattedValue(super.value), super.posOrigin.x+this.size.x-50, super.posOrigin.y+super.textsize*1.5);
|
||||
text(super.getFormattedValue(super.valueMin), super.posOrigin.x+this.size.x+1, super.posOrigin.y+super.textsize*0.5-1);
|
||||
text(super.getFormattedValue(super.valueMax), super.posOrigin.x+this.size.x+1, super.posOrigin.y-this.size.y+super.textsize*0.5-1);
|
||||
//Title
|
||||
text(super.title, super.posOrigin.x, super.posOrigin.y+super.textsize*1.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,19 +12,20 @@ void setup() {
|
|||
//vis = new BarV(150,150,10,100,0,100);
|
||||
//vis = new BarH(150,150,100,10,0,100);
|
||||
//vis = new Tacho(150,150,100,0,100);
|
||||
vis = new Direction(150,150,100,0,100,0,1);
|
||||
//vis = new Direction(150,150,100,0,100,0,1,PI/2);
|
||||
vis = new GraphRoll(150,150,200,100,0,100, 20);
|
||||
|
||||
vis.setShowMinMax(true);
|
||||
vis.setShowMinMax(false);
|
||||
vis.setTitle("Testwert");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
//rawvalue +=random(-5,5);
|
||||
//rawvalue = constrain(rawvalue, 0,100);
|
||||
rawvalue +=random(-10,10);
|
||||
rawvalue = constrain(rawvalue, 0,100);
|
||||
xoff += 0.01;
|
||||
xoff2 += 0.004;
|
||||
rawvalue=noise(xoff) * 100;
|
||||
//rawvalue=noise(xoff) * 100;
|
||||
|
||||
vis.setValue(rawvalue);
|
||||
|
||||
|
|
Loading…
Reference in New Issue