Basically I have a class that creates and ellipse. This ellipse will chase the mouse with a little bit of logic.
Then I make five of those ellipses.
QUESTION:
how do I keep multiple ellipses from following the same path? So as their projectories are different and they approach the mouse from different sides as much as possible?
Its ok if its for a little bit but I want to keep them from bunching up and overlaying. Do I have to keep track of all their locations and adjust accordingly? or can the variables or "forces" added to them be tweaked enough to make this happen?
here is the code if you do not want to go to the link above:
basically, I have an elipse that follows the mouse around. this math is no problem.
What I want to do is:
1. when ellipse comes within "x" amount of distance from mouse cursor;
a. stop following mouse
b.just take that specific mouse coordinates from that specifice frame
c.and move in that direction on a straight line ignoring actual current mouse location.
d. after another "x" amount of distance on path of line; return to following the mouse
I know how to make the ellipse move in a straight line and the logic to make it do so. but I cant figure out how to make it just keep going and ignore the current mouse location. so my math is wrong.
how can I get it to just keep going in a straight line using an old mouse position as a point of reference for the direction to move in? I cant figure out how to store a specific mouse coordinate without it always updating in the draw method.
** I have been learning a bit about PVectors and such so some of the code uses them. but its not a requirement
//if difference in distance is withing range do these if(abs(dx) < 50){ if(abs(dy) < 50){ //updateC(); }//if }//if }//draw
void distance(){ //where is our mouse? mouse = new PVector(mouseX,mouseY);
//distance and line between mouse and object dx = mouse.x - location.x; dy = mouse.y - location.y;
//visual representation of line between mouse and ellipse stroke(255); line(mouse.x,mouse.y,location.x,location.y); }//distance
void updateA(){
//follow the mouse //convert to absolute value of dx/dy so these return true //no matter where mouse is in relation to object. if //values are negative the object stops moving //if you dont do abs() you have to make two extra //if statements for when dx/dy are less than 1
After working on this I have a rough and ugly BUT WORKING example. thanks to everyone!
//Some PVectors to store our coordinates in for easy access PVector location,mouse,distance; //two booleans that are used to determine //actions between mose and object boolean isFar = true; boolean isShort = false; //floats to transfer data from PVectors and do math float x,y,dx,dy,dx_Short,dy_Short; float easing = 0.5;
void setup(){ size(500,500); //our starting location for ellipse location = new PVector(random(width/2),random(height/2)); }//setup
void draw(){ background(100); trackMouse();//always track main mouse variable render();//draw ellipse tests();//where is mouse vs. object
//if mouse is more than 50px away if(isFar){ distance(); updateA(); }//if //if mouse is less than 50px away if(isShort){ distanceShort(); }//if }//draw
//this continually tracks and updates the mouse PVector //so we can use that information in other methods. void trackMouse(){ mouse = new PVector(mouseX,mouseY); }//trackMouse
//do all our math to follow mouse void distance(){
//distance and line between mouse and object dx = mouse.x - location.x;//direction.x dy = mouse.y - location.y;//direction.y
//saves a single mouse coordinate from a single frame void distanceShort(){ //sets variables to last known values of dx, dy //when mouse is within 50px dx_Short = dx; dy_Short = dy;
//how close is the object to mouse //change booleans appropriately void tests(){ //are we 'x' distance away? if(abs(mouse.x - location.x) > 50 && abs(mouse.y - location.y) > 50){ isShort = false; isFar = true; }//if //did the mouse just move in a straight line up,down,left,right? if(abs(mouse.x - location.x) >= 0 && abs(mouse.y - location.y) > 50){ isShort = false; isFar = true; }//if if(abs(mouse.x - location.x) > 50 && abs(mouse.y - location.y) >= 0){ isShort = false; isFar = true; }//if //are we within 'x' amount of distance? if(abs(mouse.x - location.x) < 50 && abs(mouse.y - location.y) < 50){ isFar = false; isShort = true; }//if }//tests
void updateA(){ //follow the mouse //convert to absolute value of dx/dy so these return true //no matter where mouse is in relation to object. if //values are negative the object stops moving //if you dont do abs() you have to make two extra //if statements for when dx/dy are less than 1 if(abs(dx) > 1){ location.x += dx*0.05; }//if if(abs(dy) > 1){ location.y += dy*0.05; }//if }//updateA
void updateC(){ //captured the starting location of ellipse //move 'x' distance from that location in //direction of mouse in line location.x += dx_Short * 0.1; location.y += dy_Short * 0.1; }//updateC
FATAL EXCEPTION: Animation Thread
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:525)
at processing.core.PApplet.loadImage(PApplet.java:3590)
at processing.core.PApplet.loadImage(PApplet.java:3576)
at processing.test.dogsmeow.dogsMeow.loadImg(dogsMeow.java:121)
at processing.test.dogsmeow.dogsMeow.setup(dogsMeow.java:61)
at processing.core.PApplet.handleDraw(PApplet.java:1855)
at processing.core.PGraphicsAndroid2D.requestDraw(PGraphicsAndroid2D.java:161)
at processing.core.PApplet.run(PApplet.java:1746)
at java.lang.Thread.run(Thread.java:1019)
when I run my sketch on the emulator [havnt tried a device yet] the above error is recieved right at 21 out of 26 images that are loaded.what the sketch does is load 26 images and 26 sounds and lets you cycle through them. if you click on an image it plays a sound that is associated with that image. all of them from both sets are kilobytes in size. the largets image is 30 kb.
Ive been reading and i understand that when in memory the images are height*width*4 or something similar. All the images are 600x600 pixels
my questions.
1. is that large?
2. how do I use smaller images and scale them up in processing and would that help?
3. is there something happening Im not aware of?
ive tried amping up the accessable memory for the emulator but no matter what I get this error.
any help would be great.
code:
import ddf.minim.*; import ddf.minim.signals.*;//dont need yet import ddf.minim.analysis.*;//dont need yet import ddf.minim.effects.*;//dont need yet
//our main array var's int i;//image int j;//sound
noLoop(); //stop the images array from loading over and over image(images[i], 100, 0 );//draws our current image [i] }//draw
void mousePressed(){ //if the mouse is over left 'button' if (mouseX >= 0 && mouseX <= 100){ println("left button"); i--; j--; if ( i < 0){ //must subtract from array length to //account for 0 being counted i = images.length - 1; j = sounds.length - 1; }//if }//ifML
//if the mouse is over the center area/image else if (mouseX >= 101 && mouseX <= 699){ println("center button");
//play the sound when clicked play(); }//ifMC
//if the mouse is over the right button else if (mouseX >= 700 && mouseX <= 800){ println("right button"); i++; j++; if ( i >= (imgUrls.length)){ i = 0; j = 0; }//if }//ifML println(i);//what is our image # println(j);//what is our sound # println(mouseX);//where is our mouse //must use this because 'noLoop()' was
//causes draw() to run one time redraw(); }//mouse pressed
//push list of images into array void loadImg(){ imgUrls= loadStrings("listI.txt"); images = new PImage[imgUrls.length]; for(int i = 0; i<imgUrls.length;i++){ images[i] = loadImage(imgUrls[i]); println(i); }//fori }//loadImg
//push list of sounds into array void loadSnd(){ sndUrls= loadStrings("listS.txt"); sounds = new AudioSnippet[sndUrls.length]; for(int j = 0; j<sndUrls.length;j++){ minim = new Minim(this); sounds[j] = minim.loadSnippet(sndUrls[j]); println(j); }//fori }//loadSnd
////loads and positions image for 'button' void drawRecL(){ left_arrow = loadImage("arrowLeft.jpg"); image(left_arrow, 0,0); fill(l); rect(0,0,100,600); }//drawRec
//loads and positions image for 'button' void drawRecR(){ right_arrow = loadImage("arrowRight.jpg"); image(right_arrow, 700,0); fill(r); rect(700,0,100,600); }//drawRec
//our hover over affect is just a black rectangle at //a lower alpha that is hidden if the mouse is over it //because noLoop was called 'mouseMoved' was the
//only way found to get this affect as it continuously tracks the mouse
void mouseMoved(){ //if the mouse is over left button if (mouseX >= 0 && mouseX <= 100){ l = color(0, 0, 0, 10); }else if (mouseX >= 101 && mouseX <= 699){ l = color(0,0,0,200); }//if //if mouse is over right button if (mouseX >= 700 && mouseX <= 800){ r = color(0, 0, 0, 10); }else if (mouseX >= 101 && mouseX <= 699){ r = color(0,0,0,200); }//if loop(); }//rhover
//control when the sound file is played void play(){ //if it is not playing then go ahead and play if (!sounds[j].isPlaying()){ // makes sure the file plays from start sounds[j].rewind(); sounds[j].play(); }//if }//play
//when the program is closed, close all the sound threads void close(){ sounds[j].close(); minim.stop(); // super.stop(); }//stop
**update** all the code below works perfectly. I found out that two out of many sound files were .wma format and not .wav..this caused processing to through an error because it did not match what was listed in the text files i am loading.
**
right now I have two arrays.
1. loads and stores a list of images
2. loads and stores a list of sounds
the images array works perfectly. loads all 26 images
the sounds array however loads at the most 10 and then throws a "NullPointerException". Ive checked my spelling, math, adding memory in preferences, everything. I can load any number of items as long as I dont go over 10.
even if i comment out the images load method and only load the sounds it fails.
im using minim 2.02
and processing 2.0b3
everything works and runs smoothly as long as I dont load more than 10 items into the sound array.
the sketch allows you to load 26 images and 26 sounds from a text file. when you click on the image, lets say of a monkey it will play the corresponding sound of the monkey. you can cycle through the images and sounds at the same time with two 'buttons' on the left and right of the image.
code:
import ddf.minim.*; import ddf.minim.signals.*;//dont need yet import ddf.minim.analysis.*;//dont need yet import ddf.minim.effects.*;//dont need yet
//a variable to contain our array number //set to zero because that is the default //value of an array int imgVar = 0;
//our main array var's int i;//image int j;//sound
void draw(){ drawRecR(); drawRecL(); //make sure the image is refreshed and correct image(images[i], 50, 0 ); }//draw
void mousePressed(){
//if the mouse is over left button if (mouseX >= 0 && mouseX <= 50){ println("left button"); i--; j--; if ( i < 0){ //must subtract from array length to //account for 0 being counted i = images.length - 1; j = sounds.length - 1; }//if }//ifML
//if the mouse is over the center image else if (mouseX >= 51 && mouseX <= 649){ println("center button"); //play the sound play(); }//ifMC
//if the mouse is over the right button else if (mouseX >= 650 && mouseX <= 700){ println("right button"); i++; j++; if ( i >= (imgUrls.length)){ i = 0; j = 0; }//if }//ifML println(i); println(j); println(mouseX); }//mouse pressed
//push list of images into array void loadImg(){ imgUrls= loadStrings("listI.txt"); images = new PImage[imgUrls.length]; for(int i = 0; i<imgUrls.length;i++){ images[i] = loadImage(imgUrls[i]); println(i); }//fori }//loadImg
//push list of sounds into array void loadSnd(){ sndUrls= loadStrings("listS.txt"); sounds = new AudioSnippet[sndUrls.length]; for(int j = 0; j<sndUrls.length;j++){ minim = new Minim(this); sounds[j] = minim.loadSnippet(sndUrls[j]); //it always says this is the NullPointerException println(j); }//fori }//loadSnd
////draws rectanges to visualize pre and next buttons void drawRecL(){ fill(50); rect(0,0,50,600); }//drawRec void drawRecR(){ fill(25); rect(650,0,50,600); }//drawRec
//control when the sound file is played void play(){ //if it is not playing then go ahead and play if (!sounds[j].isPlaying()){ // makes sure the file plays from start sounds[j].rewind(); sounds[j].play(); }//if }//play
//control when the sound file is stoped void close(){ sounds[j].close(); minim.stop(); // super.stop(); }//stop
First day using sound and processing. Im trying out Minim because it seems the easiest to use. My sketch loads 5 images and allows you to click the right and left edge to cycle the images. if you click the center of the sketch it triggers the sound file to play.
however, the sound file stops a couple seconds early. if you click again it starts from where it left off but doesnt compete. the audio stops playing but will never play the complete track. keep clicking and the sound gets shorter and shorter but never finishes. always starting from where the audio cut out the time before.
im using processing 2.0b3.
and minim 2.02
any help would be great
thank you.
code:
import ddf.minim.*; import ddf.minim.signals.*;//dont need yet import ddf.minim.analysis.*;//dont need yet import ddf.minim.effects.*;//dont need yet
//minim Minim minim; AudioPlayer song;
//a variable to contain our array number //set to zero because that is the default //value of an array int imgVar = 0;
// this loads mysong.wav from the data folder song = minim.loadFile("owl.wav");
}//setup
void draw(){ drawRecR(); drawRecL();
//draw current image to screen image(images[i], 25, 0 ); }//draw
void mousePressed(){
//if the mouse is over left button if (mouseX >= 0 && mouseX <= 25){ println("left button"); i--; if ( i < 0){ //must subtract from array length to //account for 0 being counted i = images.length - 1; }//if }//ifML
//if the mouse is over the center image else if (mouseX >= 26 && mouseX <= 124){ println("center button"); //play the sound play(); }//ifMC
//if the mouse is over the right button else if (mouseX >= 125 && mouseX <= 150){ println("right button"); i++; if ( i >= (imgUrls.length)){ i = 0; }//if }//ifML println(i); println(mouseX); }//mouse pressed
//push list of images into array void loadImg(){ imgUrls= loadStrings("list.txt"); images = new PImage[imgUrls.length]; for(int i = 0; i<imgUrls.length;i++){ images[i] = loadImage(imgUrls[i]); println(i); }//fori }//loadImg
////draws rectanges to visualize pre and next buttons void drawRecL(){ fill(50); rect(0,0,25,100); }//drawRec void drawRecR(){ fill(25); rect(125,0,25,100); }//drawRec
//control when the sound file is played void play(){ song.play(); }//play
//control when the sound file is stoped void stop(){ song.close(); minim.stop();
had to switch from calling the audioPlayer to audioSnippet.
added logic to my play method
1. rewind makes sure the file starts from beginning
2. the if statement makes sure it doesnt play if it is already playing
import ddf.minim.*; import ddf.minim.signals.*;//dont need yet import ddf.minim.analysis.*;//dont need yet import ddf.minim.effects.*;//dont need yet
//minim Minim minim; AudioSnippet song;// changed this
//a variable to contain our array number //set to zero because that is the default //value of an array int imgVar = 0; //our main array var int i; //name our arrays String[] imgUrls; PImage[] images;
//if the mouse is over left button if (mouseX >= 0 && mouseX <= 25){ println("left button"); i--; if ( i < 0){ //must subtract from array length to //account for 0 being counted i = images.length - 1; }//if }//ifML
//if the mouse is over the center image else if (mouseX >= 26 && mouseX <= 124){ println("center button"); //play the sound play(); }//ifMC
//if the mouse is over the right button else if (mouseX >= 125 && mouseX <= 150){ println("right button"); i++; if ( i >= (imgUrls.length)){ i = 0; }//if }//ifML println(i); println(mouseX); }//mouse pressed
//push list of images into array void loadImg(){ imgUrls= loadStrings("list.txt"); images = new PImage[imgUrls.length]; for(int i = 0; i<imgUrls.length;i++){ images[i] = loadImage(imgUrls[i]); println(i); }//fori }//loadImg
////draws rectanges to visualize pre and next buttons void drawRecL(){ fill(50); rect(0,0,25,100); }//drawRec void drawRecR(){ fill(25); rect(125,0,25,100); }//drawRec
//control when the sound file is played void play(){ if (!song.isPlaying()){ song.rewind(); song.play(); } }//play
//control when the sound file is stoped void close(){ song.close(); minim.stop();
The reference is easy enough to understand if you want to read the contents of a file and not display files based off of one. I have found some good loadStrings() examples on the forum but none of them show the text files or answer my questions.
1. what does the text file look like inside if you want to load a file from your '/data'?
a. do i need specific syntax to tell processing to load the files instead of just read and print the names?
or is this right:
[top of text file]
0.jpg
1.jpg
.
.
.etc
I know how to load images and use arrays. I can make an array of images. but I dont know how to do it without loading each image individually.
so I wrote an applet using opengl. it just loads an obj file and lets the user rotate it with the mouse.
i can upload it and get it to work online with IE and FF on win7x64. but if I use anything related to Apple Inc. it fails to validate certificate for jogl.dll
ive self signed all the jars i am using. im also hosting them as well.
Any word as to where to begin. Ive trolled through my .jnlp files looking for typos or errors but to no avail.
Do apple products treat the paths differently? I am using absolute paths.
So to fix this error I only used processing 1.5.1 with P3D. I had to redo my .obj file because there was no uv map for the texture to use so it came out strange. but redoing the up map and using a lower polygon count fixed my problems
original post here down
----------------------------------------------------
Exception in thread "Animation Thread" java.lang.RuntimeException: You need to use "Import Library" to add processing.opengl.PGraphicsOpenGL to your sketch.
at processing.core.PApplet.makeGraphics(Unknown Source)
at processing.core.PApplet.size(Unknown Source)
at processing.core.PApplet.size(Unknown Source)
at vase.setup(vase.java:39)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphics.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
-----------------------------------------------------
This is the error given, I have tried using 1.5 and 2.0a5 to export the app but they both bring back this error when I run the app online. offline it works. Ive been through my source links and the .jnlp files wondering if it is jogl that is the problem.
//it uses OBJLoader and the SAITO example as a base import processing.opengl.*;
import saito.objloader.*;
OBJModel model ;
float rotX, rotY;
void setup()
{
size(640, 480, OPENGL);
frameRate(30);
///keep your poly count 32000 and below for obj files //or youre going to have a bad time //create and load instance of model model = new OBJModel(this, "vase.obj", "absolute", TRIANGLES);
model.enableDebug();
//scale of model. not sure the relationship to original size model.scale(125);
model.translateToCenter();
stroke(255);
noStroke();
}
//pushMatrix and popMatrix create little bubble for model to be in pushMatrix();//begin changes to model
translate(width/2, height/2, 0);
rotateX(rotY*0.4);
rotateY(rotX*0.4);
model.draw();
popMatrix();//end changes to model
I have a sketch. all it does is display a simple 3d cube and rotate it a little. I export as applet. the generated html will run offline just fine but online it has issues.
Java Plug-in 1.6.0_31
Using JRE version 1.6.0_31-b05 Java HotSpot(TM) Client VM
java.lang.ClassNotFoundException: Three_D_basic
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.jdesktop.applet.util.JNLPAppletLauncher.startSubApplet(JNLPAppletLauncher.java:1977)
at org.jdesktop.applet.util.JNLPAppletLauncher.access$200(JNLPAppletLauncher.java:662)
at org.jdesktop.applet.util.JNLPAppletLauncher$5.run(JNLPAppletLauncher.java:1325)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
May 2, 2012 3:31:35 PM org.jdesktop.applet.util.JNLPAppletLauncher displayError
SEVERE: Class not found: Three_D_basic
--------------------------------------------------------------------------------------------------------------
SECOND: Changing this gets rid of the 'class not found error'
I HAVE unistalled/reinstalled and tried to update my java jdk and what not.
I dont know what I am missing or understand the inner workings of java enough to know where to actually look.
QUESTIONS:
1. when processing exports an applet is there an actual '.class' file generated? because mine does not create such a thing. i kind of assumed there would be one in the jar if anywhere.
2. do I need to do something in my sketch to make things work?
like:
thisSketch extends pApplet{......and then the sketch } .. or something
<p>
<strong>
This browser does not have a Java Plug-in.
<br />
<a href="
http://www.java.com/getjava"
title="Download Java Plug-in">
Get the latest Java Plug-in here.
</a>
</strong>
</p>
</applet>
</div>
.......
<-------------------------------------------->
end html part that matters
<--------------------------------------------->
the files created by exporting an applet:
core.jar
/// I have multi jar unchecked in preferences, should this really be here if there are no libraries imported?
index.html
loading.gif
opengl.jar
Three_D_basic.jar
Three_D_basic.java
Three_D_basic.pde
...class file?
I know this is a lot of info but if there is anything I am missing to settle this problem please let me know. Thank you so much for your time even if you just read this over. I hope someone, including myself , can learn from this.
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at processing.mode.javascript.Worker.handleClient(BasicServer.java:401)
at processing.mode.javascript.Worker.run(BasicServer.java:364)
at java.lang.Thread.run(Thread.java:662)
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at processing.mode.javascript.Worker.handleClient(BasicServer.java:401)
at processing.mode.javascript.Worker.run(BasicServer.java:364)
at java.lang.Thread.run(Thread.java:662)
so basically, I can get any 2d app to work just fine but any sketch with 3D will not run. it pulls up the webpage , creates the text and graphics but the place where the sketch should be is blank.
Not really sure where to start on this one. any help would be great.
win 7 64.
processing 2.0a5
IE9
**update** just in case it matters, all the sketch does right now is draw a 3d box and rotate it 10 degrees. nothing else or complicated
**update** 4-23-12
Going from processing javascript mode and running directly to web does not work for as of today. However, working in standard mode and exporting an applet does work perfectly. So I am just going to work on embeding the applet for my needs at the moment. I will come back to this eventually however.
I cant get any sketch involving any kind of 3d code or objects to work with processing/android. it will compile and send to the device or emulator but then will be force closed by android.
I wont post any code unless you ask because even the pre-developed examples installed with processing will not work.
right now im using processing 2.0a5 on windows 7 64bit. and yes I am working in android mode as well.
I know that since API 14 for android sdk there are issues with android on windows after some research. Is this one of them? or is there something Im missing?
Thank You for your time
* UPDATE. had a thought. I have always sent sketches via usb, would it matter if I exported the project and then uploaded outside of processing?