Created
March 18, 2016 13:55
-
-
Save JotaroS/9db2c24cffd684e09793 to your computer and use it in GitHub Desktop.
p5.js script
This file contains 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
var sphere_r = 200; | |
var phi=0,theta=0; | |
function setup() { | |
var canvas = createCanvas(windowWidth, windowHeight,WEBGL); | |
canvas.parent("p5Canvas"); | |
resizeCanvas(windowWidth, windowHeight); | |
basicMaterial(0,0,0); | |
setupSphereShell(); | |
} | |
function draw(){ | |
background(250); | |
push() //orbit rotation | |
rotateX(frameCount*0.001); | |
rotateY(frameCount*0.0011); | |
rotateZ(frameCount*0.0013); | |
drawSphereShell(); | |
drawSphereShellPlanes(); | |
pop(); | |
} | |
function windowResized() { | |
} | |
var vec_arr=new Array(); | |
function setupSphereShell(){ | |
for(var i=0; i<200; i++){ | |
theta = random(0,2*PI); | |
phi = randomGaussian(0,PI); | |
vec_arr.push(createVector( | |
sphere_r * cos(theta) * sin(phi), | |
sphere_r * sin(theta) * sin(phi), | |
sphere_r * cos(phi))); | |
} | |
} | |
function drawSphereShell(){ | |
for(var i=0; i<vec_arr.length;i++){ | |
push(); | |
translate(vec_arr[i].x,vec_arr[i].y,vec_arr[i].z); | |
sphere(2); | |
pop(); | |
} | |
} | |
function drawSphereShellPlanes(){ | |
for(var i=0; i<vec_arr.length;i++){ | |
var near_arr = new Array(); | |
for(var j=0; j< vec_arr.length; j++){ | |
var d = dist( | |
vec_arr[i].x,vec_arr[i].y,vec_arr[i].z, | |
vec_arr[j].x,vec_arr[j].y,vec_arr[j].z); | |
if(d<100 && d!= 0){ | |
near_arr.push(vec_arr[j]); | |
} | |
} | |
fill('rgba(0,255,0, 0.25)'); | |
if(near_arr.length>0){ | |
beginShape(); | |
vertex(vec_arr[i].x,vec_arr[i].y,vec_arr[i].z); | |
for(var j=0; j < near_arr.length;j++){ | |
vertex(near_arr[j].x,near_arr[j].y,near_arr[j].z); | |
} | |
endShape(CLOSE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment