Skip to content

Instantly share code, notes, and snippets.

@antimatter15

antimatter15/json3.js

Last active Aug 30, 2018
Embed
What would you like to do?
json2.js in the third dimension
// author: Kevin Kwok, based on Rose Curve by Eduard Bespalov
// license: The Software shall be used for Good, not Evil.
function main(params) {
var radius = 20,
vec = new CSG.Vector3D(0, 6, 0),
angle;
angle = 360 / 4;
var pent = CSG.Polygon.createFromPoints([
vec,
vec.rotateZ(1 * angle),
vec.rotateZ(2 * angle),
vec.rotateZ(3 * angle)
])
.rotateY(90)
.setColor([0.5,0.5,0.5]);
return pent.solidFromSlices({
numslices: 500,
loop: true,
callback: function(t, slice) {
var angle = t * Math.PI,
r = radius * Math.sin(angle),
x = r * Math.cos(angle),
y = r * Math.sin(angle),
vec = new CSG.Vector3D(x, y, 0);
var x1 = radius * (Math.cos(angle) * Math.cos(angle)
- Math.sin(angle) * Math.sin(angle)),
y1 = radius * (Math.cos(angle) * Math.sin(angle)
+ Math.cos(angle) * Math.sin(angle)),
turn = (new CSG.Vector2D(x1, y1)).angleDegrees();
return this
.rotateX(t * 180)
.rotateZ(turn)
.translate(vec);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.