Okay, I can't get loadShader() to work. I'm just going through the
shader tutorial on Processing's site as a possible solution to the
question I asked yesterday, but I can't complete the simple task of loading my shader files.
So I was browsing through
Simon Page's work the other day in search of some inspiration for some sketches on my own, when I noticed a particular technique that he had used in several of his works that I wanted to recreate.
An example of the technique that I am talking about is below.
It appears that when a shape's fill is drawn on top of existing color from other shapes etc. the color is changed into a new color instead of simply overriding the previous color. That's kind of wordy but it makes sense if you just look at the picture.
Anyways, I was wondering if anyone had any idea of how this could be done in Processing.
I was wondering how I should send an ArrayList through a network... Do I need to break my ArrayList down into a String? That sounds like a lot of work, especially with a complex class. Does anyone have experience with this?
Okay, I'm completely stumped. I've been messing with .txt files of the English language, and I have 2 different versions. The first version I found was
here at Oracle's website. The second one was
here, which is a Scrabble dictionary. The one from Oracle strangely only has words that are less than 8 characters long, and has a total of 80,368 words in it. The second file has longer words, and has a total of 267,751 words.
My program runs through the text file and counts how many of each character there are. Also, it can figure out how many of each character there are for a specific word length (For example the most common letter might be 'e', but if it is an 8 letter word than the most common letter might be 'a' instead).
The program runs (I think) perfectly with the smaller text file, but only prints out 0's for the larger file. The way I've been running through my array of strings has been by running through just 1000 at a time, so the sketch doesn't crash with a giant for loop.
I don't really think that posting code would be helpful for a problem like this, but I can if you would like. Does anyone have any ideas? Thanks in advance
I have an arrayList of balls in a game similar to pong. I added a feature where about 10 balls are added in the middle of the screen so that there would be an explosion type thing... Then, I gave every ball an ID, and the only ball that matters (i.e. can score) is the ball with an ID of 1.
This code is for the explosion.. What it does is create 10 new balls, but starts at the highest ID so that there are no repeat ID's.
void moreballs() {
int maxid=-10;
for (int i=balls.size()-1;i>0;i--) {//loop through balls and get the highest ID
Ball b1=(Ball) balls.get(i);
if (b1.id>maxid) {
maxid=b1.id;
}
}
maxid+=1;
int limi=maxid+10;
for (int k=maxid;k<limi;k+=1) {//add to the balls array, but start with the highest id in the array so that there is no overlapping
balls.add(new Ball(w/2, h/2, k));//x,y,ID
}
}
So this does exactly what I need to do, but it means that the arrayList sometimes has gaps in the ID's. For example if you print the ID's of the list sometimes you get something like:
------------------------------
1
2
9
10
11
12
13
14
15
16
17
18
19
20
21
------------------------------
This leads to a problem in the
pointscored() section.
The point scored section does 2 things. If the ID is 1, it resets the ball and gives a point to whoever scored. If the ID isn't 1, then it should remove the ball. The problem is I can't get the second part to work. Everything I've been able to do has either created an out of memory error, an out of array index error, or just doesn't remove the balls.
void pointscored(int id) {
if (id==1) {
userscore+=1;
}
int j=0;
int limi=balls.size()-1;
for (int k=balls.size()-1;j<=limi;k-=1) {
if (k==id) {
j+=1;
if (id!=1) {
balls.remove(id);
}
}
}
}
When I run this code with the rest of the game I get mixed results. If just one ball "scores", then it freezes for about 5 seconds and continues. If multiple balls score, then the game freezes and gets an Index Out Of Bounds Exception.
I am trying to publish an android app. I've been trying to get my apk file so I can sign it and zipalign it, but I haven't been able to get started. I read ak_eric's post, but I didn't know which file to keytool, and I think it was supposed to be an apk file. So how do I get the apk file? First I exported from the processing IDE, but I couldn't find an apk file anywhere. Next, I tried to copy the file from my phone using the adb tool included in the SDK. I didn't have access to the files where (I think) the sketch is, because my phone isn't rooted.
So, if you think you know what I'm doing wrong, or how I can get the apk file, I would really appreciate your help. Thanks.
Edit: So I found 2 .apk's in my export folder, but when I try to keytool them it says that it is the wrong keytool format
Not the datatype. I've been trying to recreate a sketch called strings that you can see
here. He explains the idea pretty well, and so I tried to recreate it. As far as I can tell, my sketch is finding the nearest not connected point accurately, but I think the problem is with my loop for checking for intersections.
I tried to comment to explain, and a lot of the code is the segment intersection function, but sorry for posting so much code.
connections.add(new connection(-100, -100, -100, -100));//not a connection that will be checked
}
void draw() {
for (int i=dots.size()-1;i>0;i--) {
d d1 = (d) dots.get(i);
d1.update();
}
}
class d {//class for dot
float x, y;
boolean connected=false;
int id;
d(float cx, float cy, int cid) {
x=cx;
y=cy;
id=cid;
}
void update() {
float closest=100000;
int closeid=0;
boolean intersection=true;
float x3=-101;
float y3=-101;
for (int i=dots.size()-1;i>0;i--) {//loop to find the closest dot
d d1 = (d) dots.get(i);
if (d1.id==id) {
}
else {
if (d1.connected==false && connected==false) {
if (dist(x, y, d1.x, d1.y)<closest) {//if it is closer than the closest one so far
closest=dist(x, y, d1.x, d1.y);
closeid=d1.id;
x3=d1.x;
y3=d1.y;
}
}
}
}
for (int j=connections.size()-1;j>0;j--) {//loop through the connections and check to see if the connection with the closest dot intersects with any of them
connection c1=(connection) connections.get(j);
//get connection x's and y's
float x1=c1.x1;
float x2=c1.x2;
float y1=c1.y1;
float y2=c1.y2;
if(x3!=-101 && y3!=-101){
}else{
if (segIntersection(x1, y1, x2, y2, x, y, x3, y3)!=null) {//check if they are intersecting
intersection=true;
}
}
}
for (int i=dots.size()-1;i>0;i--) {//loop to pick out that dot and draw a line
d d1 = (d) dots.get(i);
if (d1.id==id) {//skip yourself
continue;
}
if (d1.id==closeid && intersection==false) {//if you aren't intersecting and if the dot that has been looped to is the dot you're looking for
stroke(0, 168, 255);
line(x, y, d1.x, d1.y);
connected=true;
d1.connected=true;
connections.add(new connection(x, y, d1.x, d1.y));//record the connection
}
}
stroke(255, 70);
point(x, y);
}
}
class connection {//class to record all the connections that have been made
My question is pretty straight forward, how can I determine if 2 segments are intersecting? I've looked around and I haven't been able to find any tutorials at all, but I can remember seeing one once, if only I could remember where...
Can somebody please tell me what is wrong with this code?
When I include it in my sketch, it crashes the first time I run it, but only the first times. Also, when the back button is pressed, the sketch still exits. The menu button works fine though.
void keyReleased() {
if (key==CODED){
if(keyCode==MENU || keyCode==BACK){//MENU and BACK keys
Hello, if someone had an application on the Android Market, and they wanted to port it over to iOS, what kind of options are available? I've heard of iProcessing, but I don't think that it's supported, or a very good option.
My question is if it is possible to just export an app through the javascript mode, and then put it on a webpage. Could I make an app that just loads that webpage, but also make the webpage only accessible through that app? What kind of performance do mobile devices get through javascript?
Another question of mine is if a set up like the one I explained earlier is in effect, is it possible to use Processing's networking library?
Also wasn't sure if this post should go in this forum or the processing implementations forum... Sorry if I was wrong!
What is the best way to mark a location as occupied? in the past I've used get(), but this is harder to maintain if I have different classes, and seems like a shortcut. Is it better to mark each location with a class or an array? If i use a class then you end up with (width*height) amount of classes which isn't good for performance. I hope that's clear enough. Any help is appreciated
When I run this code, nothing happens when I click... Does the for loop not have enough time to finish? is there another way to do this?
void mouseReleased() {
for (int i=miners.size()-1;i>=0;i--) {
if (dist(mouseX+vx, mouseY, resources[i].x,resources[i].y)<50) {
miners.add(new miner(mouseX+vx, mouseY));
cash-=100;
}
}
}
miners is a list of objects from the class miner and the vx variable is used with translate... and resources is an array of objects from my resource class... Any ideas? thanks
I'm at the very, very beginning of attempting to make a real-time multiplayer game with Processing and I need to be able to make a new building. I have a class for the building, but how do I make it so that a new instance is made under certain conditions (for example when the mouse is pressed)? My question isn't about the conditions but just about adding an object. I hope that makes sense... Thanks for any help!
So I wanted to make the "Processing" sketch... like the one at the top of this forum (and in a lot of other places). Basically I completely copied Bouncy Bubbles almost word for word when I was trying to get objects to interact with each other... So then I was messing around with it and I made the circles move and put different formulas in it.
When I added this:
if(frameCount>2){ //I think this helps it not be so bizarre in the beginning
xm = xm + .1/(x-others[i].x); //formula that makes things push away from each other
ym = ym + .1/(y-others[i].y);
}
Inside the for loop:
for (int i=id+1;i<zarray.length;i++) { //id is an id given to each object. zarray is an array of my class Z
I think maybe the circles are equaling and canceling out because a lot of them hold pretty still, until one of them shoots across the screen.
Anyways it looks like I lose a bunch of circles so I guess some of them manage to escape my if()'s on the walls. I also said:
if(x<-10 || x>width+10){ //if it leaves the screen
x=width/2;
y=height/2;
xm=random(-10,10);
ym=random(-10,-10);
}
under void move
I don't know what happens to them, and only happens most of the time. If you want to see the sketch or source its
here... but it's kind of screwy on the page.
I've been asking a lot of questions, but I don't think there's a limit... I'm looking for something that looks like gravity, not an actual scientific formula, unless you think that is the best thing to use. Anyways what I like to do is:
xm=xm+(x-mouseX)/100;
ym=ym+(y-mouseY)/100;
Where xm is the variable that is added to x, and the same for y. But the problem with this is that the farther an object is, the stronger the effect of the "gravity" is, instead of the other way around. It seems like the answer should be obvious but, uh, I haven't thought of one.
Hi! My question isn't very practical, but I noticed something when I was making a sketch. I was messing around, and decided to make a circle with expanding and decreasing size, so it would look like a spinning coin even though it was rendered in 2d. Once I had done that, I saved my sketch, and decided to try to draw lines from one part of the outside of the circle to another part of the outside. I gave the circle an outline with a stroke of 1, so only the computer could tell the difference between it and the background. Then, I used 2 for loops to run through each pixel and draw lines from pixels with an RGB value of 1, to other pixels with a value of 1. The sketch did this pretty well, but only in the bottom right quarter of the window. I didn't save the sketch, but i tried to recreate it. Unfortunately, my remade version isn't nearly as effective as the original from some reason.
int s=700;
int sm=15;
int outlineblack=-16711423;
int x=0;
int y=0;
int px, py;
void setup() {
size(700, 700);
smooth();
background(0);
}
void draw() {
if (s>700 || s<0) {
sm=-sm;
}
s+=sm;
fill(0, 30);
rect(0, 0, width, height);//background
stroke(1);
fill(0, 0, 255);
ellipse(width/2, height/2, s, 700);//coin
for (int ix=0;ix<width;ix=ix+15) {//the code is "ix=ix+10" instead of "ix++" because of performance issues
for (int iy=0;iy<height;iy=iy+15) {
if (get(ix, iy)==outlineblack) {//run through pixels and find which ones are the color of the coin's outline
px=x;
py=y;
x=ix;
y=iy;
}
if(px!=0 && py != 0 && x!=0 && y != 0){
stroke(255);
line(px, py, x, y);
}
}
}
}
So my question is why does it tend to draw lines more often in the bottom right quarter. Thanks
I wanted to make a sketch that draws a triangle, and then finds the midpoint of all three sides and draws a triangle in between those points, so that it's a triangle within a triangle within a triangle etc. That's the best way i can explain but if you run the code you can see what I mean.
Anyways I did make the sketch and it was easier than i thought, and i think that it would make a very cool effect, if you could somehow zoom in while the triangles are being drawn smaller and smaller... This is 2d, and there's no background(); in draw so i guess you could do it somehow with get();, but I'm not sure how to go about this.... here is my code:
float x1, y1, x2, y2, x3, y3;
float avx1, avy1, avx2, avy2, avx3, avy3;
void setup() {
size(700, 700);
background(0);
smooth();
x1=random(0, width);
x2=random(0, width);
x3=random(0, width);
y1=random(0, height);
y2=random(0, height);
y3=random(0, height);
frameRate(5);
}
void draw() {
fill(0);
stroke(255);
triangle(x1, y1, x2, y2, x3, y3); //draw
avx1=(x1+x2)/2; // get the midpoint of each side by averaging the points
avy1=(y1+y2)/2;
avx2=(x2+x3)/2;
avy2=(y2+y3)/2;
avx3=(x3+x1)/2;
avy3=(y3+y1)/2;
x1=avx1; // set the old points to the new midpoints
y1=avy1;
x2=avx2;
y2=avy2;
x3=avx3;
y3=avy3;
}
I know i could find the center of the triangle by averaging the three points, so that would be the place to set the get();... thanks for any ideas
Today I made a sketch that makes mazes... A lot of debugging but i sorted it out. The problem is it takes a long time to do it. Whenever the point is stuck it goes only on white squares(at random) until it finds somewhere thats good to go...
That's it... I'm asking how I could make it faster, because I really can't use this when it's this slow... I've seen mazes that generate instantly, but i have no idea of how that works. Thanks
Hi, I've had some time with processing, but I still haven't really utilized things like arrays and classes... Anyways the question is how could I choose which point is the mouse closest to in a situation like this:
size(300,300);
for(int gx=0;gx<width;gx=gx+10){
for(int gy=0;gy<width;gy=gy+10){
point(gx,gy);
}}
and maybe draw a red point at whichever spot in the grid is closest to the mouse... any help would be appreciated