Goldsmiths
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
import controlP5.*;
|
||||
import processing.serial.*;
|
||||
|
||||
//Plots
|
||||
ScopePlot plotA;
|
||||
ScopePlot plotB;
|
||||
ScopePlotDouble plotC;
|
||||
|
||||
//Communication with MMM boards
|
||||
Protocol proto;
|
||||
|
||||
//Serial port
|
||||
Serial p;
|
||||
|
||||
//Controlers
|
||||
ControlP5 cp5;
|
||||
SliderCallback scb;
|
||||
|
||||
// (k)
|
||||
float kmin = 0.0f;
|
||||
float kmax = 7.0f;
|
||||
float k = 0.2f;
|
||||
Slider k_slider;
|
||||
|
||||
// (m)
|
||||
float mmin = 0.0f;
|
||||
float mmax = 7.0f;
|
||||
float m = 1.0f;
|
||||
Slider m_slider;
|
||||
|
||||
// (d)
|
||||
float dmin = 0.0f;
|
||||
float dmax = 7.0f;
|
||||
float d = 0.02f;
|
||||
Slider d_slider;
|
||||
|
||||
void setup() {
|
||||
|
||||
int b = 15;
|
||||
int h = 300;//(displayHeight / 4) - (3*b);
|
||||
int w = displayWidth / 2;
|
||||
|
||||
plotA = new ScopePlot("Force", w, h, b, b + b, 512, true);
|
||||
plotB = new ScopePlot("Velocity", w, h, b, h + 4*b, 512, true);
|
||||
plotC = new ScopePlotDouble("Position Estimate", w, h, b, 2*h + 6*b, 512, true);
|
||||
|
||||
p = new Serial(this, Serial.list()[0], 9600);
|
||||
proto = new Protocol(p);
|
||||
|
||||
// Controls
|
||||
cp5 = new ControlP5(this);
|
||||
scb = new SliderCallback();
|
||||
|
||||
int sw = w / 3;
|
||||
|
||||
k_slider = cp5.addSlider("k", kmin, kmax, b, b-5, sw - b, b-5);
|
||||
k_slider.setColorForeground(color(127,34,255));
|
||||
k_slider.setColorBackground(color(50,50,50));
|
||||
k_slider.addListener(scb);
|
||||
|
||||
m_slider = cp5.addSlider("m", mmin, mmax, 2*b + sw, b-5, sw - b, b-5);
|
||||
m_slider.setColorForeground(color(127,34,255));
|
||||
m_slider.setColorBackground(color(50,50,50));
|
||||
m_slider.addListener(scb);
|
||||
|
||||
d_slider = cp5.addSlider("d", dmin, dmax, 3*b + 2*sw, b-5, sw - b, b-5);
|
||||
d_slider.setColorForeground(color(127,34,255));
|
||||
d_slider.setColorBackground(color(50,50,50));
|
||||
d_slider.addListener(scb);
|
||||
|
||||
size(w + 60, displayHeight - (h + (3*b)));
|
||||
//size(w + 60, 800);
|
||||
//size(600, 800);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
plotA.draw();
|
||||
plotB.draw();
|
||||
plotC.draw();
|
||||
}
|
||||
|
||||
/*
|
||||
void mouseDragged()
|
||||
{
|
||||
plotA.mdata(mouseX, mouseY);
|
||||
plotB.mdata(mouseX, mouseY);
|
||||
plotC.mdata(mouseX, mouseY);
|
||||
}
|
||||
|
||||
void mouseClicked()
|
||||
{
|
||||
plotA.mdata(mouseX, mouseY);
|
||||
plotB.mdata(mouseX, mouseY);
|
||||
plotC.mdata(mouseX, mouseY);
|
||||
}
|
||||
*/
|
||||
|
||||
void serialEvent (Serial myPort) {
|
||||
proto.processData();
|
||||
plotA.data(proto.F);
|
||||
plotB.data(proto.V);
|
||||
plotC.data(proto.X - 512, proto.Xin - 512);
|
||||
}
|
||||
|
||||
class SliderCallback implements ControlListener {
|
||||
public void controlEvent(ControlEvent ev) {
|
||||
p.write(new String(ev.controller().name()+ev.controller().value()+";"));
|
||||
//println(ev.controller().name() + ": " + ev.controller().value());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import processing.serial.*;
|
||||
|
||||
class Protocol {
|
||||
Serial port; // The serial port
|
||||
Protocol() {;}
|
||||
|
||||
int F, V, X, Xin;
|
||||
|
||||
Protocol(Serial p) {
|
||||
port = p;
|
||||
port.bufferUntil('\n');
|
||||
}
|
||||
|
||||
void processData() {
|
||||
String in = port.readStringUntil('\n');
|
||||
if(in != null){
|
||||
String[] t = splitTokens(in);
|
||||
F = int(t[0]);
|
||||
V = int(t[1]);
|
||||
X = int(t[2]);
|
||||
Xin = int(t[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
class ScopePlot {
|
||||
|
||||
int d = 4, s = 4;
|
||||
int indx, max, min;
|
||||
int w, h;
|
||||
int px, py;
|
||||
int by;
|
||||
int[] values;
|
||||
int[] pixelvalues;
|
||||
String title;
|
||||
|
||||
ScopePlot(String t, int w, int h, int x, int y, int maxval, boolean mid){
|
||||
this.title = t;
|
||||
this.w = w + d;
|
||||
this.h = h + d;
|
||||
this.indx = s;
|
||||
this.px = x - d;
|
||||
this.py = y + d;
|
||||
this.max = maxval;
|
||||
this.min = -maxval;
|
||||
noFill();
|
||||
textSize(12);
|
||||
values = new int[w / s];
|
||||
pixelvalues = new int[w / s];
|
||||
if(mid) by = h / 2;
|
||||
else by = this.h;
|
||||
}
|
||||
|
||||
void draw(){
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(px, py);
|
||||
|
||||
stroke(255,255,255);
|
||||
line( -d, h, w + d + d, h);
|
||||
line( 0, -d, 0, h + d);
|
||||
line( -d, 0, w + d + d, 0);
|
||||
line( w + d, h + d, w + d , -d);
|
||||
|
||||
fill(255,255,255);
|
||||
textSize(10);
|
||||
text(title, d, -d+2);
|
||||
noFill();
|
||||
if(by != h) {
|
||||
line(-d, by, w + d, by);
|
||||
text(Integer.toString(this.max), w + d + d + d, 0);
|
||||
text(Integer.toString(this.min), w + d + d + d, h + d);
|
||||
} else {
|
||||
text(Integer.toString(this.max), w + d + d + d, 0);
|
||||
text(Integer.toString(values.length), w + d + d + d, h + d + d + d);
|
||||
}
|
||||
|
||||
int x = s;
|
||||
for(int i = 0; i < pixelvalues.length; i++) {
|
||||
stroke(127,34,255);
|
||||
line(x, by, x, by - pixelvalues[i]);
|
||||
stroke(255,34,127);
|
||||
if(i == indx - 1) {
|
||||
stroke(255);
|
||||
text(Integer.toString(values[i]), w + d + d + d, by - pixelvalues[i]);
|
||||
}
|
||||
ellipse(x, by - pixelvalues[i], 3, 3);
|
||||
x += s;
|
||||
}
|
||||
|
||||
|
||||
popMatrix();
|
||||
|
||||
}
|
||||
|
||||
void data(int d) {
|
||||
values[indx] = d;
|
||||
float i = (float) d / (float)this.max;
|
||||
if(by != h) pixelvalues[indx++] = (int)(i * h / 2);
|
||||
else pixelvalues[indx++] = (int)(i * h);
|
||||
indx %= (w / s) - 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ScopePlotDouble extends ScopePlot {
|
||||
|
||||
int[] values_second;
|
||||
int[] pixelvalues_second;
|
||||
|
||||
ScopePlotDouble(String t, int w, int h, int x, int y, int maxval, boolean mid){
|
||||
super(t, w, h, x, y, maxval, mid);
|
||||
values_second = new int[values.length];
|
||||
pixelvalues_second = new int[pixelvalues.length];
|
||||
}
|
||||
|
||||
void data(int d0, int d1) {
|
||||
values_second[indx] = d1;
|
||||
float i = (float) d1 / (float)this.max;
|
||||
if(by != h) pixelvalues_second[indx] = (int)(i * h / 2);
|
||||
else pixelvalues_second[indx] = (int)(i * h);
|
||||
super.data(d0);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(px, py);
|
||||
|
||||
int x = s;
|
||||
for(int i = 0; i < pixelvalues_second.length; i++) {
|
||||
stroke(255,34,127);
|
||||
line(x, by, x, by - pixelvalues_second[i]);
|
||||
stroke(127,34,255);
|
||||
if(i == indx - 1) {
|
||||
stroke(255);
|
||||
text(Integer.toString(values_second[i]), w + d + d + d, by - pixelvalues_second[i]);
|
||||
}
|
||||
ellipse(x, by - pixelvalues_second[i], 3, 3);
|
||||
x += s;
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
|
||||
super.draw();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ScopePlotInteract extends ScopePlot {
|
||||
|
||||
int[] cpoints;
|
||||
int[] cpointsvalues;
|
||||
|
||||
int mx, my;
|
||||
|
||||
ScopePlotInteract(String t, int w, int h, int x, int y, int maxval, boolean mid) {
|
||||
super(t, w, h, x, y, maxval, mid);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
mx = 0;
|
||||
super.draw();
|
||||
}
|
||||
|
||||
void mdata(int mousex, int mousey) {
|
||||
if(mousex < px + w && mousex > px && mousey > py && mousey < py + h) {
|
||||
mx = (mousex - px) / s;
|
||||
my = mousey;
|
||||
if(mx < pixelvalues.length)
|
||||
pixelvalues[mx] = (by + py) - my;
|
||||
// compute real values here
|
||||
}
|
||||
/*
|
||||
else if((mousex > px + w && mousex < px + w + d) || (mousex < px && mousex > px - d) ||
|
||||
(mousey < py && mousey > py - d) || (mousey > py + h && mousey < py + h + d)) {
|
||||
px += (mousex - mx);
|
||||
py += (my - mousey);
|
||||
}
|
||||
mx = mousex;
|
||||
my = mousey;
|
||||
*/
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#include <Motion.h>
|
||||
#include <Motor.h>
|
||||
#include <Music.h>
|
||||
|
||||
char buf[16] = "";
|
||||
|
||||
char b = 'x';
|
||||
String inputString = "";
|
||||
boolean stringComplete = false;
|
||||
|
||||
float k, m, d;
|
||||
|
||||
int cnt = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
// MOTOR
|
||||
MotorA.init();
|
||||
|
||||
// MUSIC
|
||||
Music.init();
|
||||
|
||||
// MOTION
|
||||
MotionA.init(INPUTA0);
|
||||
MotionA.k = 5.2f; // spring
|
||||
MotionA.m = 1.0f; // mass
|
||||
MotionA.d = 8.02f; // damping
|
||||
|
||||
// Serial
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
MotionA.update_mass_spring_damper();
|
||||
|
||||
MotorA.torque(MotionA.F);
|
||||
|
||||
int f = map(abs(MotionA.F), 0, 512, 64, 76);
|
||||
Music.noteOn(f);
|
||||
|
||||
cnt++;
|
||||
|
||||
if(cnt == 10) {
|
||||
sprintf(buf, "%d %d %d %d", (int)MotionA.F, (int)MotionA.V, (int)MotionA.X, (int)MotionA.Xin);
|
||||
Serial.println(buf);
|
||||
cnt = 0;
|
||||
}
|
||||
|
||||
if(stringComplete) {
|
||||
if(b == 'k') {
|
||||
MotionA.k = convertToFloat(inputString);
|
||||
} else if(b == 'm') {
|
||||
MotionA.m = convertToFloat(inputString);
|
||||
} else if(b == 'd') {
|
||||
MotionA.d = convertToFloat(inputString);
|
||||
}
|
||||
b = 'x';
|
||||
stringComplete = false;
|
||||
inputString = "";
|
||||
}
|
||||
}
|
||||
|
||||
void serialEvent() {
|
||||
while (Serial.available()) {
|
||||
char inChar = (char)Serial.read();
|
||||
if(inChar == 'k' || inChar == 'm' || inChar == 'd') {
|
||||
b = inChar;
|
||||
} else {
|
||||
if (inChar == ';') {
|
||||
stringComplete = true;
|
||||
} else
|
||||
inputString += inChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float convertToFloat(String str) {
|
||||
char buf[16] = "";
|
||||
str.toCharArray(buf, str.length() + 1);
|
||||
return atof(buf);
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import controlP5.*;
|
||||
import processing.serial.*;
|
||||
|
||||
static char NEW = '!';
|
||||
static char OK = '*';
|
||||
static char PRINT = '&';
|
||||
|
||||
ForceProfilePlot fpp;
|
||||
Button send;
|
||||
Button print;
|
||||
|
||||
//Serial port
|
||||
Serial p;
|
||||
|
||||
void setup() {
|
||||
|
||||
int b = 15;
|
||||
//int h = (displayHeight / 3); (work in certain resolution)
|
||||
//int w = displayWidth / 2; (work in certain resolution)
|
||||
int w = 720;
|
||||
int h = 300;
|
||||
|
||||
println("w: " + w + " h: " + h);
|
||||
|
||||
fpp = new ForceProfilePlot("Force Profile - Perception Terrain", w, h, b, b, 80, true);
|
||||
|
||||
ControlP5 cp5 = new ControlP5(this);
|
||||
|
||||
send = cp5.addButton("send");
|
||||
send.setPosition(w - 20, 2*h + 2*b + 7);
|
||||
send.setSize(35, 15);
|
||||
send.setColorForeground(color(127,34,255));
|
||||
send.setColorBackground(color(50,50,50));
|
||||
|
||||
print = cp5.addButton("print");
|
||||
print.setPosition(w - 140, 2*h + 2*b + 7);
|
||||
print.setSize(35, 15);
|
||||
print.setColorForeground(color(127,34,255));
|
||||
print.setColorBackground(color(50,50,50));
|
||||
|
||||
size(w + 60, 2*h + 60);
|
||||
|
||||
p = new Serial(this, Serial.list()[0], 9600);
|
||||
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
fpp.draw();
|
||||
|
||||
if(p.available() > 0) {
|
||||
String in = p.readStringUntil('\n');
|
||||
if(in != null) {
|
||||
println(in);
|
||||
String[] t = splitTokens(in);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
fpp.drag(mouseX, mouseY);
|
||||
}
|
||||
|
||||
void mouseClicked()
|
||||
{
|
||||
fpp.click(mouseX, mouseY);
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
fpp.release();
|
||||
}
|
||||
|
||||
public void send() {
|
||||
|
||||
send.setOff();
|
||||
|
||||
p.write(NEW);
|
||||
println("1");
|
||||
while(p.available() <= 0);
|
||||
println("2");
|
||||
char in = p.readChar();
|
||||
println("3");
|
||||
if(in == OK) {
|
||||
println("GO!");
|
||||
int s = 800 / fpp.forces.length;
|
||||
int len = s * (fpp.forces.length - 1);
|
||||
serial_send(len);
|
||||
float dx = 1023.0f / (fpp.forces.length - 1);
|
||||
float ddx = dx / s;
|
||||
for(int i = 0; i < fpp.forces.length-1; i++) {
|
||||
float k = fpp.forces[i];
|
||||
float m = (fpp.forces[i+1] - k) / dx;
|
||||
for(int j = 0; j < s; j++) {
|
||||
int d = (int)(k + m*j);
|
||||
serial_send(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
send.setOn();
|
||||
|
||||
}
|
||||
|
||||
public void print() {
|
||||
println("print");
|
||||
print.setOff();
|
||||
p.write(PRINT);
|
||||
while(p.available() <= 0); // block
|
||||
while(p.available() > 0) {
|
||||
String s = p.readStringUntil('#');
|
||||
if(s != null)
|
||||
println(s);
|
||||
}
|
||||
send.setOn();
|
||||
}
|
||||
|
||||
public boolean serial_send(int i) {
|
||||
p.clear();
|
||||
char msb = (char) (i / 256);
|
||||
char lsb = (char) (i & 0xff);
|
||||
p.write(lsb);
|
||||
p.write(msb);
|
||||
while(p.available() <= 0);
|
||||
char in = p.readChar();
|
||||
return (in == OK);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
class ForceProfilePlot {
|
||||
|
||||
int d = 4, s = 4;
|
||||
float steps = 4;
|
||||
int max, min;
|
||||
int w, h, by;
|
||||
int px, py;
|
||||
|
||||
int res = 800;
|
||||
|
||||
int[] forces;
|
||||
int[] forces_pixelvalues;
|
||||
|
||||
int mx, my;
|
||||
|
||||
String title;
|
||||
|
||||
TerrainPlot tr;
|
||||
|
||||
|
||||
ForceProfilePlot(String t, int w, int h, int x, int y, int nbr_ctrpoints, boolean terrain) {
|
||||
this.title = t;
|
||||
this.w = w + d;
|
||||
this.h = h + d;
|
||||
this.px = x - d;
|
||||
this.py = y + d;
|
||||
this.max = 512;
|
||||
this.min = -512;
|
||||
noFill();
|
||||
textSize(12);
|
||||
this.s = 800 / nbr_ctrpoints;
|
||||
this.steps = (float)(w + 2*d) / (nbr_ctrpoints - 1);
|
||||
this.by = h / 2;
|
||||
forces = new int[nbr_ctrpoints]; // zeros???
|
||||
forces_pixelvalues = new int[nbr_ctrpoints];
|
||||
if (terrain)
|
||||
tr = new TerrainPlot("Terrain", w, h, x, y + h + 2 * d, nbr_ctrpoints, steps);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(px, py);
|
||||
|
||||
stroke(255, 255, 255);
|
||||
line( -d, h, w + d + d, h);
|
||||
line( 0, -d, 0, h + d);
|
||||
line( -d, 0, w + d + d, 0);
|
||||
line( w + d, h + d, w + d, -d);
|
||||
|
||||
fill(255, 255, 255);
|
||||
textSize(10);
|
||||
text(title, d, -d+2);
|
||||
noFill();
|
||||
line(-d, by, w + d, by);
|
||||
text(Integer.toString(this.max), w + d + d + d, 0);
|
||||
text(Integer.toString(this.min), w + d + d + d, h + d);
|
||||
|
||||
float x = 0;
|
||||
for (int i = 0; i < forces_pixelvalues.length; i++) {
|
||||
|
||||
stroke(127, 34, 255);
|
||||
line(x, by, x, by - forces_pixelvalues[i]);
|
||||
|
||||
stroke(255, 34, 127);
|
||||
ellipse(x, by - forces_pixelvalues[i], 5, 5);
|
||||
|
||||
if (i != 0) {
|
||||
stroke(255, 255, 255);
|
||||
line(x, by - forces_pixelvalues[i], x - steps, by - forces_pixelvalues[i - 1]);
|
||||
}
|
||||
|
||||
if(steps > 20)
|
||||
text(Integer.toString(forces[i]), x, by - forces_pixelvalues[i] + (forces[i] < 0 ? 7 : -7));
|
||||
|
||||
x += steps;
|
||||
}
|
||||
|
||||
|
||||
if (mx > 0) {
|
||||
int e = round((float) mx / steps);
|
||||
stroke(255, 34, 127);
|
||||
line(e * steps, by - forces_pixelvalues[e], mx, my);
|
||||
}
|
||||
|
||||
|
||||
popMatrix();
|
||||
|
||||
if (tr != null) tr.draw();
|
||||
}
|
||||
|
||||
void forces_from_pixels() {
|
||||
for (int i = 0; i < forces_pixelvalues.length; i++) {
|
||||
forces[i] = (int)(((by - forces_pixelvalues[i]) / h * 2) * 512);
|
||||
}
|
||||
}
|
||||
|
||||
void pixels_from_forces() {
|
||||
for (int i = 0; i < forces.length; i++) {
|
||||
forces_pixelvalues[i] = (int)(((float) forces[i] / (float)this.max) * h / 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drag(int mousex, int mousey) {
|
||||
if (hit(mousex, mousey))
|
||||
position_point(mousex, mousey);
|
||||
}
|
||||
|
||||
void click(int mousex, int mousey) {
|
||||
if (hit(mousex, mousey))
|
||||
position_point(mousex, mousey);
|
||||
}
|
||||
|
||||
void release() {
|
||||
mx = -1;
|
||||
my = -1;
|
||||
}
|
||||
|
||||
void position_point(int mousex, int mousey) {
|
||||
int i = round((float) (mousex - px - d) / steps);
|
||||
forces_pixelvalues[i] = h / 2 - (mousey - py - d);
|
||||
forces[i] = (int)((((float)forces_pixelvalues[i]) / h * 2) * 512);
|
||||
|
||||
my = mousey - py - d;
|
||||
mx = mousex - px - d;
|
||||
|
||||
if (tr != null) {
|
||||
tr.data(forces_pixelvalues);
|
||||
/*
|
||||
if (i > 0)
|
||||
tr.data(i - 1, forces_pixelvalues[i - 1], i, forces_pixelvalues[i]);
|
||||
if (i < forces_pixelvalues.length - 1)
|
||||
tr.data(i, forces_pixelvalues[i], i + 1, forces_pixelvalues[i + 1]);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
boolean hit(int mousex, int mousey) {
|
||||
return (mousex < px + w) && (mousex > px) && (mousey > py) && (mousey < py + h);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
class TerrainPlot {
|
||||
|
||||
int d = 4;
|
||||
float max, min;
|
||||
int w, h;
|
||||
int px, py;
|
||||
|
||||
float steps_per_index; // this should not exceed step_index;
|
||||
float s, step_index;
|
||||
|
||||
String title;
|
||||
float pixelvalues[];
|
||||
|
||||
TerrainPlot(String t, int w, int h, int x, int y, int nbr_index, float step_index) {
|
||||
this.title = t;
|
||||
this.w = w + d;
|
||||
this.h = h + d;
|
||||
this.px = x - d;
|
||||
this.py = y + d;
|
||||
noFill();
|
||||
textSize(12);
|
||||
this.step_index = step_index;
|
||||
this.steps_per_index = (step_index / 3);
|
||||
this.s = 3;
|
||||
/*
|
||||
|
||||
if(step_index > steps_per_index) {
|
||||
this.s = ((float) step_index / steps_per_index);
|
||||
} else {
|
||||
this.s = step_index;
|
||||
this.steps_per_index = 1;
|
||||
}
|
||||
*/
|
||||
pixelvalues = new float[(int)((nbr_index - 1) * steps_per_index) + 1];
|
||||
}
|
||||
|
||||
void draw() {
|
||||
pushMatrix();
|
||||
|
||||
pushMatrix();
|
||||
|
||||
translate(px, py);
|
||||
|
||||
stroke(255, 255, 255);
|
||||
line( -d, h, w + d + d, h);
|
||||
line( 0, -d, 0, h + d);
|
||||
line( -d, 0, w + d + d, 0);
|
||||
line( w + d, h + d, w + d, -d);
|
||||
|
||||
fill(255, 255, 255);
|
||||
textSize(10);
|
||||
//text(title, d, -d+2);
|
||||
|
||||
popMatrix();
|
||||
|
||||
translate(px, py + h);
|
||||
|
||||
for(int i = 0; i < pixelvalues.length; i++) {
|
||||
float y = pixelvalues[i];
|
||||
if(abs(min) > h) {
|
||||
y = (y / abs(min)) * h;
|
||||
}
|
||||
line(i * s, 0, i * s, y);
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void data(int[] forces_points) {
|
||||
|
||||
float FF = 0;//forces[0]; // forces interpolated
|
||||
float top = 0; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
max = 0; min = 0;
|
||||
for(int i = 0; i < forces_points.length - 1; i++) {
|
||||
inc = 0.005 * (forces_points[i+1] - forces_points[i]) ;
|
||||
for(int j = 0; j < steps_per_index; j++) {
|
||||
FF += inc;
|
||||
top = top + FF;
|
||||
pixelvalues[(int)(i * steps_per_index) + j] = top;
|
||||
if(top > max) max = top;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < pixelvalues.length; i++) {
|
||||
pixelvalues[i] = (int)(pixelvalues[i] - max);
|
||||
if(pixelvalues[i] < min) {
|
||||
min = pixelvalues[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
mode.id=processing.mode.java.JavaMode
|
||||
mode=Java
|
||||
Reference in New Issue
Block a user