Skip to content

Instantly share code, notes, and snippets.

@will-in-wi
Created January 13, 2013 19:52
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 will-in-wi/4525887 to your computer and use it in GitHub Desktop.
Save will-in-wi/4525887 to your computer and use it in GitHub Desktop.
Basic code to create a filled sphere with ScriptCraft
function sphere(material, radius) {
for (var i = 0; i <= radius; i++) {
up(radius + i).fwd(radius - Math.round(Math.sqrt(radius*radius - i*i))).right(radius - Math.round(Math.sqrt(radius*radius - i*i))).cylinder(material, Math.round(Math.sqrt(radius*radius - i*i)), 1);
up(radius - i).fwd(radius - Math.round(Math.sqrt(radius*radius - i*i))).right(radius - Math.round(Math.sqrt(radius*radius - i*i))).cylinder(material, Math.round(Math.sqrt(radius*radius - i*i)), 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment