This is an example sketch that will be included with my next library (QScript).
This
applet will accept a user defined function and display its graph between the low and high x values. There are 8 pre-defined graphs available but the fun is creating your own. (Summary of functions available can be found
here)
Simply type in any expression as a function of $n (all variable names in QScript start with $) and click on the Draw button. If you make a mistake then an error message will appear in the red box and the offending part highlighted.
I am pleased to announce the first release of a new library that supports the creation of 2D games and simulations requiring state driven autonomous agents.
The library is too big to describe all the features here but all these sketches show the library in action and better still are included in the download.
To help people get the best from this library there are extensive guides to the AI techniques and library features, together with a series of programming guides demonstrating how to code with it.
There are links to all of these guides and the library download from the
library home page on my website.
Its been a long time in its development, but then there are over 12000 lines of source code and I got distracted several times along the way. Despite that I have enjoyed creating it and I hope you enjoy playing with it.
G4P V3.3 (
website)
This has a new control, GImageToggleButton, this control is basically a toggle button that can have 2 or more toggle states. Although the most common toggle switches have just 2 states (think GCheckbox) this control has no upper limit to the numbers of states. In the
example there is a 16 state button using smilies.
This release allows the font used by the GDropList control to be changed.
GUI Builder V2.3 (
website)
The UI has been modified, the menu replaced with a toolbar so that it is easier and faster to use the snap-to-grid, auto hide and scaling features.
This version is the companion to the new G4P library in that it incorporates the new image toggle button control.
The other big change is that the source repositories for both G4P and GUI Builder have been moved from GoogleCode to SourceForge, I have done this because GoogleCode have deprecated the binary download feature and I have been unable to upload new versions.
All new versions of G4P and GUI Builder will be available through the PDE or from SourceForge. Older versions are still available from GoogleCode until January 2014 when GoogleCode finally switch Downloads off.
I have been asked once or twice how to create a toggle (on/off) button with G4P. Unfortunately the library does not have one out-of-the-box solution.
It is possible to use the GCheckbox and change the graphic used to simulate a toggle button and I will show how to do it here.
The first thing to do is create a tiled image with the pictures to use for the two states. An example is shown here.
The code below was created using the GUI Builder tool, the
statement at line 15 changes the image from the default tick-box to our own image above.
The
width of the GCheckbox must be at least 12 pixels wider than the displayed image (i.e. half the full image width) otherwise it will cause an exception.
// Need G4P library
import g4p_controls.*;
public void setup() {
size(480, 320, JAVA2D);
createGUI();
customGUI();
}
public void draw() {
background(230);
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI() {
mySwitch.setIcon("switch.jpg", 2, null, null);
}
gui.tab (header comments removed)
public void switch_clicked(GCheckbox source, GEvent event) { //_CODE_:mySwitch:429373:
I am creating an AI library suitable for 2D games and this applet is a milestone in that it represents a personal goal that I have decided to share with you.
The applet is a simulation of 5-a-side soccer. It runs continuously with each match lasting 2 minutes. At the end of the match the players run off the pitch and after a short interval two new teams come on the pitch for another match.
I have recently downloaded 2.0b9 and installed it.
When I attempt to add JavaScript mode it downloads the files but fails installation with the messages
Could not delete C:\Users\Peter\Documents\Processing\modes\mode9139477983085052463tmp\JavaScriptMode\keywords.txt Could not delete C:\Users\Peter\Documents\Processing\modes\mode9139477983085052463tmp\JavaScriptMode\mode\JavaScriptMode.jar Could not delete C:\Users\Peter\Documents\Processing\modes\mode9139477983085052463tmp\JavaScriptMode\mode Could not delete C:\Users\Peter\Documents\Processing\modes\mode9139477983085052463tmp\JavaScriptMode Could not delete C:\Users\Peter\Documents\Processing\modes\mode9139477983085052463tmp
Which is strange because it attempts to delete the temporary folder and contents before copying them into the Processing/modes folder.
If I copy the files manually JavaScriptMode appears in the IDE but when I attempt to change to this mode I get exception message shown below. It appears that it can't find some images.
I have found nothing in the issues list so I image it is not a problem with Processing. Has anyone else experienced the same problem or know of a solution?
FYI - my OS is WIndows 7 Professional (64 bit)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97) at java.awt.Container.paint(Container.java:1778) at java.awt.Window.paint(Window.java:3390) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:797) at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714) at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:694) at javax.swing.RepaintManager.access$700(RepaintManager.java:41) at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1636) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666) at java.awt.EventQueue.access$400(EventQueue.java:81) at java.awt.EventQueue$2.run(EventQueue.java:627) at java.awt.EventQueue$2.run(EventQueue.java:625) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) at java.awt.EventQueue.dispatchEvent(EventQueue.java:636) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at processing.app.EditorToolbar.loadImages(EditorToolbar.java:145) at de.bezier.mode.javascript.JavaScriptToolbar.init(Unknown Source) at processing.app.EditorToolbar.paintComponent(EditorToolbar.java:170) at javax.swing.JComponent.paint(JComponent.java:1037) at javax.swing.JComponent.paintChildren(JComponent.java:870)
...
I have raised this topic in reponse to a PM since the answer was likely to be useful to others and because Zoho in their wisdom do not allow formatted text or even multiple paragraphs in PMs.
Version 3 of G4P introduced the StyledText class which enabled text used for labels, buttons etc. to be styled e.g. italic, bold, underline etc. It means that G4P now uses the java.awt.Font class for all controls that display text.
To get a similar output on different platforms (Windows, OSX) then the font used must be installed on the computer system running the sketch (or viewing the applet) which limits the range of fonts available.
With GTextField and GTextArea controls the setFont(Font) method can be used to specify the font to use - this requires a java.awt.Font object passed as a parameter. The problem of cross-platform availablity still exists.
The code below demonstrates how you can load and use a custom True Type Font (TTF). The actual font file (has .ttf extension) must be in the data folder which is inside the sketch folder. Also beware that there may be copyright issues when distributing the font.
import g4p_controls.*;
import java.awt.*;
Font font;
GTextArea txaTester;
public void setup() {
size(400, 400);
createGUI();
// For plain text use Font.PLAIN
font = getFont("consola.ttf", Font.ITALIC | Font.BOLD, 20);
if (font != null)
txaTester.setFont(font);
}
// This method creats and returns a java.awt.Font object from the TTF font
// file in the sketch data folder.
// Returns null if unable to create the font.
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setCursor(ARROW);
if(frame != null)
frame.setTitle("Sketch Window");
txaTester = new GTextArea(this, 33, 17, 226, 208, G4P.SCROLLBARS_BOTH);
txaTester.setOpaque(true);
}
public Font getFont(String ttf_name, int style, float size) {
There have been posts on the forum related to users having problems with the Add Library and Add Tool features of 2.0b8 - the most common error reported that the library/tool package had the wrong structure.
So I have some questions
has the library/tool structure changed with the new templates?
do I need to rebuild my library and tool distributions using the new templates so they can be added via the IDE
I am creating a tool that can be used to sign applets. To do this it needs to run the keytool and jarsigner applications that come with the JDK (Java Development Kit)
On windows these files have a dot-exe extendion i.e.
keytool.exe jarsigner.exe
on MacOSX they don't have a file extension so are
keytool jarsigner
I don't have a Linux machine so I have no idea whether executable files have an extesion or not. So if you have a Linux machine with JDK installed I would be pleased if you would look and let me know the extension for these files.
GSlider2D - provides slider functionality using 2 variable ouputs based on the X and Y position of the control thumb. The ranges for the two variables can be set independantly. Play with it
here.
GStick - simulates the old micro-switched joystick and can be used for in either 4 or 8 direction mode. Great replacement for keyboard control with WASD keys. Play with it
here.
Also the GTextField and GTextArea controls have been updated so their styled text can be saved/loaded from file.
The GUI builder tool has been updatad to include these new controls.
There are more and more questions on the forum about using existing 3rd party libraries with Processing.js and as a library developer I am interested in porting some of my libraries to JS.
Looking at the website I found this
article and in it it states
If you are a library creator and are interested in creating a JavaScript compatible library, stay tuned as we are developing standards and methods for doing so.
So my first question is what stage has this reached?
______________________________________________________________________________________
I have been thinking of making my libraries cross-mode and being realistic I don't think that is a viable option. The problem is that some of my libraries make use of Java language features such as the Java collections and reflection which are not available in JavaScript or in the Processing API
So unless someone knows better it seems that I have three choices
rewrite the libray to only use methods available in the Processing API and then let Processing.js convert it to JavaScript and omit those elements that can't be implemented.
rewrite as much of the library as possible using the Processing API and create pure JavaScript code for those remaining parts.
rewrite the library in pure JavaScript
The first option is good in that it would make it JAVA<>JAVASCRIPT cross-mode compatible, but then (in some libraries) many of the features available in JAVA mode would have to go.
Options 2 and 3 would need a mechanism to integrate 3rd party JavaScript into the sketch. Does anyone know if this already exists?
Anyway these are some of my initial thoughts and it would be good to hear other people's thoughts on this topic.
The sprites library has been updated to work with Processing 2.0b7. The examples have also been updated and tested with b7 and those any that used G4P now need the latest version (3.1.1)
I have just released a new version of G4P which can be downloaded from
here. Apart from some bug fixes and some minor enhancements the main difference is the addition of dialog boxes.
Of particular interest are the
selectFolder,
selectInput and
selectOutput dialogs which behave in the same manor as those in Processing 1.5.1 (before the changes introduced for 2.0). Effectively it means you have an easier upgrade path for any of your old sketches that used these methods.
It also includes simple dialogs (single button) with the
showMessage method and option dialogs (2/3 buttons) with the
showOption method.
Also there is the
selectColor dialog which gives easy access to the Java Swing color chooser dialog.
The dialog boxes can be seen in action
here and this is also included as an example in the library download.
EDIT I am now using Doxygen to create the online
reference for this library. I hope you find it easier to use.
There have been queries about removing the
Export Applet option as Processing goes from 1.5.1 to 2.0 and although I understand the reasons for doing it, I will mourn the loss.
I am still keen to create applets for my website as I use them to demonstrate features of the libraries I create. SInce I am updating my libraries for 2.0 using V1.5.1 to export my applets is problematic (not surprisingly).
Anyway to cut a long story short I have been experimenting with ways to export 2.0 sketches (JAVA2D only) as applets and I need your help.
I have created a signed applet to demonstrate the new features to appear in the next version of G4P and I would like you to try it out and report whether it loaded or not (please report OS and browser versions).
I have tried it out on WIndows 7 (64 bit) with IE 9 (64 bit) and FireFox (32 bit) 17.0.1 and they worked but I am also interested in hearing from MacOS and Linux users and other browsers.
Both the G4P library and its associated GUI Builder tool are now available for download. In particular this new version of G4P (3.1.0) usues the new event model and classes in Processing 2.0 so is no longer compatible with Processing 1.5.1.
It was noted in this
topic that PeaseyCam no longer appears to be working in 2.0b7 and that when the mouse is moved over the window it creates the following exception error.
I have experienced the same problem not on;y with PeaseyCam but also G4P (Torroid example) when using the P3D renderer.
My question is whether anyone is experiencing the same error with other libraries using P3D.
PeasyCam v105
Exception in thread "Animation Thread" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1084)
at processing.core.PApplet.handleMouseEvent(PApplet.java:2532)
at processing.core.PApplet.dequeueEvents(PApplet.java:2463)
at processing.core.PApplet.handleDraw(PApplet.java:2153)
at processing.opengl.PGL$PGLListener.display(PGL.java:2472)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:548)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:533)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:280)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:904)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:822)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:543)
at processing.opengl.PGL.requestDraw(PGL.java:814)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1566)
The library is compatible with 1.5.1 (JAVA2D, P2D, P3D) and 2.0b6 (JAVA2D, P2D, P3D/OPENGL) in fact it works seemlessly in all these renderers and with libraries such as PeasyCam (see the included examples G4P_Torroid and G4P_with_PeasyCam)
The library package name has changed so this version can co-exist with previous versions inside the Processing IDE without causing problems. It means that you still work on all those old sketches using earlier versions of G4P while using this new version in new sketches.
When I try to use the registerMethod in my library I get an exception error but not in the pde.
The listings below demonstrate the problem.
In Eclipse I got the following exception:
Exception in thread "Animation Thread" java.lang.NoSuchMethodError: tests.PreTest.registerMethod(Ljava/lang/String;Ljava/lang/Object;)V at tests.PreTest.setup(PreTest.java:9) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:722)
I have tried using both 32bit and 64bit Procesing libraries.
Has you experienced the same problem? If so do you have a solution? Any ideas?
It includes a new class Extrusion. The extrusion takes a user defined 2D contour and user defined 3D path and then draws the extruded shape along this path. Also the user can define the scaling to be used along the path. The library has some pre-defined classes for contour (rod & I-beam), path (Bezier spine, Bezier 3D and linear) and scaling (constant, tapered). It also includes 3 new examples that demonstrate how easy it is to create your own contour, path and scaling classes.
For the more adventurous the Xshape class has been updated and includes an example of how to add add your own shape.
This release has been tested with Processing V2.0b3 and some of the examples need the PeasyCam library.
set the pickBuffer transofrmation matrix to match the on-screen matrix
then draw each shape onto the buffer in a different colour
find the colour at the mouse position
find the matching object (if any) and return it.
The actual code is shown below. In mousePresssed I call this method to identify the shape clicked on unfortunately it doesn't work now (it used to in 1.5.1) i.e.
when the mousePressed (or any input event handler) method is executed does the transformation matrix still reflect changes made in draw?
would it be better to call this shape picker method from inside draw after any camera() commands?
is there a better / more 'proper' way of setting the transformation matrix in the off-screen buffer than the way I have done it (lines 7 & 8 in the code below)?
I suspect from my experience that the answers to the first 2 questions are going to be no/yes. The third question I don't know the answer so I would be interested in any response or detail related to how Processing works under the hood.
Thanks
Shape picking code
public static Shape3D pickShape(PApplet papplet, int x, int y){
I am keen to make use of the new event handling mechanism for libraries provided in V2.0b2. I know that there is documentation to come and perhaps I am being a bit hasty but I decided to do some experiments for my own benefit.
In the code below I have succeded in creating an object that handles mouse events with the current mouse position being updated all the time. It does not appear to be capturing key events. I am probably doing something wrong but I can't see it - must be tunnel vision.