Skip to content

Instantly share code, notes, and snippets.

@jaredly
Last active December 17, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredly/5560644 to your computer and use it in GitHub Desktop.
Save jaredly/5560644 to your computer and use it in GitHub Desktop.
This is my spiral for zen photon garden
// Constants for you to play around with :)
scope.ctx = {
x0: ['cx', 0, -100, 100],
y0: ['cy', 0, -100, 100],
radius0: [100, 10, 200], // pixels
finalRadius: [200, 10, 400],
theta0: [0, 0, Math.PI*2], // in radians. 2*PI = full circle
segments: [10, 3, 50],
segLength: [1, 0, 10, 0.1], // 1 makes a continuous spiral
numCircles: [1, 0.1, 3, 0.1],
transmissive: [0.5, 0, 1],
diffuse: [0, 0, 1],
reflective: [0.5, 0, 1]
};
// calculated, cached constants
var deltaTheta = (Math.PI * 2) * c.numCircles / c.segments
, deltaRadius = (c.finalRadius - c.radius0) / c.segments;
// Create the walls
for (var i=0; i < segments; i+=1) {
var theta1 = c.theta0 + i * deltaTheta
, theta2 = theta1 + deltaTheta * c.segLength
, radius1 = c.radius0 + i * deltaRadius
, radius2 = radius1 + deltaRadius + 20;
add_wall(Math.cos(theta1) * radius1 + c.x0,
Math.sin(theta1) * radius1 + c.y0,
Math.cos(theta2) * radius2 + c.x0,
Math.sin(theta2) * radius2 + c.y0,
c.transmissive, c.reflective, c.diffuse);
add_wall(-Math.cos(theta1) * radius1 + c.x0,
Math.sin(theta1) * radius1 + c.y0,
-Math.cos(theta2) * radius2 + c.x0,
Math.sin(theta2) * radius2 + c.y0,
c.transmissive, c.reflective, c.diffuse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment