I'm after a lib which was created a few years back but all the download links are out of date. Does anyone have it and if so could they send it to me? The link to the library is below.
was hoping someone might be able to help me out with a toxiclibs related problem. I have a TriangleMesh that I'm building around points but it seems to be doing something a bit strange....when I instruct the mesh to build it doesn't do it immediately as with most examples I have seen. Instead it grows slowly and slows the sketch down considerable. I also have problems with it running out of memory after a while.
Is this something to do with how I have it set up? I would really appreciate someone having a look for me. I have posted part of the sketch containing the mesh below in case anyone can spot any glaring errors.
There is a video of an early experiment on my vimeo page which shows what I mean when I describe the mesh as 'growing' (vimeo.com/33283368).
could someone point me in the right direction....I have a sketch (attached) to do with optimal paths based on a particle and springs system. It's working how I want but I need to create a mesh around the 'threads' to give them thickness. The mesh needs to branch where the threads separate and thicken where there are more threads.
The threads themselves never really branch as they don't actually connect and that is why I was thinking some sort of marching cubes algorithm would suit. The threads are made up of a set of springs and particles.
I think the volumeutils part of the toxiclibs library will do what I want but I'm really not sure how to start implementing it. If anyone fancies having a quick look at my sketch and has any ideas on how best to implement the toxiclibs library I'd really appreciate it!
thanks, farley
in my sketch:
// first phase
'a' initiates attraction between primary springs
'p' turns particles on/off
// second phase
'm' makes secondary springs
'a' initiates attraction between secondary springs
has anyone had the problem where processing exports curves using curveVertex() to pdf as a series of very short lines? It's making things difficult because it makes the illustrator file size huge!
quick question about ContolP5 Sliders.....does anyone know if you can reposition text? I want the name of the slider to be below the slider itself rather than at the end on the right? I'm sure it's possible but I can't find it anywhere!
I was hoping someone could help me with this pretty basic problem. I'm trying to model the attraction forces of a web of woolen threads to one another when they are wet. I have developed my script so that there are a number of threads within a bounding box, composed of particles and springs. All I have to do now is implement the attraction forces between the particles so the threads 'bundle'. However, I am having difficulty working out how to access the particle arraylists for each thread. This is important as my particle class contains a function called attraction() where the particle looks through the relevant arraylist and calculates its distance to that particle. This distance decides whether the function is initiated or not.
If anyone fancies a quick glance at my script and can offer any suggestions I would be very appreciative!
Thanks,
Farley
// IMPORT EXTERNAL LIBRARIES
import peasy.*; // the camera library
import processing.opengl.*; // openGL library
/*------------------------------------------------------------------
*** GLOBAL VARIABLES ***
------------------------------------------------------------------*/
//----------declare the camera
PeasyCam theCamera;
//----------declare the environment
int boundingBoxX = 600;
int boundingBoxY = 600;
int boundingBoxZ = 1200;
// spring variables
float SPRING_RESTLENGTH = 8.0; // the length a spring is at rest
float SPRING_DAMPING = 0.3; // equiv hydraulic damping of a piston
//----------declare the mid particles
int numParticles = 10;
//----------declare threads
int numThreads = 5;
//----------declare thread list
ArrayList threadList = new ArrayList();
/*------------------------------------------------------------------
*** GLOBAL SETUP ***
------------------------------------------------------------------*/
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
PVector pos;
PVector vel;
PVector acc;
float pSize;
boolean pFixed;
ArrayList conSprings = new ArrayList();
ArrayList partList = new ArrayList();
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Particle(PVector pos_) {
pos = pos_;
vel = new PVector();
acc = new PVector();
pSize = 10.0;
pFixed = false;
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
//----------MOVE AND DRAW TO SCREEN
void update() {
if (pFixed==false) {
updatePos();
//attraction();
}
showMe();
}
//----------SOLVE THE SPRINGS
void solveForce() {
if (pFixed==false) {
Particle otherP;
PVector sumForces = new PVector();
//sumForces.add(gravity);
sumForces.add(acc);
// loop thru our connections
for (int i = 0; i < conSprings.size(); ++i) {
// get a spring
Spring s = (Spring) conSprings.get(i);
// get other end of spring
if ( s.p00 == this ) {
otherP = s.p01;
}
else {
otherP = s.p00;
}
// calculate the push/pull of spring
PVector vecBet = PVector.sub(otherP.pos, pos);
float currLen = vecBet.mag();
float desiredLen = currLen-SPRING_RESTLENGTH;
vecBet.normalize();
vecBet.mult(desiredLen/2);
// add this force to our sum of forces
sumForces.add(vecBet);
}
// apply a damping to the force
sumForces.mult(SPRING_DAMPING);
// add the resultant force to our vel
vel.add(sumForces);
}
}
void updatePos() {
vel.limit(2);
pos.add(vel);
acc = new PVector(0, 0, 0);
//-------------------
/*pos.add(vel); // move the particle
vel.mult(0); */ // reset the vel for next time
}
/*void attraction() {
PVector steer = new PVector();
int count = 0;
for (int i = 0; i < ??????????.size(); i++) {
// get a PVector from the list
Particle tmpPart = (Particle) ?????????.get(i);
float distance = PVector.dist(tmpPart.pos, pos);
if (distance > 0 && distance < 100) {
PVector vecBetween = PVector.sub(tmpPart.pos, pos);
// get the length of the vector
vecBetween.normalize();
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
// declare all the class variables
Particle p00;
Particle p01;
int col;
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Spring (Particle INPUT_00, Particle INPUT_01, int col_) {
// assign all the class variables
p00 = INPUT_00;
p01 = INPUT_01;
col = col_;
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
//----------declare particle list
ArrayList particleList = new ArrayList();
//----------declare spring list
ArrayList springList = new ArrayList();
//----------declare the springs
Spring s0, s1;
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Thread() {
//----------make the particles
// make vectors
PVector tmpPos1 = new PVector(random(boundingBoxX), random(boundingBoxY), 0);
PVector tmpPos2 = new PVector(random(boundingBoxX), random(boundingBoxY), boundingBoxZ);
// sub end vectors
PVector vecBetween = PVector.sub(tmpPos1, tmpPos2);
// divide vecBetween by 10
vecBetween.div(numParticles);
for (int i = 0; i < numParticles+1; i++) {
// scale vecBetween by i
PVector vecScale = PVector.mult(vecBetween, i);
// add new vector to end vector
PVector newVec = PVector.add(vecScale, tmpPos2);
// create new Particle at newVec
Particle tmpPart = new Particle(newVec);
// fix end particles
if ( i == 0 || i == numParticles) {
tmpPart.fixMe();
}
// add particle to list
particleList.add(tmpPart);
}
//----------make the springs
for (int i = 0; i < particleList.size(); i++) {
if (i > 0) {
int col = i*20;
Particle p1 = (Particle) particleList.get(i);
Particle p2 = (Particle) particleList.get(i-1);
s0 = new Spring(p1, p2, col);
springList.add(s0);
p1.addSpring(s0);
p2.addSpring(s0);
}
}
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
void createThread() {
for (int i = 0; i < particleList.size(); i++) {
Particle tmpPart = (Particle) particleList.get(i);
tmpPart.solveForce();
}
for (int i = 0; i < particleList.size(); i++) {
Particle tmpPart = (Particle) particleList.get(i);
tmpPart.update();
}
}
void createSprings() {
for (int i = 0; i < springList.size(); i++) {
// get a spring from the arraylist
Spring currS = (Spring) springList.get(i);
currS.showMe();
}
}
}
quick question....what is the best way to create a chain locked at either end which consists of points equidistant from one another connected by springs? I know how to do this if the chain is parallel to an axis, e.g.
for (int i = 0; i < 10; i ++) {
Particle p = new Particle (i*10, 0, 0);
}
but what if the direction of the lines is random? My initial thoughts are to calculate the distance between the vectors of the 2 static points and divide by (for example) 10 and place a point at each new vector.
Does this sound sensible? Does anyone have any examples of this?
I've attached an image of a sketch I have just done but the static points are connected by a single line and not a chain of points and springs.
Does anyone know why my slider controls aren't working how I want? Basically I have sliders for the number of surface_attractors, interstitial_attractors, x_particles and y_particles and I want the number of each of these to change as per their respective sliders.
The x_particles and y_particles seem to be sort of working although if you move the slider above the original variable input you get an error. I also want the 'fixed' particles, shown in blue, to move as the grid is changes in the x and y direction so their position at the boundary of the surface (in the x direction) remains.
I also want the number of attractors to change as per the sliders but I cannot get that working at all! I realise that my problems come from the fact that the arraylists holding the attractors are initialised in the setup via mesh.init(), so cannot be updated. How can I amend my script to accomodate this?
I know this might be quite a lot of work and the script is quite long (and probably messy!!), but I'd really appreciate some pointers. Hopefully i've explained myself. I have posted the script below.
Basically what I'm trying to make is 2 undulating surfaces, the overall size of which can be changed via sliders, which respond to attractors, the amount of which can again be varied.
Cheers guys, and thanks for the help!!
// IMPORT EXTERNAL LIBRARIES
import processing.pdf.*;
import processing.opengl.*; // openGL library
import peasy.*; // the camera library
import controlP5.*; // the interface library
/*------------------------------------------------------------------
*** GLOBAL VARIABLES ***
------------------------------------------------------------------*/
// particle variables
int X_PARTICLES = 28;
int Y_PARTICLES = 70;
// x and y increments
int xInc = 12;
int yInc = 12;
// environment
int bBoxX = X_PARTICLES * xInc;
int bBoxY = Y_PARTICLES * yInc;
int bBoxZ = 100;
// spring variables
//PVector gravity = new PVector(0, 0, 0);
float SPRING_REST_LENGTH = 8.0; // the length a spring is at rest
float SPRING_DAMPING_FORCE = 0.3; // equiv hydraulic damping of a piston
// ArrayLists of attractors
ArrayList attList1 = new ArrayList();
ArrayList attList2 = new ArrayList();
ArrayList attList3 = new ArrayList();
int SURFACE_ATTRACTORS = 20;
int INTERSTITIAL_ATTRACTORS = 2;
//----------draw attractors
for (int i = 0; i < attList1.size(); ++i) {
Attractor myAtt = (Attractor) attList1.get(i);
myAtt.run();
myAtt.display();
}
for (int i = 0; i < attList2.size(); ++i) {
Attractor myAtt = (Attractor) attList2.get(i);
myAtt.run();
myAtt.display();
}
for (int i = 0; i < attList3.size(); ++i) {
Attractor myAtt = (Attractor) attList3.get(i);
myAtt.run();
myAtt.display();
}
if (export) {
//topMesh.exportToTxt(1);
//bottomMesh.exportToTxt(2);
}
if (record) {
endRaw();
record = false;
}
// makes the gui stay on top of elements
// drawn before.
hint(DISABLE_DEPTH_TEST);
gui();
}
/*-------------------------------------------------------------
*** MAKE PARTICLES, SPRINGS AND ATTRACTORS ***
--------------------------------------------------------------*/
void initMesh() {
bottomMesh = new Mesh(bBoxZ, attList1, attList3);
topMesh = new Mesh(meshHeight, attList2, attList3);
}
void keyPressed() {
if (key == 'p' || key == 'P') {
record = true;
export = true;
}
}
tmpMeshHeight = meshHeight_;
particleList = new Particle[X_PARTICLES][Y_PARTICLES];
springList = new ArrayList();
faceList = new ArrayList();
tmpAttList1 = attList_;
tmpAttList2 = attList2_;
//-----initialise particles
for (int i=0; i < X_PARTICLES; ++i) {
for (int j=0; j < Y_PARTICLES; ++j) {
// make a vector
PVector tmpPos = new PVector(i*xInc, j*yInc, tmpMeshHeight);
// make a particle
Particle newP = new Particle(tmpPos, tmpAttList1, tmpAttList2);
// fix perimeter particles
if ( (i < X_PARTICLES && j==0) || (i < X_PARTICLES && j==Y_PARTICLES-1) ) {
newP.fixMe();
}
// store the particle in our list
particleList[i][j] = newP;
}
}
//-----initialise springs
for (int i=0; i < X_PARTICLES; ++i) {
for (int j=0; j < Y_PARTICLES; ++j) {
if ( i>0 ) {
s0 = new Spring( particleList[i][j], particleList[i-1][j] );
springList.add(s0);
particleList[i][j].addSpring(s0);
particleList[i-1][j].addSpring(s0);
}
if ( j>0 ) {
s1 = new Spring( particleList[i][j], particleList[i][j-1] );
springList.add(s1);
particleList[i][j].addSpring(s1);
particleList[i][j-1].addSpring(s1);
}
}
}
//-----initialise faces
for (int i=0; i<X_PARTICLES; ++i) {
for (int j=0; j<Y_PARTICLES; ++j) {
if (i>0 && j>0) {
f0 = new Face( particleList[i][j], particleList[i][j-1], particleList[i-1][j-1], particleList[i-1][j], tmpMeshHeight );
faceList.add(f0);
}
}
}
// print how many springs we made
println("Number of springs " + springList.size() );
//-----initialise surface attractors
for (int i = 0; i < SURFACE_ATTRACTORS; ++i) {
//if (i < SURFACE_ATTRACTORS) {
PVector aPos = new PVector(random(0, bBoxX), random(150, bBoxY-150), tmpMeshHeight);
PVector aVel = new PVector(random(0.5, 2.5), random(0.5, 2.5), 0);
tmpAtt = new Attractor(aPos, aVel, 20);
tmpAttList1.add(tmpAtt);
}
//-----initialise middle attractors
for (int i = 0; i < INTERSTITIAL_ATTRACTORS; ++i) {
//if (i < SURFACE_ATTRACTORS) {
PVector aPos = new PVector(random(0, bBoxX), random(150, bBoxY-150), midAttHeight+30);
PVector aVel = new PVector(random(1, 2), random(1, 2), 0);
tmpAtt = new Attractor(aPos, aVel, 150);
tmpAttList2.add(tmpAtt);
}
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
//----------update particle positions
for (int i=0; i<X_PARTICLES; ++i) {
for (int j=0; j<Y_PARTICLES; ++j) {
particleList[i][j].update();
}
}
}
void createSprings() {
for (int i=0; i<springList.size(); i++) {
// get a spring from the arraylist
Spring currS = (Spring) springList.get(i);
currS.showMe();
}
}
void createFaces() {
for (int i=0; i<faceList.size(); i++) {
// get a spring from the arraylist
Face currF = (Face) faceList.get(i);
//currF.showMe();
}
}
void exportToTxt(int num_) {
int num = num_;
output = createWriter("data/points" + num + ".txt");
for (int i = 0; i < X_PARTICLES; i++) {
for (int j = 0; j < Y_PARTICLES; j++) {
output.println (particleList[i][j].pos.x + "," + particleList[i][j].pos.y + "," + particleList[i][j].pos.z);
}
}
output.flush();
output.close();
println("points have been exported");
exit();
}
}
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
int pID;
PVector pos;
PVector vel;
PVector acc;
float pSize;
boolean pFixed;
ArrayList conSprings = new ArrayList();
ArrayList tmpAttList1;
ArrayList tmpAttList2;
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Particle(PVector STARTPOS, ArrayList attList1_, ArrayList attList2_) {
// assign all the class variables
pos = STARTPOS;
vel = new PVector();
acc = new PVector();
pSize = 10.0;
pID = 0;
pFixed = false;
tmpAttList1 = attList1_;
tmpAttList2 = attList2_;
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
//----------MOVE AND DRAW TO SCREEN
void update() {
if (pFixed==false) {
updatePos();
attraction();
attractionB();
}
showMe();
}
//----------SOLVE THE SPRINGS
void solveForce() {
if (pFixed==false) {
Particle otherP;
PVector sumForces = new PVector();
//sumForces.add(gravity);
sumForces.add(acc);
// loop thru our connections
for (int i = 0; i<conSprings.size(); ++i) {
// get a spring
Spring s = (Spring) conSprings.get(i);
// get other end of spring
if ( s.p00 == this ) {
otherP = s.p01;
}
else {
otherP = s.p00;
}
// calculate the push/pull of spring
PVector vecBet = PVector.sub(otherP.pos, pos);
float currLen = vecBet.mag();
float desiredLen = currLen-SPRING_REST_LENGTH;
vecBet.normalize();
vecBet.mult(desiredLen/2);
// add this force to our sum of forces
sumForces.add(vecBet);
}
// apply a damping to the force
sumForces.mult(SPRING_DAMPING_FORCE);
// add the resultant force to our vel
vel.add(sumForces);
}
}
//----------Add a spring to my list of springs
void addSpring(Spring S) {
// store this spring
conSprings.add(S);
}
void attraction() {
PVector steer = new PVector();
int count = 0;
for (int i = 0; i < tmpAttList1.size(); i++) {
// get a PVector from the list
Attractor tmpAtt = (Attractor) tmpAttList1.get(i);
float distance = PVector.dist(tmpAtt.aPos, pos);
if (distance > 0 && distance < attRange+21) {
PVector vecBetween = PVector.sub(tmpAtt.aPos, pos);
// get the length of the vector
vecBetween.normalize();
void attractionB() {
PVector steer = new PVector();
int count = 0;
for (int i = 0; i < tmpAttList2.size(); i++) {
// get a PVector from the list
Attractor tmpAtt = (Attractor) tmpAttList2.get(i);
float distance = PVector.dist(tmpAtt.aPos, pos);
if (distance > 0 && distance < attRange+31) {
PVector vecBetween = PVector.sub(tmpAtt.aPos, pos);
// get the length of the vector
vecBetween.normalize();
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
// declare all the class variables
Particle p00;
Particle p01;
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Spring (Particle INPUT_00, Particle INPUT_01) {
// assign all the class variables
p00 = INPUT_00;
p01 = INPUT_01;
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
was hoping someone could give me some much needed advise on the following issue.
Basically I am trying to set up a grid of points (which I have achieved) in which each point moves according to a sine wave. I have attached an image below which shows something I did in a parametric design tool called grasshopper, but I am now trying to achieve the same effect using processing. The way the original system worked was that it divided the grid into groups of rows of points and then altered the position of these points along the y direction using graphs which were basically visual representations of different sine calculations. Because the sine calculation (or graph) was different for each group it created variation and randomness across the grid.
I am switching to processing for several reasons, but mainly because I want to create an 'animation' which shows the grid moving.
I really need help with what is (probably) a pretty basic question. I've got a 2D grid which I want to distort in the Y axis to create something pretty similar to the image below. The lines should never overlap but i should be able to control the points positions via a slider.
I have done this in other parametric tools like grasshopper using graphs (e.g. sin) to control the location of points but I want to achieve this in processing and I'm not sure how it can be done.
Below is an image of what I hope to achieve and a really basic Processing Sketch of a 2D grid I put together, to get the ball rolling.
Thanks in advance!!
Farley
int numNodesX = 20;
int numNodesY = 10;
int xInc = 50;
int yInc = 35;
int bBoxX = numNodesX * xInc;
int bBoxY = numNodesY * yInc;
Node[][] nodeList;
ArrayList lineList;
void setup() {
size(bBoxX+100, bBoxY+100);
nodeList = new Node[numNodesX][numNodesY];
for (int i=0; i<numNodesX; ++i) {
for (int j=0; j<numNodesY; ++j) {
// make a vector
PVector tmpPos = new PVector(i*xInc+50, j*yInc+50);
// make a particle
Node newN = new Node(tmpPos);
nodeList[i][j] = newN;
}
}
}
void draw() {
background(250);
for (int i=0; i<numNodesX; ++i) {
for (int j=0; j<numNodesY; ++j) {
nodeList[i][j].update();
}
}
for (int i=0; i<numNodesX; i++) {
for (int j=0; j<numNodesY; ++j) {
I was hoping someone could help me. I've got a sketch (posted below) which calls 2 grids that react to attractors to create an undulating surface. However, I want to render it so I can show heights, i.e. deviation from the base of each grid, and this should change as the grid changes.
I guess it might be a case of creating a mesh and then putting in some variables so the colour changes from green to yellow for example depending on the points deviation from a base vector. If some one could give me some clues on creating and applying meshes (or if theres a better way) it would be really helpful.Please feel free to muck around with the script!!
Cheers, Farley
(ps, sorry if the scripts a bit of a mess!!)
// IMPORT EXTERNAL LIBRARIES
import processing.pdf.*;
import processing.opengl.*; // openGL library
import peasy.*; // the camera library
import controlP5.*; // the interface library
/*------------------------------------------------------------------
*** GLOBAL VARIABLES ***
------------------------------------------------------------------*/
// ArrayLists of stuff
ArrayList springList1 = new ArrayList();
ArrayList springList2 = new ArrayList();
// particle variables
int numParticlesX = 28;
int numParticlesY = 70;
// particle list
Particle[][] particleList1 = new Particle[numParticlesX][numParticlesY];
Particle[][] particleList2 = new Particle[numParticlesX][numParticlesY];
// x and y increments
int xInc = 12;
int yInc = 12;
// environment
int bBoxX = numParticlesX * xInc;
int bBoxY = numParticlesY * yInc;
int bBoxZ = 400;
// spring variables
//PVector gravity = new PVector(0, 0, 0);
float SPRING_RESTLENGTH = 8.0; // the length a spring is at rest
float SPRING_DAMPING = 0.3; // equiv hydraulic damping of a piston
// ArrayLists of attractors
ArrayList attList1 = new ArrayList();
ArrayList attList2 = new ArrayList();
ArrayList attList3 = new ArrayList();
int numAttractors = 12;
int attMAXHEIGHT = 168;
// declare meshes
Mesh bottomMesh;
Mesh topMesh;
/*------------------------------------------------------------------
*** GLOBAL SETUP ***
------------------------------------------------------------------*/
//----------draw attractors
for (int i = 0; i < numAttractors; ++i) {
Attractor myAtt = (Attractor) attList1.get(i);
myAtt.run();
}
for (int i = 0; i < numAttractors; ++i) {
Attractor myAtt = (Attractor) attList2.get(i);
myAtt.run();
}
for (int i = 0; i < 4; ++i) {
Attractor myAtt = (Attractor) attList3.get(i);
myAtt.run();
}
if (record) {
endRaw();
record = false;
}
}
/*-------------------------------------------------------------
*** MAKE PARTICLES, SPRINGS AND ATTRACTORS ***
--------------------------------------------------------------*/
void initMesh() {
bottomMesh = new Mesh(bBoxZ, particleList1, springList1, attList1, attList3);
topMesh = new Mesh(bBoxZ+bBoxX, particleList2, springList2, attList2, attList3);
}
for (int i=0; i<numParticlesX; ++i) {
for (int j=0; j<numParticlesY; ++j) {
// make a vector
PVector tmpPos = new PVector(i*xInc, j*yInc, meshHeight);
// make a particle
Particle newP = new Particle(tmpPos, tmpAttList1, tmpAttList2);
// fix perimeter particles
if ( (i < numParticlesX && j==0) || (i < numParticlesX && j==numParticlesY-1) ) {
newP.fixMe();
}
// store the particle in our list
particleList[i][j] = newP;
}
}
//-----initialise springs
for (int i=0; i<numParticlesX; ++i) {
for (int j=0; j<numParticlesY; ++j) {
if ( i>0 ) {
s0 = new Spring( particleList[i][j], particleList[i-1][j] );
//springList.add(s0);
particleList[i][j].addSpring(s0);
particleList[i-1][j].addSpring(s0);
}
if ( j>0 ) {
s1 = new Spring( particleList[i][j], particleList[i][j-1] );
springList.add(s1);
particleList[i][j].addSpring(s1);
particleList[i][j-1].addSpring(s1);
}
}
}
// print how many springs we made
println("Number of springs " + springList.size() );
//-----initialise surface attractors
for (int i = 0; i < numAttractors; ++i) {
//if (i < numAttractors) {
PVector aPos = new PVector(random(0, bBoxX), random(150, bBoxY-150), meshHeight);
PVector aVel = new PVector(random(1, 1.5), random(1, 2), 0);
tmpAtt = new Attractor(aPos, aVel);
tmpAttList1.add(tmpAtt);
}
//-----initialise middle attractors
for (int i = 0; i < 2; ++i) {
//if (i < numAttractors) {
PVector aPos = new PVector(random(0, bBoxX), random(150, bBoxY-150), 568);
PVector aVel = new PVector(random(1, 1.5), random(1, 2), 0);
tmpAtt = new Attractor(aPos, aVel);
tmpAttList2.add(tmpAtt);
}
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
//----------update particle positions
for (int i=0; i<numParticlesX; ++i) {
for (int j=0; j<numParticlesY; ++j) {
particleList[i][j].update();
}
}
}
void createSprings() {
for (int i=0; i<springList.size(); i++) {
// get a spring from the arraylist
Spring currS = (Spring) springList.get(i);
currS.showMe();
}
}
}
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
int pID;
PVector pos;
PVector vel;
PVector acc;
float pSize;
boolean pFixed;
ArrayList conSprings = new ArrayList();
ArrayList tmpAttList1;
ArrayList tmpAttList2;
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Particle(PVector STARTPOS, ArrayList attList1_, ArrayList attList2_) {
// assign all the class variables
pos = STARTPOS;
vel = new PVector();
acc = new PVector();
pSize = 10.0;
pID = 0;
pFixed = false;
tmpAttList1 = attList1_;
tmpAttList2 = attList2_;
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
//----------MOVE AND DRAW TO SCREEN
void update() {
if (pFixed==false) {
updatePos();
attraction();
attractionB();
}
//showMe();
}
//----------SOLVE THE SPRINGS
void solveForce() {
if (pFixed==false) {
Particle otherP;
PVector sumForces = new PVector();
//sumForces.add(gravity);
sumForces.add(acc);
// loop thru our connections
for (int i = 0; i<conSprings.size(); ++i) {
// get a spring
Spring s = (Spring) conSprings.get(i);
// get other end of spring
if ( s.p00 == this ) {
otherP = s.p01;
}
else {
otherP = s.p00;
}
// calculate the push/pull of spring
PVector vecBet = PVector.sub(otherP.pos, pos);
float currLen = vecBet.mag();
float desiredLen = currLen-SPRING_RESTLENGTH;
vecBet.normalize();
vecBet.mult(desiredLen/2);
// add this force to our sum of forces
sumForces.add(vecBet);
}
// apply a damping to the force
sumForces.mult(SPRING_DAMPING);
// add the resultant force to our vel
vel.add(sumForces);
}
}
//----------Add a spring to my list of springs
void addSpring(Spring S) {
// store this spring
conSprings.add(S);
}
void attraction() {
PVector steer = new PVector();
int count = 0;
for (int i = 0; i < tmpAttList1.size(); i++) {
// get a PVector from the list
Attractor tmpAtt = (Attractor) tmpAttList1.get(i);
float distance = PVector.dist(tmpAtt.aPos, pos);
if (distance > 0 && distance < attMAXHEIGHT+1) {
PVector vecBetween = PVector.sub(tmpAtt.aPos, pos);
// get the length of the vector
vecBetween.normalize();
void attractionB() {
PVector steer = new PVector();
int count = 0;
for (int i = 0; i < tmpAttList2.size(); i++) {
// get a PVector from the list
Attractor tmpAtt = (Attractor) tmpAttList2.get(i);
float distance = PVector.dist(tmpAtt.aPos, pos);
if (distance > 0 && distance < attMAXHEIGHT+1) {
PVector vecBetween = PVector.sub(tmpAtt.aPos, pos);
// get the length of the vector
vecBetween.normalize();
/*------------------------------------------------------------------
*** CLASS VARIABLES ***
------------------------------------------------------------------*/
// declare all the class variables
Particle p00;
Particle p01;
/*------------------------------------------------------------------
*** CLASS CONSTRUCTOR ***
------------------------------------------------------------------*/
Spring (Particle INPUT_00, Particle INPUT_01) {
// assign all the class variables
p00 = INPUT_00;
p01 = INPUT_01;
}
/*------------------------------------------------------------------
*** CLASS FUNCTIONS ***
------------------------------------------------------------------*/
could someone give me some much needed advise/pointers on how to achieve an undulating landscape in processing. I have posted below a sketch I'm working on. Basically I want an array of attractors moving randomly top of the grid of nodes. These attractors should distort the grid by moving those nodes that are within a defined distance in the z direction (+ or -). The movement of these nodes should be fluid in their movement.
My next step will be to implement some springs between the nodes so the grid becomes more like a surface or undulating landscape....or I was thinking that i should tie the nodes to a mesh and define this as the spring to achieve this effect. Does this sound right? Any advise comments would be gratefully received!
The pic below hopefully gives an idea of the overall surface form I'm trying to achieve.
could someone give me some much needed advise/pointers on how to achieve an undulating landscape in processing. I have posted below a sketch I'm working on. Basically I want an array of attractors moving randomly top of the grid of nodes. These attractors should distort the grid by moving those nodes that are within a defined distance in the z direction (+ or -). The movement of these nodes should be fluid in their movement.
My next step will be to implement some springs between the nodes so the grid becomes more like a surface or undulating landscape....or I was thinking that i should tie the nodes to a mesh and define this as the spring to achieve this effect. Does this sound right? Any advise comments would be gratefully received!
The pic below hopefully gives an idea of the overall surface form I'm trying to achieve.
has anyone here had any experience of modelling physical material properties, e.g. the curvature of a piece of plywood, and creating a digital model of that (preferably in real time) in processing. My aim is to create a surface that is representative of the physical model and evaluate it in an engineering software, checking stresses etc.
Can anyone recommend any tools, bits of hardware etc, and any sites that have useful code for this sort of thing.
has anyone had the problem of duplicate lines when exporting a pdf from processing and opening in illustrator. I'm using the pdf export library. Should I be using a different library or is there a way round the problem (without deleting the lines in illustrator)?
what is the best way to distort a plane in the Z axis. Basically I am trying to create an analogous terrain of hills and valleys which is pulled up/pushed down by repellers/attractors that might move along the surface. If anyone has any examples of something similar or even a quick description of the direction I should be heading in, it would be really useful!
I'm quite confident using vectors but haven't touched much on physics. Is this where I should be heading, if so what library do you recommend?
I'm new to Processing so probably a fairly basic question but:
I have set up a 3D arraylist of nodes (points within a boundarybox).
I need to draw fibres (lines) between each node on the x axis moving incrementally along the y and z axis. I have created a very primitive fibre class...do I need to create a nested for loop to extract the necessary points?
Thanks,
Farley
void setup() {
nodeArray = new ArrayList();
for(int i = 0; i < numGroundX; i++) {
for(int j = 0; j < numGroundY; j++) {
for(int k = 0; k < numGroundZ; k++) {
Vec3D nodeOrigin = new Vec3D((i+0.5) * envX/numGroundX, (j+0.5) * envY/numGroundY, (k+0.5) * envZ/numGroundZ);
Node tmpNode = new Node(nodeOrigin);
nodeArray.add(tmpNode);
}
}
}
void draw() {
background(0);
for(int i = 0; i < nodeArray.size(); i++) {