I want to precalculate a dynamic scene like the
Bouncy BubblesExample.
For that, i made a 2D-Array-PVector-return-method, which gives you all the positions of the single particles back.
The values that are going into the functions are the start positions and the start directions of the particles, and the value of how many steps should be calculated.
Now the problem, when you run the calculation (hit Arrow Key Up or Down), you can notice that only the balls with a lower array-id value are effecting the higher ones, but not vise versa. And this is where I'm stuck. I hope anyone could help me with this issue. Thx!
here the method:
PVector [][] fP(PVector [] posIn, PVector [] dir, int steps){
I wanna load a txt file and write some more data to it. I would need to combine the vals[0] with x.[i]... (i guess).
But I am not sure how to to bring them together, so that if I save and start the sketch again, x[] or y[] are getting always bigger... Simplified, draw, save, load and continue to draw...
Right now, I am just able to load the drawing from the previous running... but not to add more to the file...
I wanna make this very simple drawing tool without using mouseX, pmouseX, etc...
But how can i get an interruption when i stop drawing and than start again.
For example the array is at a value of 12 when i stop dragging the mouse, when i press again it should skip
number 13 in the array.
Do i need a return or a break funktion?
I would like to draw balls randomly postitioned with different sizes and also that they take the color of the background image, like in the shiffman example of the
pointillism sketch, exept the ellipses dont intersect with each other...
But there is a bug and i dont know how to fix it(float to array conversion).
I tried to integrate a sketch into my html code. It worked. But when I tried a sketch, which used a library, it didnt work anymore... is this normal or is there a way to use a libray within processing.js?
I have very problems to understand and to figure out an algorithm for a box collision detection.
Actually i wanted to use a library (fisica) for my purpose and wanted to implement it into html via processing.js. But seems the processing.js cannot read any imported libraries.
Really hope someone can give me some advice for a collision detection.
I a, trying to modify shiffmans multi-user/multi-client exaples (
multi-user,
multi-client) with the network library. What I noticed was that, when i use the readString() function, like in the examples, it always crashed down sooner or later.
Than i tried to write the datas separately. I wanna write four datas: mouseX, mouseY, pmouseX and pmouseY (4x "client.write(data);" ). Works well actually, never crashes. But it looks like the other client cant catch them in the correct order, so the lines always jumps.
Now im trying to write the datas with a byte[]. Dont seems to work as well (i am not sure if i set it up right). So my question, what is the best way to write datas with an array?
I tried this two codes form the daniel shiffman examples with the server and client example using the network library. Seems to work fine if i use the rigth IP adress from one to another computer. But how can i handle it to sending some datas over wide distances, like china... ? Didnt work, even i used the right IP adress... what could be the problem, it should be possible, right?
// SERVER
//
import processing.net.*;
// Declare a server
Server server;
PFont f;
int data = 0;
void setup() {
size(200,200);
// Create the Server on port 5204
server = new Server(this, 5204);
f = createFont("Arial",20,true);
}
void draw() {
background(255);
// Display data
textFont(f);
textAlign(CENTER);
fill(0);
text(data,width/2,height/2);
// Broadcast data (the number is continuously sent to all clients because write() is called every cycle through draw())
server.write(data);
// Arbitrarily changing the value of data randomly
data = (data + 1) % 256;
}
// The serverEvent function is called whenever a new client connects.
void serverEvent(Server server, Client client) {
println(" A new client has connected: "+ client.ip());
}
// CLIENT
//
// Import the net libraries
import processing.net.*;
// Declare a client
Client client;
// The data we will read from the server
int data;
void setup() {
size(200,200);
smooth();
// Create the Client
client = new Client(this,"127.0.0.1", 5204); //local host
I am trying get the rgb values of an image and to display them like the PS curves.
I found this code(1.code) below somewhere. The problem here is that, when i run the code in draw() modus the lines moving, but it shouldnt because its a static picture and the rgb values are still the same... and i wanna use it later for to get the values of a movie.
Anyway, how to get the total red value of an image? If i am using a loop and extract the red value it seems just to take the value from the very last pixel of the image (width,height), but it does not count every pixel of the whole image together... (2. code)
//1.CODE
PImage img;
void setup(){
size(200, 200);
img = loadImage("girl.png");
}
int[] histBright = new int[256];
int[] histR = new int[256];
int[] histG = new int[256];
int[] histB = new int[256];
void draw(){
image(img, 0, 0);
for (int i = 0; i < img.width; i++) {
for (int j = 0; j < img.height; j++) {
int bright = int(brightness(get(i, j)));
int r = int(red(get(i, j))); // gets values
int g = int(green(get(i, j)));
int b = int(blue(get(i, j)));
histBright[bright]++; //??
histR[r]++;
histG[g]++;
histB[b]++;
}
}
int histBrightMax = max(histBright);
int histRMax = max(histR);
int histGMax = max(histG);
int histBMax = max(histB);
stroke(255);
for (int i = 0; i < img.width; i += 3) {
int which = int(map(i,0, img.width, 30, 255));
int yBright = int(map(histBright[which], 0, 1500, img.height, 0));
int yR = int(map(histR[which], 0, 1000, img.height, 0));
int yG = int(map(histG[which], 0, 1000, img.height, 0));
int yB = int(map(histB[which], 0, 1000, img.height, 0));
stroke(255);
line(i, img.height, i, yBright);
stroke(255,0,0);
line(i+1, img.height, i+1, yR);
stroke(0,255,0);
line(i+2, img.height, i+2, yG);
stroke(0,0,255);
line(i+3, img.height, i+3, yB);
}
}//1.CODE END
//2.CODE
PImage img;
float r,g,b;
float X,Y;
void setup() {
size(243,202);
img = loadImage("girl.png");
frameRate(12);
smooth();
}
void draw() {
loadPixels();
// We must also call loadPixels() on the PImage since we are going to read its pixels.
img.loadPixels();
for (int y = 0; y < height; y++ ) {
for (int x = 0; x < width; x++ ) {
int loc = x + y*width;
// The functions red(), green(), and blue() pull out the three color components from a pixel.
r = red(img.pixels [loc]);
g = green(img.pixels[loc]);
b = blue(img.pixels[loc]);
// Image Processing would go here
// If we were to change the RGB values, we would do it here, before setting the pixel in the display window.