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

Saturday, 7 February 2009

Spooky Stuff, there is more than one way to do it

Thought I would take a look at Matrix stuff in processing, turns out it works OK with my Saucer class. So as Larry Wall (he of Perl fame) there is definitely more than one way of doing it, take the code to present three saucer images from my chunk68 (3 instances of saucer), compared to this version which just has one saucer with two translation to produce much the same result:-

   1:void setup() {
2: size(300, 250);
3: Saucer saucer = new Saucer(50.0f, 50.0f); // new saucer centre 50.0f, 50.0f
4: smooth();
5: background(11, 17, 67); // space, the final frontier
6: fill(116, 39, 39); // planet fill
7: ellipseMode(CENTER);
8: ellipse(225, -125, 350, 350); // define the planet
9: saucer.setSize(5.0f);
10: saucer.setColor(color(211, 11, 211));
11: saucer.tilt( QUARTER_PI/2);
12: saucer.render(); // render saucer, if used in animation place in draw()
13: pushMatrix(); // store current coordinate system
14: translate(50, 50); // translate coordinate system
15: saucer.setSize(10.0f);
16: saucer.tilt( QUARTER_PI/4);
17: saucer.setColor(color(255, 0, 0));
18: saucer.render();
19: popMatrix(); // restore original coordinate system
20: translate(160, 110); // now do another translation
21: saucer.setSize(15.0f);
22: saucer.tilt(0.0f);
23: saucer.render(); // color is default Saucer color
24:}
25:
26:// Like Larry says there is more than one way to do it (Spooky stuff)


Code for Saucer is unchanged.

Just for a bit of fun now the international season is upon us...

   1:// the ginger_monster.pde aka neil (Darrel knows!!!) to be continued
2:float x = 50;
3:float y = 100;
4:float angle1 = 0.0;
5:float angle2 = 0.0;
6:float angle3 = HALF_PI;
7:float segLength = 50;
8:
9:void setup() {
10: size(200, 200);
11: smooth();
12: strokeWeight(20.0);
13: stroke(0, 100);
14:}
15:
16:void draw() {
17: background(226);
18:
19: angle1 = (mouseX/float(width) - 0.5) * -PI;
20: angle2 = (mouseY/float(height) - 0.5) * PI;
21:
22: pushMatrix();
23: leg(x, y, angle1);
24: leg(segLength, 0, angle2);
25: foot(segLength, 0, -angle3);
26: popMatrix();
27:}
28:
29:void leg(float x, float y, float a) {
30: translate(x, y);
31: rotate(a);
32: line(0, 0, segLength, 0);
33:}
34:
35:void foot(float x, float y, float a) {
36: translate(x, y);
37: rotate(a);
38: line(0, 0, segLength/4, 0);
39:}

No comments:

Post a Comment

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