A Blog Exploring Digital Art

Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore ruby/rp5. and processing.py

Thursday, 25 April 2013

Updating My MeshToVBO library (for hemesh-1.8.1 and processing-2.0b8)

I have recently updated my MeshToVBO library here. Since githubs change of policy (to not support binary downloads) it is only available as source (so when building you will need to include dependent jars from processing and hemesh, this is best done in an ide eg Eclipse or Netbeans, I will endeavour to write an ant build file). Here is an example displaying library usage (based on a hemesh example sketch).
   1 import mshape.util.*;
   2 import mshape.*;
   3 import wblut.math.*;
   4 import wblut.processing.*;
   5 import wblut.core.*;
   6 import wblut.hemesh.*;
   7 import wblut.geom.*;
   8 
   9 PShape retainedMesh;
  10 ArcBall arcball;   
  11 MeshToVBO mshape;
  12 HE_Mesh mesh;
  13 HEC_IsoSurface creator;
  14 
  15 void setup() {
  16   size(800, 800, P3D);
  17   arcball = new ArcBall(this);
  18   mshape = new MeshToVBO(this);  
  19   smooth(16);
  20 
  21   // Create an isosurface from an explicit grid of values.
  22   // Potentially uses a lot of memory.
  23 
  24   float[][][] values=new float[51][51][51];
  25   for (int i = 0; i < 51; i++) {
  26     for (int j = 0; j < 51; j++) {
  27       for (int k = 0; k < 51; k++) {
  28         values[i][j][k]=2.1*noise(0.07*i, 0.07*j, 0.07*k);
  29       }
  30     }
  31   }
  32 
  33   creator = new HEC_IsoSurface();
  34   creator.setResolution(50, 50, 50);// number of cells in x,y,z direction
  35   creator.setSize(8, 8, 8);// cell size
  36   creator.setValues(values);// values corresponding to the grid points
  37   // values can also be double[][][]
  38   creator.setIsolevel(1);// isolevel to mesh
  39   creator.setInvert(false);// invert mesh
  40   //creator.setBoundary(100);// value of isoFunction outside grid
  41   // use creator.clearBoundary() to rest boundary values to "no value".
  42   // A boundary value of "no value" results in an open mesh
  43 
  44   mesh = new HE_Mesh(creator);
  45   noStroke();
  46   // stainless steel
  47   retainedMesh = mshape.meshToRetained(mesh, color(224, 223, 219));
  48 }
  49 
  50 
  51 void draw() {
  52   background(100);
  53   lights();
  54   lightSpecular(80, 80, 80);
  55   directionalLight(80, 80, 80, 0, 0, -1);
  56   ambientLight(50, 50, 50);
  57   translate(400, 400, 0);
  58   arcball.update();
  59   shape(retainedMesh);
  60 }

Sunday, 3 March 2013

Povray ray tracing from processing-2.0b8

I have just made my latest povwriter library available as a zip download at java.net, I returned from github owing to the lack of download support at github. I will consider re-forking the library at github should anyone wish like to get involved in its' development. This library now replaces the original library (processing-1.5.1), however the original is also available as a zip download. The new library has a template installer feature so it should eventually be available for automatic download/update from the processing ide.
To install just put the zip archive in your sketchbook/libraries folder and unzip it there.  Next navigate to the povwriter libraries example (from the processing ide) and select either the README or installer examples. Use the installer example to 1st install the templates, and 2nd to set the path to the povray executable, then you should be good to go. Make sure that you run the other included examples to see how the library works (it is a good idea to explore using different templates, eventually you should bea able to write your own.
Since processing-2.0 it is also possible to run processing sketches from jEdit, now that might also be super convenient, because jEdit has povray support built in. So now you can post edit the processing generated povray files and using my jEdit commando files run povray from jEdit (both ini and pov commando files are available). See below for image of data folder for the ftest example:-
The simplest to adjust the quality setting is to directly edit the ftest.ini file:-
   1 ; ftest.ini
   2 
   3 Input_File_Name=/home/tux/sketchbook/libraries/povwriter/examples/ftest/data/ftest.pov
   4 Output_File_Name=/home/tux/sketchbook/libraries/povwriter/examples/ftest/data/ftest.png
   5 Width=500
   6 Height=500
   7 Declare=ASPECT_RATIO=1.0000
   8 Declare=ZDEPTH=144.3375
   9 Quality=9
  10 Antialias=on
  11 ; Sampling_Method=2
  12 ; Antialias_Threshold=0.3
  13 Max_Image_Buffer_Memory=516
  14 Output_File_Type=N8
  15 Declare=ScaleP5=1.5000

the highest available quality is 11 and the lowest sensible is 3, but your experience may vary. You can also adjust the placement, size and rotation of the processing geometry in the sketch using the Declare feature (ScaleP5 is shown here). This depends on code in the povray template, and / or introduced by the library. In this case ScaleP5 was set in the setup of the processing sketch when the ini file was declared.

Tuesday, 5 February 2013

Parameters in context free art designs

   1 startshape GoldenRatio
   2 
   3 CF::Background = [b -0.2]
   4 
   5 IPHI = 2/(sqrt(5) + 1) 
   6 
   7 shape GoldenRatio{
   8     isocelesAndArc(0.5, IPHI)[alpha -0.9]
   9 } 
  10  
  11 shape isocelesAndArc(number nm, phi) {
  12    isoceles(nm) [alpha nm]
  13    Arc(nm)[alpha nm]
  14    isocelesAndArc(=) [alpha 0.1 s phi x (nm + nm*phi) y (nm - nm*phi) r -90 ]
  15 }
  16  
  17 path Arc(number nm) {
  18     MOVETO(nm, nm)
  19     ARCTO( -nm,  -nm, 1, 1, 90)
  20     CLOSEPOLY()
  21 }
  22 
  23 path isoceles(number nm) {
  24     MOVETO( nm ,nm)
  25     LINETO( -nm , -nm)
  26     LINETO( nm , -nm)
  27     CLOSEPOLY()
  28 }
Click on image to view full size (else you won't see detail)

Friday, 14 December 2012

Adding Mouse Wheel Listener to Sketches

This is an interesting one, I've been having difficulty registering a MouseWheelListener from a library in vanilla processing sketches since processing-2.0b7.  However in this simple ruby-processing sketch it was as easy as pie to add a mouse wheel listener, and what is more it still works with my updated ruby-processing that is based on processing-2.0b7.


   1 # mouse_listener.rb
   2 
   3 class JWheelListener
   4   include java.awt.event.MouseWheelListener
   5 
   6   attr_reader :zoom
   7 
   8   def initialize(zoom)
   9     @zoom = zoom
  10   end
  11 
  12   def mouse_wheel_moved(e)
  13     @zoom += e.get_wheel_rotation * 10
  14   end
  15 
  16 end
  17 
  18 attr_reader :wheel
  19 
  20 def setup
  21     size(1000, 1000)
  22     @wheel = JWheelListener.new(10)
  23     self.add_mouse_wheel_listener(@wheel)   
  24 end
  25 
  26 def draw
  27     background 0
  28     fill 255, 0, 0
  29     ellipse(width/2, height/2, wheel.zoom, wheel.zoom)    
  30 end

Of course it all turned out a bit disapointing when I tried it with a 3D sketch, no mouse wheel action.....

Thursday, 22 November 2012

Whither the MouseWheel in Processing-2.0

What really seems to have buggered things up just recently is the recent adoption of  jogl NEWT (Native Windowing Toolkit), which could be a showstopper for MouseWheel users as the mousewheel listeners (java.awt.etc) are now silently failing......
I kind of hope this issue will just go a away (but I'm not optimistic), so I'm starting of with this posting to my blog, instead of posting to the discussion forum which often gets swamped with homework etc.

It was always the case that library users, or anyone else for that matter who wanted to use the mouse wheel in processing had to write their own MouseWheelListener, however since the introduction of the new processing.event.Event, there was the possibility that we might be able to extend the Event class. Sadly I think there has been a decision not to support the MouseWheel (possibly in favor of the new TouchEvent?).  When I experimented in NetBeans it seemed as though we might be able to access a mouseWheelMoved method of the NEWTMouseAdapter, only to find it had not been implemented. Somewhat annoyingly but probably for good practical reasons it does not throw an unsupportedOperationException, but just silently fails. Here is the the offending line/s of code in PGL.java (r10447):-


  @Override
    public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent e) {
      // Not supported in Processing.
    }

This is the sort of hack that may be required (but probably won't work either because we also need to register the native event listener in the first place).
17     @Override
18     public void mouseWheelMoved(com.jogamp.newt.event.MouseEvent e) {
19       nativeMouseEvent(e, MouseEvent.ROTATE);
20     }
....................
   1 package processing.event;
   2 
   3 public class MouseWheelEvent extends Event {
   4     int rotate = 0;
   5     public MouseWheelEvent(Object nativeObject, long millis, int action, int modifiers) {
   6         super(nativeObject, millis, action, modifiers);
   7         this.flavor = MOUSE;
   8         this.rotate += ((com.jogamp.newt.event.MouseEvent)nativeObject).getWheelRotation();
   9     }
  10     
  11     public int getRotation(){
  12         return rotate;    
  13     }
  14 }
 
Update 2 December 2012, I have proposed an enhancement to processing-2.0 to implement the mouseWheelMoved in processing-2.0 to vote for this enhancement follow this link.
Update 18 January just tried latest svn release (includes preliminary support for MouseWheel) looking good!!!!


   public void mouseEvent(MouseEvent event) {
        if (event.getAction() == MouseEvent.WHEEL) {
            System.out.println(event.getAmount());
            }
        }

Update 11 February 2013 processing development got moved to github see issue/request here:- https://github.com/processing/processing/issues/1461

Sunday, 11 November 2012

Simple object import processing.py

Since processing-2.0 object (wavefront) import is built in. Checkout this sketch, vanilla processing version was a rocket:-
   1 ##
   2 # Load and Display an OBJ Shape. In this a cow
   3 ##
   4 ry = 0
   5 
   6 def setup():
   7   size(640, 360, P3D)
   8   global cow 
   9   cow = loadShape("/home/tux/cow.obj")
  10   
  11   
  12 def draw():
  13   background(0)
  14   lights()
  15   global ry
  16   translate(width/2, height/2, -200)
  17   rotateZ(PI)
  18   rotateY(ry)
  19   scale(50)
  20   shape(cow)  
  21   ry += 0.02

Followers

Blog Archive

About Me

My Photo
Pembrokeshire, United Kingdom
Consolidating my online identity as monkstone. I am a 64 bit linux user and advocate of open source software, you can sometimes find me on the processing forum.