Skip to content

Instantly share code, notes, and snippets.

@kernalphage
Last active August 15, 2016 03:29
Show Gist options
  • Select an option

  • Save kernalphage/54486a23110b03fb361e to your computer and use it in GitHub Desktop.

Select an option

Save kernalphage/54486a23110b03fb361e to your computer and use it in GitHub Desktop.
some hexagons spinning around for your pleasure. Works with P5js
//rendered gif can be found at https://imgur.com/gallery/uADuMZE/
//a rotational for each loop, Runs fn() Spokes times, evenly spaced along a circle len width
//supports fractional spokes for 'unfolding'
function rotational_for(spokes, len, fn) {
var di = TAU / spokes;
for (var i = 0; i < spokes; i++) {
push();
angle =i*di
translate(sin(angle)*len, cos(angle)*len, 0);
fn(angle, len);
pop();
}
}
//rotate a cube to look good
function hexagon(sz,angle,len) {
push();
translate(sin(angle+breath)*len, cos(angle+breath)*len,0);
rotateX(PI / 4);
rotateY(PI / 4);
ssz = sz * (1.5 + (sin( breath*3))/2);
box(ssz,ssz,ssz);
pop();
}
function setup() {
createCanvas(540,540, WEBGL);
ortho(-width / 2, width / 2, height / 2, -height / 2, 0.1, 10);
}
function draw() {
//eyeballed colors and sizes
background(20, 25, 33);
sz = 300;
scl =.336;
ambientLight(45, 57, 63);
//linear time, scaled down
breath = frameCount * .01;
//this makes the fractional bit ease in, but overall it still increases linearally
br = floor(breath);
bf = pow(breath - br,5);
breath = br + bf;
//1 breath is 1/(n*2)th rotation.
leaves = 6;
breath=breath*(TAU/leaves)
pointLight(48, 59, 76, sin(breath + PI/3)*sz,cos(breath + PI/3)*sz,10); //out of phase
pointLight(190, 136, 75, sin(breath)*sz,cos(breath)*sz,10);
//signgle set of 6 hexagons
petal = function(angle,len){
rotational_for(leaves, len*scl,
hexagon.bind(undefined, len*scl*scl));
};
//set of 6 petals
dbl = function(angle,len){
//fill the center with a petal
petal(angle, scl*len);
rotational_for(leaves,len*scl, petal)
}
//fill the center with a double set
dbl(0,sz);
//a set of 6 dbl petals
rotational_for(leaves, sz, dbl );
}
@kernalphage
Copy link
Author

Example: 2016-01-11 18_08_11-rotational_for

https://imgur.com/gallery/uADuMZE/

Using Processing5 JS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment