Last active
January 24, 2019 16:04
-
-
Save brycec/a6cec38ba4b1fbaa8a1123b4fe574c70 to your computer and use it in GitHub Desktop.
Flower planet in processing 3d
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
| void setup() { | |
| w=screen.width; | |
| h=screen.height-60; | |
| size(w,h); | |
| background(0); | |
| loadPixels(); | |
| colorMode(HSB); | |
| } | |
| void draw() { | |
| f=frameCount/400*TWO_PI; | |
| loadPixels(); for(p=0;p<pixels.length;p=p+1) | |
| {if(random()>0.3){continue;} | |
| i=p; | |
| x=(i%w)-(w/2); | |
| y=int(i/w)-(h/2); | |
| if(x<0&&y>0){pixels[i]=pixels[i-x-x];} | |
| else if(x<0&&y<0){pixels[i]=pixels[i-2*y*w-x-x];} | |
| else if(x>0&&y<0) | |
| {pixels[i]=pixels[i-2*y*w];} | |
| else{ | |
| d=1+cos(f)*100+sqrt(x*x+y*y)+sin(sin(f)*atan(y/x)*5)*30; | |
| d2=2+sin(f)*80+sqrt(x*x+y*y)+cos(cos(f)*atan(y/x)*3)*60; | |
| pixels[i]= | |
| lerpColor(pixels[i],color( | |
| d%230,d2+40,400-d2),0.3); | |
| } | |
| } | |
| updatePixels(); | |
| } |
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
| float gh = 35.5; | |
| float[][] grass = new float[360][3]; | |
| color[] colrs = {#ff1111,#ff7700,#ffff00,#00ff00,#0033ff,#7700ff}; | |
| void setup() { | |
| //size(screen.width, screen.height, P3D); | |
| size(screen.height, screen.width, P3D); | |
| noStroke(0); | |
| for(i=0;i<grass.length;i=i+1){ | |
| grass[i][0]= | |
| random(PI*.75,PI*1.25); | |
| grass[i][1]=random(0,TWO_PI); | |
| grass[i][2]=random(0,gh); | |
| } | |
| } | |
| void draw() { | |
| ambientLight(100, 120, 220); | |
| directionalLight(30, 60, 225, -1, -1, 1); | |
| lightFalloff(1, 0, 0); | |
| lightSpecular(255, 255, 255); | |
| background(120,170,255); | |
| f = frameCount/1.5; | |
| float cameraY = height; | |
| float fov = PI/3.0; | |
| float cameraZ = (height/2.0) / tan(fov/2.0); | |
| perspective(fov-(max(f-601,0))*.0066, float(width)/float(height), | |
| cameraZ/10.0, cameraZ*10.0); | |
| //sun | |
| pointLight(255,255,90,100,20,90); | |
| pushMatrix(); | |
| translate(80, 30, -100); | |
| fill(255,255,0); | |
| emissive(235,235,0); | |
| specular(80); | |
| sphereDetail(8); | |
| sphere(50); | |
| rotateY(0.4); | |
| rotateX(-0.4); | |
| translate(0,0,20); | |
| rotateZ(sin(f*.02)); | |
| box(96,96,1); | |
| rotateZ(PI/4); | |
| box(96,96,1); | |
| popMatrix(); | |
| //sky | |
| specular(30); | |
| emissive(0,0,255); | |
| fill(200,235,255); | |
| sphere(1000); | |
| //rainbow | |
| for(i=0;i<colrs.length;i=i+1){ | |
| emissive(colrs[i]); | |
| pushMatrix(); | |
| translate(420+i*10, 120, 20+i); | |
| rotateZ(PI/5); | |
| fill(colrs[i]); | |
| box(9,800,1); | |
| popMatrix(); | |
| } | |
| //planet | |
| translate(width/2, height/2+120, cameraZ/2+35); | |
| rotateZ(PI/2); | |
| phase=min((f*0.004)%TWO_PI,1.04); | |
| rotateY(phase); | |
| if(f>=600){ rotateY((f-600)*0.004);} | |
| fill(60,200,50); | |
| emissive(10); | |
| sphere(119); | |
| // door | |
| pushMatrix(); | |
| rotateY(.4); | |
| fill(100,65,35); | |
| translate(0,0,-200); | |
| box(10,80,10); | |
| translate(0,-40,50); | |
| box(10,10,100); | |
| translate(0,80,0); | |
| box(10,10,100); | |
| if(f>=290){ emissive(0); | |
| pushMatrix(); translate(100,-40,60); fill(0); box(1,150,340); popMatrix(); rotateZ(min(-1.15+(f*0.004),PI/2)); } | |
| fill(90,40,15); | |
| translate(5,-40,0); | |
| emissive(25,30,15); | |
| box(5,70,90); | |
| fill(255,240,0); | |
| translate(-5,-25,0); | |
| sphere(4); | |
| popMatrix(); | |
| for (i=0;i<grass.length;i=i+1) { | |
| x=grass[i][0]; | |
| y=grass[i][1]; | |
| z=grass[i][2]; | |
| zz=max(0,z-gh-2)/3; | |
| grass[i][2]=0.01+z+.03*sin(f*.005); | |
| if(grass[i][2]>=gh+5){ | |
| grass[i][2]=0; | |
| } else | |
| if(grass[i][2]<0){ | |
| grass[i][2]=gh+5; | |
| } | |
| if(z>gh){z=gh;} | |
| ph=TWO_PI-phase; | |
| if(y+.75<ph && ph<y+3.2 || | |
| y+.75<ph+TWO_PI && ph+TWO_PI<y+3.2){ | |
| pushMatrix(); | |
| rotateY(y); | |
| rotateX(x); | |
| // clouds | |
| sphereDetail(7); | |
| if (z<=4) { | |
| pushMatrix(); | |
| translate(0,0,-300); | |
| rotateX(0.33); shearX(.299); | |
| rotateY(PI*(x/3)); | |
| shearY(z/3.9); | |
| fill(255,255,255, | |
| (1-pow((z/2)-1,2))*255); | |
| sphere((z*6)+25); | |
| popMatrix(); | |
| } | |
| //grass | |
| shearY(-PI/8); | |
| shearX(-PI/8); | |
| translate(0, 0, zz*12-108); | |
| rotateX(sin(f*.05+x)*0.2); | |
| rotateY(-zz*zz*1.4+sin(f*.04+z)*0.2); | |
| rotateZ(-y-z-cos(f*.03+y)*0.66); | |
| emissive(25-(zz*25)); | |
| alph=255-(zz*295); | |
| fill(20,220-zz*200,10,alph); | |
| box(1,1,22+z); | |
| pushMatrix(); | |
| rotateY(-0.15); | |
| rotateX(-0.15); | |
| box(1,1,8+z); | |
| rotateY(0.3); | |
| rotateX(0.3); | |
| box(1,1,14+z); | |
| popMatrix(); | |
| //flowers | |
| if (z>gh-5.5) { | |
| //emissive(32); | |
| translate(0,0,5-z); | |
| fill(lerpColor(colrs[int(x*10)%6],0,zz*1.25),alph); | |
| rotateY(-.4); | |
| l=(5.5-(gh-z)); | |
| sphere(min(l,2)); | |
| if(l>2){ | |
| l=(l-2)*3; | |
| translate(zz*5,0,0); | |
| box(l-l*zz*1.2,l,1.25-zz*1.5); | |
| rotateZ(PI/4); | |
| rotateX(zz*1.2); | |
| translate(0,0,zz*5); | |
| box(l-l*zz*1.2,l,1.25-zz*1.5);} | |
| } | |
| emissive(0); | |
| popMatrix();} | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment