Last active
August 30, 2018 20:36
-
-
Save antimatter15/3e0897deb6d27caeaefbc05cceafc859 to your computer and use it in GitHub Desktop.
json2.js in the third dimension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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