Hi, I´ve made an skech wich consist in a wheel whith some hooks in wich you can hung some weights. So when you push a button, the wheel start to round depending on the weights you hang.
It works but since I have added some new improvements, sometimes you need to click several times on an icon to make it work.
Hi, Im having a mess with arraylist. I´ve made an skech wich consist in a wheel whith some hooks in wich you can hung some weights. So when you push a button, the wheel start to round depending on the weights you hang.
It works, but I tried to put a restart button. So when you push, the weights arraylist is suposed to be erased, but its strange because only some weights are erasen, not all. The code that erase the weights is at the end.
Hi, Im programming a videogame, and I would like it to have different screens. For exampe an introduction to the game and after the propper game, and after a different stage of the game.
As far as I know I can only have one draw function. I could solve the problem if I had different draws functions. Another solution is to use if, but I think there has to be better ways ¿What is the usual way to solve it?
Hi. I have a sketch in wich I create an arraylist of balls that flow in a pipe. Now I want to create diferent pipes, so I created a pipe class. I had a line inside the draw function that created new balls and was this:
Now I´ve moved this line inside the pipe class, for the balls to be created inside their pipe. The line is inside a function called inicialize() inside the pipe class.
A message appears:
the constructor pipes.ball (int, int) is undefined.
Hi, Some people who answer my posts paste codes with lines numbered. If I want to check the codes, I have to paste it in processing and delete the numbers. If I paste it in eclipse, this is not processing. There has to be something here that Im not understanding, or Im doing wrong
Hi, Im working on a sketch that have a lot of particles moving at the same time. Im trying to simulate water flow on a pipe. The sketch was OK till I started to draw the limit of the pipe. Then the sketch start to be too slow.
I´ve solve the problem changing the way I draw the borders, but I dont understand why my skectch was so slow, and I want to know about it to select in the future faster solutions. The instructions that draw the borders are few compared with the ones that draw the particles.
This is the code as it is now. The lines that draw the borders the slow way are writen at the end as comentaries:
float count;
int width=800;
int height=600;
float g=2;
ArrayList balls= new ArrayList();
float k=1;//factor to increment distance between balls
float c= 4;//maximun penetrance in walls
float vlim=10;//maximum speed
float population=1000;//population limit
float suck = 20;// distance of influence
float leftborder;
float rightborder;
float visc;
float pipediam = 600;
float middle;
float repulsion = 0.1;
float reslenght = 100;
float respoint;
I want to fill a surface with aleatory points, but if I do it with random I dont like the way it ends because there are some areas with many points and others empty. If I use noise, it doesnt fill the borders of the area.
I want something as particles of a fluid, or as trees in a forest. With an impression of dissorder, but without concentration or empty spaces.
I can do it with random and after separating points creating a force, but it has to be a more eficient way.
Hi, I once made a sketch of bouncing balls. Now I want to simulate a pipe in wich the fluid is hunk of little balls. I can make the sketch using fluid mechanics knodledge cause I know how balls should move, but I prefer let the balls move free adding forces and letting them bounce between them and with walls. I´ve tried to add viscosity so particles closest to walls should move slower.
By now I,ve made only a vertical pipe in wich particles that reach the botton returns upside. It should not be horizontal movement, but because of the parts of the program that separate balls between them or from the walls, there are little horizontal movement that end causing a lot of bouncing that shouldnt be. I dont want to force vertical movement because I want the particles moving free, because later I want to change the pipes direction.
Programming movement and physics brings always instability problems. I don´t know if Im facing this problem correctly. I know is hard to simulate it accurately.
I would like to know if Im making mistakes or not using the best way, or if there are other examples online of the same idea.
This is the code:
class ball{
PVector x;
PVector v;
color c;
int r=3;
float f = 0.1;
float g = 0.1;
float force;
ball(int x0, int y0){
x=new PVector(x0,y0);
v=new PVector(0,0);
}
void update(){
force = 0.05 * ( g/visc );
v.y = v.y + force ;
x.add(v);
v.mult(1-f);
}
void render(){
if (abs(x.x-middle)<0.4 * pipediam){
set(int(x.x),int(x.y),color(255));;
}
}
}
int width=800;
int height=600;
float g=2;
ArrayList balls= new ArrayList();
float k=1;//factor to increment distance between balls
float c= 4;//maximun penetrance in walls
float vlim=10;//maximum speed
float population=1000;//population limit
float suck = 10;// distance of influence
float leftborder;
float rightborder;
float visc;
float limitlayer = 10;
float pipediam = 100;
float middle;
void draw(){
fill (0,100);
rect(0,0,width, height);
for(int i=0;i<balls.size();i++){
ball b = (ball) balls.get(i);
// speed limit
if (b.v.y>vlim){b.v.y=vlim;}
// bounce against walls
if (b.x.x<b.r){b.v.x=abs(b.v.x);}
if (b.x.x>width-b.r){b.v.x=-abs(b.v.x);}
if (b.x.y>height-b.r){b.x.y = 0;}
//separate from walls
if(b.x.x>rightborder-b.r+c){b.x.x-=5;}
if(b.x.x<leftborder + b.r-c){b.x.x+=5;}
if(b.x.y>height-b.r+c){b.x.y-=5;}
//bounce between them
//viscosity
visc = 0.3 * (sq(15*(b.x.x - middle))/sq(15*pipediam/2));
//b.v.y = b.v.y - visc;
Hi, I've seen this line: for(int p: img.pixels) in a code. I´ve never seen this kind of for before. I´ve always seen the for (;;) kind. It seems p takes all the picture's pixels values, but I would like to see in general the way of using this for(:) structure
PImage picture;
Integer[] palette;
void setup(){
size(466, 520);
background(0);
picture = loadImage("kadinsky.jpeg");
image(picture,0,0);
palette = getPalette(picture);
for(int i = 0; i < palette.length; i++){
set(i % width, 330 + (i / width), palette[i]);
}
fill(255);
text("Number of pixels in image = " + picture.width * picture.height, 10, height - 40);
An array list is a resizable list ob objects. I´ve used it sometimes but now I simply need a resizable list of variables. In this case of colors, and it doesnt work. It doesnt seem to me that the solution is to make a class of colors. I thougt that I could use an arraylist of colors and it doesnt work. This is the line of the errror:
colors.add (new color (c));
This is the complete code, trying to get a color palette from a picture
class ColorHandler {
color[] palette ;
ColorHandler(){
}
void SetColor(PImage theimage){
color c;
boolean found;
ArrayList colors = new ArrayList ();
for (int i = 0; i < theimage.width; i++){
for (int j = 0; j < theimage. height; j++){
c= theimage.get(i,j);
found = FALSE;
for ( k = 0; k < colors.size; k++){
color thecolor = (color) colors.get(k);
if (thecolor == c){
found = TRUE;
}
}
if (!found){
colors.add (new color (c));
}
and I had a problem with the sentence: initTUIO(); it appears a message: "the function initTUIO() does not exist".
I`ve looked in google and I found TUIO library
http://www.tuio.org/?processing. I`ve instaled it and included the sentence:
import TUIO.*;
and still appears the same message. I`ve read the source code of the library and I don't find the initTUIO function in it.
Im trying to understand the MSAFluidDemo. The code is pasted below, and there are clases and functions that are used and are not defined in the library nor in the pde file. I´ve checked the source code of the library. The class ParticleSystem are not defined and not the updateTUIO() function
Im try to execute the MSAfluidDemo.pde. The code is pasted below. I´ve made a folder called msafluid inside another folder called libraries inside the sketchbox folder as I have done with others libraries that worked correctly. I´ve put the msafluid.jar inside msafluid folder, and MSAFluidDemo.pde inside a MSAFluidDemo folder inside scketchbook.
I receive a message " the mackage msafluid does not exist. You migh be missing a library"
I´ve executed MSAFluidDemo.pde from diferent places with the same result
// create fluid and set options
fluidSolver = new MSAFluidSolver2D((int)(FLUID_WIDTH), (int)(FLUID_WIDTH * height/width));
fluidSolver.enableRGB(true).setFadeSpeed(0.003).setDeltaT(0.5).setVisc(0.0001);
// create image to hold fluid picture
imgFluid = createImage(fluidSolver.getWidth(), fluidSolver.getHeight(), RGB);
// create particle system
particleSystem = new ParticleSystem();
// add force and dye to fluid, and create particles
void addForce(float x, float y, float dx, float dy) {
float speed = dx * dx + dy * dy * aspectRatio2; // balance the x and y components of speed with the screen aspect ratio
if(speed > 0) {
if(x<0) x = 0;
else if(x>1) x = 1;
if(y<0) y = 0;
else if(y>1) y = 1;
float colorMult = 5;
float velocityMult = 30.0f;
int index = fluidSolver.getIndexForNormalizedPosition(x, y);
if ( !drawing )
{
physics.tick();
if ( greyer < 255 )
greyer *= 1.11111;
if ( greyer > 255 )
greyer = 255;
}
else
{
if ( greyer >= 64 )
greyer *= 0.9;
}
background( 255 );
drawOldGrey();
}
void drawOldGrey()
{
stroke( 255 - greyer );
for ( int i = 0; i < tendrils.size()-1; ++i )
{
T3ndril t = (T3ndril)tendrils.get( i );
drawElastic( t );
}
void drawElastic( T3ndril t )
{
float lastStretch = 1;
for ( int i = 0; i < t.particles.size()-1; ++i )
{
Vector3D firstPoint = ((Particle)t.particles.get( i )).position();
Vector3D firstAnchor = i < 1 ? firstPoint : ((Particle)t.particles.get( i-1 )).position();
Vector3D secondPoint = i+1 < t.particles.size() ? ((Particle)t.particles.get( i+1 )).position() : firstPoint;
Vector3D secondAnchor = i+2 < t.particles.size() ? ((Particle)t.particles.get( i+2 )).position() : secondPoint;
//float springStretch = 2.5f/((Spring)t.springs.get( i )).stretch();
Spring s = (Spring)t.springs.get( i );
float springStretch = 2.5*s.restLength()/s.currentLength();
strokeWeight( (float)((springStretch + lastStretch)/2.0f) ); // smooth out the changes in stroke width with filter
lastStretch = springStretch;
if ( !drawing )
{
physics.tick();
if ( greyer < 255 )
greyer *= 1.11111;
if ( greyer > 255 )
greyer = 255;
}
else
{
if ( greyer >= 64 )
greyer *= 0.9;
}
background( 255 );
drawOldGrey();
}
void drawOldGrey()
{
stroke( 255 - greyer );
for ( int i = 0; i < tendrils.size()-1; ++i )
{
T3ndril t = (T3ndril)tendrils.get( i );
drawElastic( t );
}
void drawElastic( T3ndril t )
{
float lastStretch = 1;
for ( int i = 0; i < t.particles.size()-1; ++i )
{
Vector3D firstPoint = ((Particle)t.particles.get( i )).position();
Vector3D firstAnchor = i < 1 ? firstPoint : ((Particle)t.particles.get( i-1 )).position();
Vector3D secondPoint = i+1 < t.particles.size() ? ((Particle)t.particles.get( i+1 )).position() : firstPoint;
Vector3D secondAnchor = i+2 < t.particles.size() ? ((Particle)t.particles.get( i+2 )).position() : secondPoint;
//float springStretch = 2.5f/((Spring)t.springs.get( i )).stretch();
Spring s = (Spring)t.springs.get( i );
float springStretch = 2.5*s.restLength()/s.currentLength();
strokeWeight( (float)((springStretch + lastStretch)/2.0f) ); // smooth out the changes in stroke width with filter
lastStretch = springStretch;
to set the position of the new node (p) in relation to q that is other node. If the quantity to add is aleatory, I dont see why the lenght of the edges are all the same. The quantity to add is between -1 and 1 that is a very small quantity. I also don´t know what is position().x(). Position returns a pVector. Pvector.x is x coordinate, but what is x()?
1. I dont have the fade.png file, I dont know how it is.
2. I've taken a look to the code and I see that it is a particle that atracts other ones than appears in a random way throught the windows. I´ve modified the code to represent the particles as a point instead of using the fade.png. The particles appears at the beginning and all dissapear quickly. I´ve changed the atraction constant and they dissapear slowly, but they don't move. I vave no idea of why this is happening.
Hi, Im looking at the clothe example in physic lybrary.
Changing spring_strenght and spring _damping parameters, it happens strange things. So theese parameters are extremely sensible, and have a very few values possible to take. Why is this?
I dont understad what damp is.
I would like to have more tenses springs, and dont see the way to change it
I´ve seen this line of code in a contribuited library. I think this is a general question, so I post in this forum. I don´t know what is 0.5f, I've never seen a letter written after a numbre like that
I thought that in import command there I had to put the file name, that in this case is traer_physics_lib_src but in this case there is the name of the package...is a bit of a mess for me
Because there are more semicolons. But setPosition is cp5 method and if I write cp5.setPosition(20,20); Im not telling the element to set the position. setPosition refers to the Bang, so it should be a bang method, but it is not. I dont understand this. For example if later I want to change the bang position, I dont know how to do it.
Hi, Im trying to learn to use the control IP5 library. I've been reading this example code, accordion, and I can´t tell why the control are blue. I dont see any command where the control color is set. I guess it can be channged, but I dont know how:
/**
* ControlP5 Accordion
* arrange controller groups in an accordion like style.
*
* find a list of public methods available for the Accordion Controller
* at the bottom of this sketch. In the example below 3 groups with controllers
* are created and added to an accordion controller. Furthermore several key
* combinations are mapped to control individual settings of the accordion.
* An accordion comes in 2 modes, Accordion.SINGLE and Accordion.MULTI where the
* latter allows to open multiple groups of an accordion and the SINGLE mode only
* allows 1 group to be opened at a time.
*
* by Andreas Schlegel, 2012
*
www.sojamo.de/libraries/controlp5 *
*/
// create a new accordion
// add g1, g2, and g3 to the accordion.
accordion = cp5.addAccordion("acc")
.setPosition(40,40)
.setWidth(200)
.addItem(g1)
.addItem(g2)
.addItem(g3)
;
Im starting with processing and Im trying to learn about libraries. I've downloaded ControlIP5, and I see that it is a really huge library. I supose I will only use a few classes and methods from this library, but I need to find how each method works. Methods and classes desciptions. I read the references and I only find examples. Is there a place where I can find something as: this method receive theese parameters and do this. And the source font of each method?
My problem is to make the shades, that seems to be drawn eith a pencil in aleatorial way. I´ve try diferents ways and reald O`reilly books, but my results are far from being good