|
Author |
Topic: phyllotaxis spiral lattice (Read 938 times) |
|
Ethan
|
phyllotaxis spiral lattice
« on: Dec 19th, 2004, 8:09pm » |
|
I was trying to implement the function from this page on phyllotaxis: http://www.math.smith.edu/~phyllo/About/Lattices/SpiralLattices.html The code below doesn't result in anything that looks like a pattern. Any ideas why? I've tried converting to radians too, with no luck. Code: void setup(){ size(360,240); float G = 1.0; float Ginc = 0.0002; float d = 0; float dinc = 137.5; float xpt; float ypt; push(); translate(width/2, height/2); for(int k = 0; k < 200; k++){ xpt = pow(G, k) * cos(k*d); ypt = pow(G, k) * sin(k*d); //xpt = sqrt(k*G) * cos(k*d); //ypt = sqrt(k*G) * sin(k*d); point(xpt, ypt); G += Ginc; d = (d + dinc) % 360; } pop(); } void loop(){ } |
|
|
|
|
|
sspboyd
|
Re: phyllotaxis spiral lattice
« Reply #1 on: Dec 19th, 2004, 9:19pm » |
|
I worked on something similar. Its not fast but it works: Code:/* This program will place a square in an ever enlarging spiral (determined by the GM) stephen boyd - gmail.com acct, username is sspboyd proce55ing.net */ // dimensions of canvas int dimY = 600; int dimX = 971; float gm = 137.5077640500378; // golden mean ratio float spacer = 0.6176470588235294/2; // the incremental distance I want the // radius to increase by (21/34)/2 int iNodeCentreX = dimX/2; // starting point for nodes int iNodeCentreY = dimY/2; int iNodeX = 0; // initial radius int iNodeY = 0; int iNode = 0; // current node number int maxNodes = 1000; // number of nodes to create float currAngle = 0; // current angle boolean shoot = false; // flag to manage taking a image of the final shot // P5 ENVIRONMENTAL METHODS ++++++++++++++++++++++++++++++++++++++++++ void setup(){ size(dimX, dimY); background(255); noStroke(); rectMode(CENTER_DIAMETER); } void loop(){ if (iNode < maxNodes){ placeNode(); iNode +=1; } else if(shoot){ // save("phiSquares.tif"); shoot = false; } } // METHODS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++ // placeNode() is a routine to place a square at an x y position based // on the GM and an incrementing radius void placeNode(){ currAngle += gm; // increase the angle by the gm iNodeX = int((spacer * iNode) * sin(radians(currAngle)) + iNodeCentreX); //radius * sin(angle) + the offset distance iNodeY = int((spacer * iNode) * cos(radians(currAngle)) + iNodeCentreY); float scaleDot = currAngle / (gm*maxNodes); // value 0-1 based on distance from origin int clrVals = int(scaleDot*255); // fill(clrVals,clrVals,clrVals); // creates clr based on hsb fill(clrVals); // creates shade of grey // rotate(radians(currAngle)); // not using these yet // translate(iNodeX, iNodeY); // ellipse(iNodeX, iNodeY, 10, 10); rect(iNodeX, iNodeY, int(25*scaleDot), int(25*scaleDot)); // draws rectangle } |
|
|
gmail.com w/ sspboyd username
|
|
|
|