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.
IndexDiscussionExhibition › Kinda live coding through reflect on two windows
Page Index Toggle Pages: 1
Kinda live coding through reflect on two windows (Read 678 times)
Kinda live coding through reflect on two windows
Mar 18th, 2008, 12:21pm
 
This is just a very early proof of concept, so don't expect anything to fancy.

I've been looking into the java.lang.reflect library to see if it would be possible to use it to create a sort of live coding environment. Well, it can... sort of.

It's by no means perfect, and it'll require a thorough look through the pApplet docs, for example - the background command actually only accepts an integer, not a color, but it is possible.

So, what this code does is;
1. Create an embedded applet in a new window, so you have to processing sketches at once
2. Create a callStack array, that contains the command name and the parameters as an Object[] array.
3. The embedded applet then calls everything on the callStack, through reflective programming from the parent app.

You can click the larger embedded app to randomise the lines and color.


So, yeah it's got a long way to go before its perfect, i'm sure if you gave it anything slightly harder to do, it'd choke immediately.

It needs a lot of error handling and stuff to make it more user friendly, or perhaps a 'pre' function that makes sure that the parameters are passed in the correct format, or maybe creating a hash table from the pApplet's commands to ensure it gets it right first time.

anyway, you can download the source here;

http://www.graphicfilth.com/_2wndapplet.zip

Download it, add to it, improve it (and post it back here!), do what ever you want.

Martin

(apologies for the messy coding)
Re: Kinda live coding through reflect on two windo
Reply #1 - Mar 20th, 2008, 5:00pm
 
Hey Martin.

It's cool what you're doing with java.lang.reflect, but have you taken a look at Ruby-Processing? Because Ruby is interpreted, you can code on the fly, changing variables, redefining methods, and even mixing up classes as you go. You can rewrite your draw loops, call methods on your sketch, or whatever.

You can get it at:
http://the-shoebox.org/apps/44

Good luck.

Re: Kinda live coding through reflect on two windo
Reply #2 - Mar 22nd, 2008, 3:30pm
 
Thanks for telling me about that, I'll definitely have a look into using that!
Re: Kinda live coding through reflect on two windo
Reply #3 - Mar 22nd, 2008, 3:56pm
 
Hey Manic.

I just wanted to give you the quick breeze-through for live coding, because it's something that I've been playing with. Once you have your Ruby-Processing set up, the best way to get started is to go inside the Ruby-Processing folder and do like this:

>> jirb

JIRB will open up, leaving you with a prompt. I'm going to open up jwishy.rb as an example, but you would choose to open your sketch here.

>> require 'samples/jwishy'

A window will pop open on the side, with the Sketch playing inside of it.

>> app = Processing::App.current

This will give you a handle on the instance of the app, and now you can go to town.

>> app.magnitude = 3

This will set the "@magnitude" instance variable of the app. But you can also, say, redefine a method, even the methods that are part of the Processing core. So:

>> def app.oval( x, y, width, height )
>>     rect x, y, width, height
>> end

So now when the app goes to draw an oval (or an ellipse), it'll make a rect instead, converting the fluid WishyWorm into more of a Robo-worm. As soon as you press return on that last line, the changes go into effect.

Have fun with it.
— Jeremy
Page Index Toggle Pages: 1