“Curtain” by Jared Counts
https://openprocessing.org/sketch/20140
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/2.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution ShareAlike
Archived Sketch
This sketch is created with an older version of Processing,
and doesn't work on browsers anymore.
View Source Code
Curtain
Counts
xxxxxxxxxx
// The Link class is used for handling constraints between particles.
class Link {
float restingDistance;
float stiffness;
Particle p1;
Particle p2;
// the scalars are how much "tug" the particles have on each other
// this takes into account masses and stiffness, and are set in the Link constructor
float scalarP1;
float scalarP2;
// if you want this link to be invisible, set this to false
boolean drawThis = true;
Link (Particle which1, Particle which2, float restingDist, float stiff) {
p1 = which1; // when you set one object to another, it's pretty much a reference.
p2 = which2; // Anything that'll happen to p1 or p2 in here will happen to the paticles in our array
restingDistance = restingDist;
stiffness = stiff;
// although there are no differences in masses for the curtain,
// this opens up possibilities in the future for if we were to have a fabric with particles of different weights
float im1 = 1 / p1.mass; // inverse mass quantities
float im2 = 1 / p2.mass;
scalarP1 = (im1 / (im1 + im2)) * stiffness;
scalarP2 = (im2 / (im1 + im2)) * stiffness;
}
void constraintSolve () {
// calculate the distance between the two particles
PVector delta = PVector.sub(p1.position, p2.position);
float d = sqrt(delta.x * delta.x + delta.y * delta.y);
float difference = (restingDistance - d) / d;
// if the distance is more than curtainTearSensitivity, the cloth tears
// it would probably be better if force was calculated, but this works
if (d > curtainTearSensitivity)
p1.removeLink(this);
// P1.position += delta * scalarP1 * difference
// P2.position -= delta * scalarP2 * difference
p1.position.add(PVector.mult(delta, scalarP1 * difference));
p2.position.sub(PVector.mult(delta, scalarP2 * difference));
}
void draw () {
if (drawThis)
line(p1.position.x, p1.position.y, p2.position.x, p2.position.y);
}
}
See More Shortcuts