Bill Examples
M&MStudioBV
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
|
||||
// Click within the image to change
|
||||
// the value of the rectangle
|
||||
|
||||
int value = 20;
|
||||
|
||||
void setup(){
|
||||
size(300,400);
|
||||
stroke(value);
|
||||
background(250);
|
||||
}
|
||||
|
||||
void draw(){
|
||||
value = mouseX;
|
||||
fill(value);
|
||||
stroke(value-100);
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
ellipse(mouseX,mouseY,20,20);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
int[] altitude = { 10, 20, 30, 40, 50, 40, 30, 20, 10, 0 };
|
||||
int i;
|
||||
int s = 80;
|
||||
|
||||
void setup() {
|
||||
size(800,100);
|
||||
}
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,50,799,50);
|
||||
stroke(0);
|
||||
|
||||
for (i = 0; i < 9; i = i+1) {
|
||||
line(s*i,altitude[i],s*(i+1),altitude[i+1]);
|
||||
}
|
||||
|
||||
line(s*9, altitude[9], s*10-1, 50);
|
||||
|
||||
for (i = 0; i < 9; i = i+1) {
|
||||
ellipse(s*(i+1),altitude[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
int pos = (mouseX+40)/s;
|
||||
altitude[pos]=mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
int pos = mouseX/s;
|
||||
altitude[pos]=mouseY;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, ibest;
|
||||
float dist;
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=int(random(-100,100));
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY-100;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY-100;
|
||||
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = 0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(i*s+j,height,i*s+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
// arrow keys for one-pixel motion
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY-100;
|
||||
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = -0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
//s = x[i+1] - x[i] + 1; // variable widths!
|
||||
s = x[i+1] - x[i]; // number of increments
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
|
||||
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// Profile of forces and terrain
|
||||
|
||||
int n = 10; //number of values of F calculated for each s
|
||||
int s = 80; //number of samples for each n
|
||||
int[] F = new int[11]; //course Force values
|
||||
float[] FF = new float[800]; //fine Forces interpolated
|
||||
int i,j;
|
||||
//int s = 80;
|
||||
//int n = 10;
|
||||
int pos;
|
||||
|
||||
void setup() {
|
||||
size(800,200); // double height to see what interpolation looks like
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,50,n*s-1,50);
|
||||
stroke(0);
|
||||
|
||||
for (i = 0; i <n; i = i+1 ) {
|
||||
line(s*i, F[i], s*(i+1), F[i+1]);
|
||||
}
|
||||
|
||||
// line(s*(n-1), F[n-1], s*n, 0);
|
||||
|
||||
for (i = 0; i <9; i = i+1) {
|
||||
ellipse(s*(i+1),F[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
pos = (mouseX+s/2)/s;
|
||||
F[pos]=mouseY;
|
||||
}
|
||||
// plot seg ments of curving terrain (interpolating force?)
|
||||
for (i = 0; i <n; i = i+1) {
|
||||
line(i*s,height-F[i],(i+1)*s,height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void mouseReleased(){
|
||||
for (i = 0; i<n; i = i+1){
|
||||
line(i,height,i+s,height-j);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
Ctrl c1, c2, c3;
|
||||
|
||||
void setup()
|
||||
{
|
||||
size(640, 360);
|
||||
noStroke();
|
||||
c1 = new Ctrl( 100, 100, 0);
|
||||
c2 = new Ctrl( 200, 120, 100);
|
||||
c3 = new Ctrl( 300, 130, 200);
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
background(250);
|
||||
|
||||
c1.update(mouseX, mouseY);
|
||||
c2.update(mouseX, mouseY);
|
||||
c3.update(mouseX, mouseY);
|
||||
|
||||
c1.display();
|
||||
c2.display();
|
||||
c3.display();
|
||||
|
||||
}
|
||||
|
||||
class Ctrl {
|
||||
int x, y;
|
||||
int offset;
|
||||
|
||||
Ctrl(int tx, int ty, int to) {
|
||||
x = tx;
|
||||
y = ty;
|
||||
offset = to;
|
||||
}
|
||||
|
||||
void update(int mx, int my) {
|
||||
offset = mouseX;
|
||||
}
|
||||
void display() {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
fill (250);
|
||||
rotate(offset);
|
||||
fill (153);
|
||||
ellipse(offset, 0, offset/2, 2*offset);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
//(Arduino) Profile sends pos to (Processing) ProfileFx
|
||||
|
||||
void setup(){
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
Serial.println(analogRead(A0));
|
||||
delay(100);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, j, ibest;
|
||||
int s = 80;
|
||||
int n = 10;
|
||||
float dist;
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
|
||||
|
||||
void setup(){
|
||||
noFill();
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=0;
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(200);
|
||||
stroke(150);
|
||||
line(0,100,width,100);
|
||||
line(0,200,width,200);
|
||||
for (i = 1; i < 10; i = i+1){
|
||||
line (i*80,0,i*80,200);
|
||||
}
|
||||
stroke(0);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i]+100,x[i+1],F[i+1]+100);
|
||||
}
|
||||
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]+100-mouseY)+sq(x[0]-mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]+100-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]+100-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest]+100,20,20);
|
||||
|
||||
text (Integer.toString(ibest), mouseX+10, mouseY-12);
|
||||
text (Integer.toString(F[ibest]), mouseX+10, mouseY);
|
||||
text (Integer.toString(x[ibest]), mouseX+10, mouseY+12);
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
x[ibest] = min(x[ibest+1],max(x[ibest-1],mouseX));
|
||||
F[ibest] = mouseY - 100;
|
||||
if (mouseY < 0) F[ibest] = -100;
|
||||
if (mouseY > 200) F[ibest] = 100;
|
||||
}
|
||||
|
||||
//plot "terrain" assuming 80 point separation of F[]'s
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
s = x[i+1]-x[i]+1; // increment used for plotting
|
||||
inc = 0.01*(F[i+1]-F[i])/s;
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(x[i]+j,height,x[i]+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == CODED) {
|
||||
if (keyCode == UP) --F[ibest];
|
||||
if (keyCode == DOWN) ++F[ibest];
|
||||
if (keyCode == RIGHT) ++x[ibest];
|
||||
if (keyCode == LEFT) --x[ibest];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
// Profile of forces and terrain
|
||||
|
||||
int n = 10; //number of values of F calculated for each s
|
||||
int s = 80; //number of samples for each n
|
||||
int[] F = new int[11]; // Force values [-512 to +511] scaled for plot?
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
int i,j;
|
||||
int pos;
|
||||
int vt = 50; //vertical translation for force curve
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
size(800,800); // double height to see what interpolation looks like
|
||||
for(i=0;i<n+1;i=i+1){
|
||||
F[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(200);
|
||||
|
||||
pushMatrix();
|
||||
translate(0,vt); // center force plot at vt
|
||||
stroke(150);
|
||||
line(0,0,n*s-1,0); // the zero force line
|
||||
|
||||
stroke(0); // the force segments
|
||||
for (i = 0; i <n; i = i+1 ) {
|
||||
line(s*i, F[i], s*(i+1), F[i+1]);
|
||||
}
|
||||
|
||||
for (i = 0; i <9; i = i+1) {
|
||||
ellipse(s*(i+1),F[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
pos = (mouseX+s/2)/s;
|
||||
F[pos]=mouseY-vt;
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = 0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(i*s+j,height,i*s+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void mouseReleased(){
|
||||
}
|
||||
|
||||
// plot seg ments of curving terrain (interpolating force?)
|
||||
top = 50;
|
||||
for (i = 0; i <n; i = i+1) {
|
||||
inc = (F[i+1]-F[i])/s; // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1){
|
||||
top = top + inc*j; // j increments of inc = F diff.
|
||||
line(i*s,height-top,i*s,height);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
// Profile of forces and terrain
|
||||
|
||||
int n = 10; //number of values of F calculated for each s
|
||||
int s = 80; //number of samples for each n
|
||||
int[] F = new int[11]; // Force values [-512 to +511] scaled for plot?
|
||||
float FF; // forces interpolated
|
||||
float top; // terrain value (integral of forces)
|
||||
float inc; // interpolated slope ( F[i+1] - F[i] ) / s
|
||||
int i,j;
|
||||
int pos;
|
||||
int vt = 50; //vertical translation for force curve
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
size(800,800); // double height to see what interpolation looks like
|
||||
for(i=0;i<n+1;i=i+1){
|
||||
F[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw() {
|
||||
background(200);
|
||||
|
||||
pushMatrix();
|
||||
translate(0,vt); // center force plot at vt
|
||||
stroke(150);
|
||||
line(0,0,n*s-1,0); // the zero force line
|
||||
|
||||
stroke(0); // the force segments
|
||||
for (i = 0; i <n; i = i+1 ) {
|
||||
line(s*i, F[i], s*(i+1), F[i+1]);
|
||||
}
|
||||
|
||||
for (i = 0; i <9; i = i+1) {
|
||||
ellipse(s*(i+1),F[i+1], 10, 10);
|
||||
}
|
||||
|
||||
if (mousePressed == true) {
|
||||
pos = (mouseX+s/2)/s;
|
||||
F[pos]=mouseY-vt;
|
||||
}
|
||||
|
||||
popMatrix();
|
||||
pushMatrix();
|
||||
translate(0,height/2);
|
||||
/*for (i = 0; i<n; i = i+1){
|
||||
line(i*s,0,(i+1)*s,0);
|
||||
}*/
|
||||
top = 0;
|
||||
FF = F[0];
|
||||
for (i = 0; i < n; i = i+1) {
|
||||
inc = 0.001*(F[i+1]-F[i]); // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1) {
|
||||
FF = FF + inc;
|
||||
top = top + FF; // j increments of inc = F diff.
|
||||
line(i*s+j,height,i*s+j,top);
|
||||
}
|
||||
}
|
||||
popMatrix();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void mouseReleased(){
|
||||
}
|
||||
|
||||
// plot seg ments of curving terrain (interpolating force?)
|
||||
top = 50;
|
||||
for (i = 0; i <n; i = i+1) {
|
||||
inc = (F[i+1]-F[i])/s; // increment used for plotting
|
||||
for (j = 0; j < s; j = j+1){
|
||||
top = top + inc*j; // j increments of inc = F diff.
|
||||
line(i*s,height-top,i*s,height);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// two-dimensional array?
|
||||
// i = 1, 8;
|
||||
// int F[], // shown an height
|
||||
// x[i], //
|
||||
|
||||
// constrain x[i]<x[i+1]??
|
||||
|
||||
int F[] = {0,0,0,0,0,0,0,0,0,0,0};
|
||||
int x[] = {1,2,3,4,5,6,7,8,9,10,11};
|
||||
int i, ibest;
|
||||
float dist;
|
||||
|
||||
void setup(){
|
||||
size(800,800);
|
||||
for(i=0;i<11;i=i+1){
|
||||
F[i]=int(random(200));
|
||||
x[i]=80*i;
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
background(190);
|
||||
for (i = 0; i < 10;i= i+1){
|
||||
line(x[i],F[i],x[i+1],F[i+1]);
|
||||
}
|
||||
|
||||
//if (mousePressed == false){
|
||||
//test every F,x pair to see who is closest call it ibest;
|
||||
ibest = 1;
|
||||
dist = sq(F[0]-mouseY)+sq(x[0]*mouseX);
|
||||
for (i=1;i<10;i=i+1){
|
||||
if(dist > sq(F[i]-mouseY)+sq(x[i]-mouseX)){
|
||||
ibest = i;
|
||||
dist = sq(F[i]-mouseY)+sq(x[i]-mouseX);
|
||||
}
|
||||
}
|
||||
ellipse(x[ibest],F[ibest],20,20);
|
||||
// }
|
||||
|
||||
if (mousePressed == true){
|
||||
//now use ibest to move to mouseX, mouseY
|
||||
F[ibest] = mouseY;
|
||||
x[ibest] = min(x[ibest+1],mouseX);
|
||||
x[ibest] = max(x[ibest-1],mouseX);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user