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

Wednesday, 3 June 2009

A Smoother Nautilus Shape

For my chunk 42 I presented an approximate Nautilus shape using the vertex function, now I've finished that section I thought it would be nice to produce a more realistic shape, here is the processing code now using curveVertex and curve functions.

   1:// nautilus.pde
2:float A = 0.8f;
3:float B = 1.4f;
4:ArrayList pvect;
5:
6:float x, y, x0, y0, x1, y1, x2, y2, x3, y3;
7:void setup(){
8: size(300, 300);
9: pvect = new ArrayList(42); // 42 the answer to the ultimate question
10: PVector tmp;
11: PVector tmp0;
12: PVector tmp1;
13: PVector tmp2;
14: PVector tmp3;
15:
16: translate(width/2, height/3);
17: rotate(PI - QUARTER_PI);
18: smooth();
19: // Todo: draw curved septa (internal chamber walls)
20: background(255); // NB: looks neater if we draw the radial lines first
21: strokeWeight(1);
22: stroke(0, 0, 255);
23:
24: for (int i = 0; i < 41; i++){
25: x = getX(i*A);
26: y = getY(i*A);
27: pvect.add(new PVector(x, y));
28: }
29: for (int z = 8; z < pvect.size() - 1; z++){ // note we start 8 segments in because...
30: tmp0 = (PVector)pvect.get(z + 1);
31: tmp1 = (PVector)pvect.get(z); // on curve
32: tmp2 = (PVector)pvect.get(z - 8); //on curve
33: tmp3 = (PVector)pvect.get(z - 7);
34: x0= tmp0.x;
35: y0 = tmp0.y;
36: x1= tmp1.x; // we would have negative increments otherwise
37: y1 = tmp1.y;
38: x2= tmp2.x;
39: y2 = tmp2.y;
40: x3= tmp3.x; // we would have negative increments otherwise
41: y3 = tmp3.y;
42: curveTightness(-0.8f);
43: curve( x0, y0, x1, y1, x2, y2, x3, y3); // draw the radial lines
44: }
45: strokeWeight(4);
46: stroke(255, 0, 0);
47: noFill();
48: curveTightness(0.0f);
49: beginShape(); // begin spiral 'shell' shape
50: for (int v = 0; v < pvect.size(); v ++){
51: tmp = (PVector)pvect.get(v);
52: curveVertex(tmp.x, tmp.y); // successive calls to curveVertex a variation on curve?
53: }
54: endShape();
55: saveFrame("nautilus.png");
56:}
57:
58:float getX(float theta){
59: return A*cos(theta)*exp(theta/tan(B));
60:}
61:
62:float getY(float theta){
63: return A*sin(theta)*exp(theta/tan(B));
64:}


Here is the smoother Nautilus:

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