HELP!!! The field component x is not visiable
in
Programming Questions
•
1 years ago
I first started a sketch by learning a example to draw four groups of circles that continuously changing the radius,and they follow the cursor.the following are my code:
Spring2D s1, s2, s3, s4;
float gravity = 0;
float mass = 5.0;
void setup()
{frameRate(30);
size(600, 600);
smooth();
fill(0);
// Inputs: x, y, mass, gravity
s1 = new Spring2D(0.0, width/2, mass, gravity);
s2 = new Spring2D(0.0, width/2, mass, gravity);
s3 = new Spring2D(0.0, width/2, mass, gravity);
s4 = new Spring2D(0.0, width/2, mass, gravity);
}
void draw()
{
background(150);
s1.update(mouseX, mouseY,0);
s1.display(mouseX, mouseY,0);
s2.update(s1.x, s1.y,15);
s2.display(s1.x, s1.y,15);
s3.update(s2.x, s2.y,30);
s3.display(s2.x, s2.y,30);
s4.update(s3.x, s3.y,45);
s4.display(s3.x, s3.y,45);
}
class Spring2D {
float vx, vy; // The x- and y-axis velocities
float x, y; // The x- and y-coordinates
float gravity;
float mass;
float radius = 80;
float stiffness = 0.2;
float damping = 0.7;
Spring2D(float xpos, float ypos, float m, float g) {
x = xpos;
y = ypos;
mass = m;
gravity = g;
}
void update(float targetX, float targetY,float si) {
float forceX = (targetX - x) * stiffness;
float ax = forceX / mass;
vx = damping * (vx + ax);
x += vx;
float forceY = (targetY - y) * stiffness;
forceY += gravity;
float ay = forceY / mass;
vy = damping * (vy + ay);
y += vy;
}
void display(float nx, float ny,float si) {
noStroke();
float ran=random(-radius+5,5);
float r=radius+ran-si;
float co=random(0,255);
fill(co);
if (r>0){
ellipse(x, y, r, r);
}
}
}
you may find the four groups move with certain acceleration.and then i wanted to get audio line in to control the radius of the circles.and i got the following:
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup()
{
size(600, 600, P2D);
background(0);
smooth();
colorMode(HSB);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.STEREO, 10);
}
void draw()
{
fill(0,10);
strokeWeight(0);
rect(0,0,width,height);
for(int i = 0; i < in.bufferSize() - 1; i++)
{
float r=in.left.get(i);
Circle x=new Circle(mouseX,mouseY,r*2200);
x.display();
}
}
class Circle{
float x,y,ra;
Circle(float x1,float y1,float r1){
x=x1;
y=y1;
ra=r1;
}
void display(){
fill(random(0,255),255,255);
stroke(255);
strokeWeight(random(0,10));
ellipse(x-40,y-40,ra,ra);
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
but the circles appear along the movement of the cursor instead of four groups,and the acceleration is missing.so i tried the following:
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup()
{
size(600, 600, P2D);
background(0);
smooth();
colorMode(HSB);
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.STEREO, 10);
Circle x=new Circle(0,0,5);
}
void draw()
{
fill(0,10);
strokeWeight(0);
rect(0,0,width,height);
for(int i = 0; i < in.bufferSize() - 1; i++)
{
x.update(mouseX,mouseY);
x.display(in.left.get(i));
}
}
class Circle{
float x,y,ra,mass;
float stiffness = 0.2;
float damping = 0.7;
Circle(float x1,float y1,float m){
x=x1;
y=y1;
mass=m;
}
void update(float targetX, float targetY) {
float forceX = (targetX - x) * stiffness;
float ax = forceX / mass;
vx = damping * (vx + ax);
x += vx;
float forceY = (targetY - y) * stiffness;
float ay = forceY / mass;
vy = damping * (vy + ay);
y += vy;
}
void display(float r1){
ra=r1;
fill(random(0,255),255,255);
stroke(255);
strokeWeight(random(0,10));
ellipse(x-40,y-40,ra,ra);
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
But when running this code, it shows "The field component x is not visiable" on that red part.anyone know why??
Waiting for your help~~~
1