I am developing a 2D sketch that will include many (1,000+) irregular closed shapes, each made of two lines and two Bezier curves.
I would like to be able to both draw the shapes also be able to easily test whether each of them contains the mouse location.
Before I get too deep into the project, I am experimenting with possible approaches, and I have tried two ways to create the shapes:
Option 1. Use beginShape() and endShape()
Pro: Easy to draw/render/make visible.
Con: Difficult to determine whether or not the shape contains the mouse location.
Option 2. Import java.awt.geom.Path2D
Pro: Can easily test whether the shape contains the mouse.
Con: I can't figure out how to render it (e.g. give it a stroke and fill).
At this point, the only solution I can figure out is to simultaneously do both, by creating two co-located versions of each shape (a visible Processing version and an invisible Java Path2D version). This allows the shapes to be visible and also allows me to test whether they contain the mouse location. But it also seems really awkward and redundant. Any ideas for more elegant solutions, code examples, relevant libraries...?
I am trying to solve a problem with text rotation (posted elsewhere in this forum).
One option would be to convert a string to an image and then rotate the image.
Can anyone point me to an example of code that converts a string to an image?
Thanks in advance for any assistance/guidance you might be able to provide.
I am using native fonts in a Processing application with the default (JAVA2D) renderer.
The fonts anti-alias fine in Processing, but not in the exported Java applet.
I experienced this problem previously with Processing 1.2.1 using createFont() and now with Processing 1.5 using hint(ENABLE_NATIVE_FONTS) and createFont(). It is evident across browsers (Firefox, Chrome, IE).
Is there something I can do to get the fonts to anti-alias properly in the exported Java applet?
Setup:
MacBook Air
OS X Snow Leopard
Processing 1.2.1 and 1.5
I've been having a problem where rotated text displays as a stack of vertical characters, rather than as normal, left-to-right text, but I only get this behavior in the exported Java applet, not in Processing.
I have narrowed the problem to using hint(ENABLE_NATIVE_FONTS) in Processing 1.5, but I also experience the same problem in Processing 1.2.1 if I use createFont() with a native font.
Below are two screen captures from a mini-program that demonstrates the problem. On the left is output from Processing (which is correct). On the right is the output from the Java applet (which is messed up).
In case you're thinking it might be a problem with the default font, that's not the case. The same problem persists if I load Arial using createFont("Arial",12,true) and use textFont(arial,12).
It just seems to be a problem with exporting an applet that uses native fonts, which is a real problem for me, since I'm using a lot of scaled fonts in the application I'm writing.
(NOTE: I am also posting a question about anti-aliasing of native fonts, since I can't seem to get them to anti-alias in the Java applet export, though the anti-alias fine in Processing. Not sure if this is related.)
I'm looking for guidance on best practice for creating click-and-drag selection sets in Processing.
I describe below my specific application, but I am interested in generic guidance on what seems a pretty standard function.
I have an array of 480 (Sector) objects stored in an array sectors[]. Each Sector includes, among others, the following variables:
x x-position [set up as an Integrator to allow smooth transitions]
y y-position [ditto]
active whether or not the sector is active (highlighted on screen) [boolean]
Currently, multiple sectors can be activated by shift-clicking their location on screen. And I can click-and-drag an individual sector using the following code:
void mouseDragged() {
for (int i = 0; i < finalStart; i++) {
if (sectors[i].rollover(mouseX,mouseY) && sectors[i].active) {
sectors[i].locate(mouseX,mouseY);
sectors[i].target(mouseX,mouseY);
}
}
}
I'd like to be able to do the following:
1. Click-and-drag all selected sectors as long as the mouse is over one of the selected sectors
2. Select multiple sectors using a bounding box
These seem like pretty standard GUI functions, and I'm wondering if there are some best-practice code examples (or even a library?) out there for the most efficient way to achieve these effects?
I am also open to advice on whether my click-and-drag is the most efficient way to achieve the desired effect.
(Note that the second part of the if condition is required in order to avoid sectors getting "picked up" along the way if another sector is dragged over their location. I assume that creating a selection set would be the other way to deal with this, but I'd prefer to create it with the benefit of others' knowledge of the best ways to do this...)
I have exported a Processing sketch as a Java applet and uploaded the index.html as the home page of a website.
When I access the page using Firefox, the Java applet is sometimes (but not always) cropped from its actual size (1000x750) to 640x480.
I can't be sure what triggers the behavior, but it seems as if if is determined by which URL I use:
mydomain.org works fine (shows full 1000x750)
www.mydomain.org crops to 640x480
The problem does not occur with Safari, and other Firefox users can access the site fine using either URL.
I am using the most up-to-date versions of Firefox and Processing.
Does anyone have any ideas of what might be causing this behavior?
I have an array of objects, each of which has a number of variables.
I would like to select the "top 20" objects, based on a specific variable.
I think this is really a version of the question: "How can I sort an object array based on a specific object variable?"
So I think that I can provide a simplified example of my question. Assume the following code:
Employee[] employees;
void setup() {
employees = new Employee[3];
employees[0] = new Employee(0,20000.00);
employees[1] = new Employee(1,40000.00);
employees[2] = new Employee(2,30000.00);
}
class Employee {
String firstName;
String lastName;
int employeeID;
float salary;
How could I sort this array based on salary (...and then ideally put the results in a new array)?
Based on web research so far, I am seeing some information about using Comparators in Java, but I'm wondering how I would embed a Comparator in Processing so it worked properly.
(I have experience coding Processing, but not Java.)
I have a sketch that I am trying to export to both MacOSX application and Java applet. In setup, I have the following line:
frame.setTitle("Title that appears in application title bar");
This works great for the MacOSX export. But it causes the Java applet to hang. Any ideas for how to include this instruction so that the code can be exported to both MacOSX and Java?
My current workaround is to comment out this line when exporting to Java, but that is kind of a pain. Any ideas for how to write the line so it doesn't interfere with Java?
(Java doesn't give an error. It just sits there doing nothing and doesn't seem to get to the draw section of the code.)