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 jruby + processing and processing.py

Tuesday, 26 May 2009

Collections in Processing

Welcome to our old friend ArrayList, which can be used in processing, its back to the old days of storing objects, and recasting them back to what you knew you had stored in the first place.....ie no parameterized lists.......
Also don't try getting to clever you can't store the ArrayList as a generic List.....
Well that's not exactly true (however you need to import java.util.List, because List could be ambiguous).

   1:import processing.core.*;
2:// import java.util.List; if you want use a generic List uncomment this line
3:
4:ArrayList vertices; // declare an expandable collection class
5:
6:void setup() {
7: size(400, 400);
8: vertices = new ArrayList(); // initialise the collection class
9: background(255);
10:}
11:// record vertex when mouse clicked (you can keep going even after drawing has been rendered)
12:void mousePressed() {
13: vertices.add(new PVector(mouseX, mouseY)); // adds an anonymous PVector instance
14:}
15:
16:// Pressing any key draws the currently stored vertices as a line strip
17:void keyPressed() {
18: float x = 0.0f;
19: float y = 0.0f;
20: PVector vert; // a temporary PVector instance to hold an instance of PVector read from the collection
21: stroke(255, 0, 0);
22: strokeWeight(5);
23: noFill();
24: beginShape(); // begin the recording of vertices
25: for (int i = 0; i < vertices.size(); i++) { // iterating the verices ArrayList
26: vert = (PVector)vertices.get(i); // need to cast the stored object to PVector
27: x = vert.x;
28: y = vert.y;
29: vertex(x, y); // the vertex to be recorded
30: }
31: endShape();
32:}
33:
34:void draw(){ // probably required to keep program running
35:}



PS I can confirm that if you post pre-formatted text from jEdit to the blog there is no issue with carriage return/linefeed etc creating a new line, see Sharons blog if you are interested about the linefeed issue. I have also updated (my personal) jEdit processing mode to include ArrayList a late addition?

Thursday, 7 May 2009

Second Chunk

I've volunteered to create another chunk for the book, it is one of the five such chunks providing examples of the vertex function.
Heres the link http://martinpchunk42.blogspot.com/
In this chunk I will describe how to create line strips using vertex functions.The sketches will feature 'aesthetically' pleasing logarithmic spirals base on the Fibonacci series which approximates to the 'golden ratio' at limit.
Following one of Sharon Dawes postings I have cracked how to present my vim syntax highlighted code without double space. As Sharon noted when you enter you code into the blog line feeds are taken as a new html line, since vim correctly already puts a <br> at the end of each line, thats leads to double spaced lines, so now I've been removing it. As an extra refinement I'm now adding line numbering back into my syntax highlighted code, I'm a pretty poor vimmer but now I've found the :set nu command that gives line numbers (lacks the fancy look from the jEdit code2html plugin).

Tuesday, 5 May 2009

New Blog for Ruby Processing

I have started a new blog to publish my experiments with ruby-processing http://learning-ruby-processing.blogspot.com
I have recently been developing some code in parallel (sometimes first in the processing ide, sometime first in ruby-processing) between java processing and ruby-processing, and java is just plain clunky....
Finally I have managed to convert my animated saucer/with dynamic starfield applet to ruby-processing (some crazy saucer shifting behaviour I've yet to understand, but otherwise works pretty well). After that exercise I reckon I could probably re-factor my java code, funny how programming in different languages can give different insights!!!
By the way if you didn't know it both netbeans and JEdit hava special features that support programming in ruby, probably thanks to jruby and the popularity of ruby on rails.

Saturday, 2 May 2009

Bloggers finally coming to the table

Some well dormant blogs finally flickering into action, however I don't see the deadline being met, and it wasn't meant to be like this, it can hardly be a collaborative effort when all posting is left to the twelfth hour or as final chunk whatever!!!
I've been a bit inactive of late because my dad was ill then died, something that I couldn't have predicted when I signed up for the project.
If anyone is interested I have cracked how to get a full width console look, see my other blog at
http://martinpchunk68.blogspot.com/ my code highlighting is now using in text body formatting (ie no css). The html format produced by using the vim command :runtime syntax/2html.vim from a vim console. I really can't see why most bloggers are putting up with writing to less than half screen width....................

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2