We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 3 
LiveCode (Read 15327 times)
Re: LiveCode
Reply #30 - Jan 20th, 2006, 8:09pm
 
Thanks for the kind words and I am happy to see someone else having fun playing with it.

Here is a newer version using a MD5 hash to eval the draw script only if it is changed, to reduce the disk I/O. This time all necessary files should be included.
http://rzserv2.fhnon.de/~lg016586/processing/Processing_Interpreter_Demo-001.zip

Alex, I will take a look at your work later for sure!!

I feel like I won't post it over at ToplapSytems wiki, as this is an too simple approach for showing it with real livecoding apps. This is really no special work, because most of it is just wrapping to avoid the try/catch stuff in main sketch and maybe there is a lot more work needed to have a live coding session with it.
Re: LiveCode
Reply #31 - Feb 23rd, 2006, 5:08am
 
Could someone repost the LiveCode library ? The FloHimself links seem to be dead.
Thanks Smiley
Re: LiveCode
Reply #32 - Feb 23rd, 2006, 11:41pm
 
Links should work again.
Re: LiveCode
Reply #33 - Nov 23rd, 2006, 5:34am
 
Does the bsh stunt work with P3D or OPENGL?  I've been able to get bsh scripts using JAVA2D just fine, but not otherwise.

When using P3D, I get errors like this: (sorry for huge dump)
Error while running applet.
java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at bsh.Reflect.invokeMethod(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.Name.invokeLocalMethod(Unknown Source)
       at bsh.Name.invokeMethod(Unknown Source)
       at bsh.BSHMethodInvocation.eval(Unknown Source)
       at bsh.BSHPrimaryExpression.eval(Unknown Source)
       at bsh.BSHPrimaryExpression.eval(Unknown Source)
       at bsh.BSHBlock.evalBlock(Unknown Source)
       at bsh.BSHBlock.eval(Unknown Source)
       at bsh.BshMethod.invokeImpl(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.This.invokeMethod(Unknown Source)
       at Processing.setup(BeanShell Generated via ASM (www.objectweb.org))
       at processing.core.PApplet.handleDisplay(PApplet.java:1240)
       at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
       at processing.core.PApplet.run(PApplet.java:1409)
       at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.RuntimeException: new renderer
       at processing.core.PApplet.size(PApplet.java:884)
       at processing.core.PApplet.size(PApplet.java:815)
       ... 23 more
java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at bsh.Reflect.invokeMethod(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.Name.invokeLocalMethod(Unknown Source)
       at bsh.Name.invokeMethod(Unknown Source)
       at bsh.BSHMethodInvocation.eval(Unknown Source)
       at bsh.BSHPrimaryExpression.eval(Unknown Source)
       at bsh.BSHPrimaryExpression.eval(Unknown Source)
       at bsh.BSHBlock.evalBlock(Unknown Source)
       at bsh.BSHBlock.eval(Unknown Source)
       at bsh.BshMethod.invokeImpl(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.BshMethod.invoke(Unknown Source)
       at bsh.This.invokeMethod(Unknown Source)
       at Processing.setup(BeanShell Generated via ASM (www.objectweb.org))
       at processing.core.PApplet.handleDisplay(PApplet.java:1240)
       at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
       at processing.core.PApplet.run(PApplet.java:1409)
       at java.lang.Thread.run(Thread.java:613)
Caused by: java.lang.RuntimeException: new renderer
       at processing.core.PApplet.size(PApplet.java:884)
       at processing.core.PApplet.size(PApplet.java:815)
       ... 23 more

I'm simply building a bsh script without any intermediate classes like this:

#!/usr/bin/env bsh

addClassPath("/Applications/Processing 0121/lib/core.jar");
import processing.core.*;

class Processing extends PApplet {
 public void setup() {
   size(600, 500, JAVA2D); // works
   //nope: size(600, 500, P3D); // P3D
 }
 public void draw() {
   background(128);
   fill(255,255,0);
   stroke(255,0,0);
   rect (random(width),random(height), 10,10);
   if (frameCount%10==0)
     println("frameRate="+frameRate+" frameCount="+frameCount);
 }
}

processing=new Processing();
frame = new JFrame( "My Frame" );
frame.setResizable(false);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.add(processing);
processing.init();
while (processing.defaultSize&&!processing.finished)
 try {Thread.sleep(5);} catch (Exception e) {println(e);}

frame.pack();
frame.setVisible(true);

Re: LiveCode
Reply #34 - Nov 23rd, 2006, 6:05am
 
I just noticed the interest in rhino.  I've built a test in rhino that work well enough, although the javascript language is a bit odd.  I've also done a jython version.  It may be closer to a Live environment .. just modify a function and it should "take" right away.
 http://backspaces.net/hacks/30/processing-with-jython

The trick to running rhino on a .js file is this:
export CLASSPATH=~/local/processing/lib/core.jar
java -cp ~/local/rhino/js.jar:.:$CLASSPATH \
org.mozilla.javascript.tools.shell.Main RandBoxes.js

.. note that ~/local will be different on your system.

The test file, RandBoxes.js is here:
importPackage(Packages.processing.core)
// Class RandBoxes:
function RandBoxes(w,h,n) {
 this.w = w
 this.h = h
 this.n = n
 this.boxes = new Array(n)
}
RandBoxes.prototype = {
 setup: function() { with(this) {
   size(w, h, JAVA2D)
   for (var i = 0; i<n; i++)
     boxes[i] = new Box(this, random(w), random(h))
   println("boxes[0].c = "+ boxes[0].c)
   println("color(255,255,255) = "+ color(255,255,255))
 }},
 draw: function() {
   this.background(128)
   for (var i = 0; i<this.n; i++)
     this.boxes[i].step()
   if(this.frameCount % 10 == 0)
     this.println("frameRate="+this.frameRate+" frameCount="+this.frameCount);
 }
}
// Class Box:
// Problem: fill(c) chooses float overload, thus "gray"
// Can fix w/ proxy class for RandBoxes to subclass.
// http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html
function Box(p, x, y) {
 this.p = p
 this.x = x
 this.y = y
 //var i255 = new java.lang.Integer(255)
 this.c = p.color(255,255,0)
 //this.c = 0xFFFFFF00
}
Box.prototype = {
 step: function() { // with not used: 10% slowdown
   this.x += this.p.random(-1, 1)
   this.y += this.p.random(-1, 1)
   this.paint();
 },
 paint: function() {
   this.p.noStroke();
   //this.p.fill(this.c); //overload: chooses fill(float gray)
   this.p.fill(255,255,0); //cheat, a tad slower
   this.p.rect(this.x-2, this.y-2, 5, 5);
 }
}

panel=new JavaAdapter(PApplet, new RandBoxes(600,500,1000))

frame = new Packages.javax.swing.JFrame
frame.add(panel)
frame.setResizable(false)
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);

panel.init()
while (panel.defaultSize && !panel.finished){}
frame.pack()
frame.visible = true
Re: LiveCode
Reply #35 - Nov 25th, 2006, 7:20pm
 
(Sorry to spam the list, but I thought some folks could use this.  PLEASE let me know if you can improve this .. I plan to put it on my web site as a mini-tutorial.)

Here's the deal: I sometimes want to use Processing in an interpretive environment.  For example, I'm studying transforms and the camera, and being able to manipulate the camera in an interpreted environment is way nice!

I tried beanshell, but ran into trouble with using P3D.  I've got a message into their list to see if I just made a dumb mistake.  But in the mean time, I decided to use Jython: its so clean and uncluttered, and is used quite a bit by my co-workers at redfish.com.

My solution was to build a simple Jython package, proctools, which has a single procedure which creates a JFrame with a PApplet.  The procedure takes arguments for the window size, a 2D/3D flag, and a frameRate number .. where "0" means calling noLoop() .. letting you call redraw() in the Jython session instead.

The PApplet has a no-op draw() method initially.  You simply replace that method within your interactive session.  The code is here, and also at the end of this message if you'd prefer to cut/paste:
 http://backspaces.net/files/proctools.py

To use proctools, download the file to a convenient directory.  I prefer starting with an empty one, because Jython will create a few files of its own.  You can also add data to this directory such as fonts and images etc.  Before you start jython, make sure you've set the CLASSPATH:
 export CLASSPATH=~/local/processing/lib/core.jar:.

Then start jython, importing proctools.  In the following sample session, I build a simple scene for camera navigation experiments.  Note that I've included Arial-Black-24.vlw in the directory I'm using:

from proctools import startProcessing
p = startProcessing(600,400,True,2)
p.textFont(p.loadFont("Arial-Black-24.vlw"))

def drawScene(p):
   p.background(200)
   p.noStroke()
   p.fill(200,0,0)
   p.sphere(50)
   p.stroke(0)
   p.fill(255, 255, 255, 200)
   p.rect(-200,-200,400,400)
   len = p.width/2
   p.line(0,0,0,len,0,0)
   p.line(0,0,0,0,len,0)
   p.line(0,0,0,0,0,len)
   p.fill(255,0,0)
   p.text("X",len,0,0)
   p.text("Y",0,len,0)
   p.text("Z",0,0,len)

p.drawProc = drawScene
len = p.width*.75
p.camera(len,len,len,  0,0,0,  0,0,-1)

.. and so on..

Let me know if this works for you, and any improvements you spot .. this is VERY raw, and I'm definitely a Python newbie.  I'd love to figure out how to avoid the p.xxx everywhere, for example .. like javascript's "with" statement.

Owen

The code for proctools.py:
# Enable use of processing and local classes (such as proxies) and packages.
# export CLASSPATH=~/local/processing/lib/core.jar:.
from javax.swing import JFrame
from processing.core import PApplet

class Processing(PApplet):
   def __init__(self, w, h, use3D, rate):
       self.w = w
       self.h = h
       self.use3D = use3D
       self.rate = rate
       self.drawProc = None
   def setup(self):
       if self.use3D:
           self.size(self.w, self.h, self.P3D) # JAVA2D P3D OK
       else:
           self.size(self.w, self.h, self.JAVA2D) # JAVA2D P3D OK
       if self.rate==0:
           self.noLoop()
       else:
           self.frameRate(2)
   def draw(self):
       if self.drawProc == None:
           pass
       else:
           self.drawProc(self)

def startProcessing(width, height, use3D, rate):
   p = Processing(width, height, use3D, rate)
   frame = JFrame(title="Processing",
       resizable = 0,
       defaultCloseOperation=JFrame.EXIT_ON_CLOSE)
   #p.frame = frame;
   p.init()
   while p.defaultSize and not p.finished:
       pass
   frame.add(p)
   frame.pack()
   frame.visible = 1
   return p
Re: LiveCode
Reply #36 - Feb 27th, 2007, 9:16am
 
So we're going into the second day of a workshop dealing with some of these themes and in preparation I experimented quite a bit with FloHimself’s code:

FloHimself wrote on Jan 20th, 2006, 8:09pm:
Here is a newer version using a MD5 hash to eval the draw script only if it is changed, to reduce the disk I/O. This time all necessary files should be included.
http://rzserv2.fhnon.de/~lg016586/processing/Processing_Interpreter_Demo-001.zip


Some people have had some problems using P3D, but this can be hacked in various ways -- for one just by forcing the sketch to be in 3D from the get-go. But then a problem arises with the interpreter: since the variables are dynamically typed, it creates doubles whenever it discovers a 2.3, 3.14, 666.999, etc, etc. Processing doesn't like doubles, it likes floats.

One solution, which becomes quite annoying but works, is to force variables to remain floats and then you can livecode in 3d. But it's not a realistic solution and just too much of a pain to make it work.

So given that we only have three days left before our performance, we're going with a different system that we're building ourselves with OSC as a base. But it's still an interresting prospect to livecode in Processing and a lot of fun (despite all the troubles).

Oh, I should mention that I've also found the above solution quite slow. There are a few hacks to speed it up, but not all that serious.
Re: LiveCode
Reply #37 - Feb 27th, 2007, 1:42pm
 
hi douglas,

i based a tool on florians example a while ago. i never released it because it's hacked into the svn version of processing. it basically uses the current tab open in processing as input to beanshell.

an os-x example is here:
http://www.bezier.de/slc/Processing%200115-slc.zip
( you have to use Processing->Tools->SimpleLiveCoding or Command-L to run the included examples )

a newer version of the source is here:
http://www.bezier.de/slc/SimpleLiveCoding.zip

to make it work you have to remove:
  import processing.app.tools.*;
and
 extends Tool
from
SimpleLiveCoding.java

then check-out the latest svn version

then add the SLC to:
processing/app/tools
( i think it might need a package processing.app.tools; )
and create an instance inside (Editor.java).buildToolsMenu() just as the other standard tools are done in Processing.

let me know if you run into trouble ...

F
Re: LiveCode
Reply #38 - Mar 1st, 2007, 4:37am
 
Thanks for the tutorial and file. I downloaded it, but I'll have to try it later. We're 24-hours until the public representation, and we've built our own funky thing that isn't really Livecode, but it's close enough for our needs. So I'll check out your solution when it's all over and I have a moment free.
Re: LiveCode
Reply #39 - Aug 15th, 2007, 5:02pm
 
not sure if it's what you want, but if you're talking about livecoding you got tocheck out vvvv from http://www.vvvv.org
that's the fastest manipulation of programmingstructures at runtime i've ever seen.
that's no processing at all, but see for yourself...
Re: LiveCode
Reply #40 - May 28th, 2008, 10:23pm
 
Hi, sorry to resurrect a dead thread.

I'm trying out Flo's liveCode library, but i'm getting the following error;

Quote:
Sourced file: C:\processing-0135\examples\Demo\data\setup.bsh : Exception invoking imported object method. : at Line: 2 : in file: C:\processing-0135\examples\Demo\data\setup.bsh : size ( 200 , 200 )

Target exception: java.lang.reflect.InvocationTargetException


Processing is printing a String from Processing

Sourced file: C:\processing-0135\examples\Demo\data\draw.bsh : illegal use of undefined variable, class, or 'void' literal : at Line: 3 : in file: C:\processing-0135\examples\Demo\data\draw.bsh : , i / 2 , i / 2 , i * 2 ) ;



Does anyone know how to fix it?

EDIT: fixed it, turns out it didn't like having setup called from beanshell, which is fine with me, and that the draw.bsh file was using an undeclared variable and I hadn't bothered to look. Here's to reading error messages!


Cheers
Martin
Pages: 1 2 3