“Fibonacci Cap” by sean matthews
https://openprocessing.org/sketch/558955
License CreativeCommons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
UP/DOWN arrows
CC Attribution ShareAlike
Fibonacci Cap
matthews
xxxxxxxxxx
float R = 277;
float rotationX = 0;
float rotationY = 0;
float velocityX = 0;
float velocityY = 0;
float pushBack = 0;
float ga = (3 - sqrt(5)) * PI;
int kMaxPoints = 100000;
int nbrPoints = 2000;
float capHeight = 0.75;
float heightChanged = false;
// To add: Give each point a heading and velocity, adjust based on distance/heading to nearby points.
class SpherePoint {
float lat,lon;
SpherePoint(float lat, float lon)
{
this.lat = lat;
this.lon = lon;
}
};
SpherePoint[] pts = new SpherePoint[kMaxPoints];
void initSphere()
{
int usePts = (capHeight/2.0) * min(nbrPoints,pts.length);
for (int i = 1; i <= usePts; ++i) {
float lon = ga*i;
lon /= 2*PI; lon -= floor(lon); lon *= 2*PI;
if (lon > PI) lon -= 2*PI;
// Convert dome height (which is proportional to surface area) to latitude
float lat = asin(1 - 2*i/(float)nbrPoints);
pts[i] = new SpherePoint(lat, lon);
}
}
void setup()
{
// size(1024, 768, P3D);
size(600, 600, P3D);
R = .8 * height/2;
initSphere();
colorMode(HSB, 1);
background(0);
}
void draw()
{
if(heightChanged)
{
initSphere();
heightChanged = false;
}
background(0);
smooth();
renderGlobe();
rotationX += velocityX;
rotationY += velocityY;
velocityX *= 0.95;
velocityY *= 0.95;
// Implements mouse control (interaction will be inverse when sphere is upside down)
if(mousePressed){
velocityX += (mouseY-pmouseY) * 0.01;
velocityY -= (mouseX-pmouseX) * 0.01;
}
}
void renderGlobe()
{
pushMatrix();
translate(width/2.0, height/2.0, pushBack);
float xRot = radians(-rotationX);
float yRot = radians(270 - rotationY - millis()*.01);
rotateX( xRot );
rotateY( yRot );
strokeWeight(3);
float elapsed = millis()*.001;
float secs = floor(elapsed);
float usePts = (capHeight/2.0) * min(nbrPoints,pts.length);
for (int i = 1; i <= usePts; ++i)
{
float lat = pts[i].lat;
float lon = pts[i].lon;
pushMatrix();
rotateY( lon);
rotateZ( -lat);
float lum = (cos(pts[i].lon+PI*.33+yRot)+1)/2;
stroke(.5,.5*lum,.2+lum*.8);
point(R,0,0);
popMatrix();
}
popMatrix();
}
void keyPressed()
{
if (keyCode == UP)
{
capHeight -= 0.1;
}
else if (keyCode == DOWN)
{
capHeight += 0.1;
}
capHeight = min(capHeight, 2.0);
capHeight = max(capHeight, 0.1);
heightChanged = true;
}
See More Shortcuts