Darmn… you make me want to do some generative planet ;D (psss quite some time that I will not pass on my projects :P)
It is far from uptimized and the code is a lot messy 
Class for the “rendering”
package net.bonbonchan.planet;
import java.awt.image.BufferedImage;
/**
*
* @author Bonbon-Chan
*/
public class Planet
{
private BufferedImage img;
private int width;
private int height;
private double halfX;
private double halfY;
private double lx;
private double ly;
private double lz;
private double light;
public Planet(BufferedImage img,double lx,double ly,double lz,double light)
{
this.img = img;
width = img.getWidth();
halfX = width/2.0f;
height = img.getWidth();
halfY = height/2.0f;
double norm = Math.sqrt(lx*lx+ly*ly+lz*lz);
this.lx = lx/norm;
this.ly = ly/norm;
this.lz = lz/norm;
this.light = light;
}
public BufferedImage gen(Gradiant g,Height h,double size)
{
for(int x=0;x<width;x++)
{
for(int y=0;y<width;y++)
{
double xx = (x-halfX)/size;
double yy = (y-halfY)/size;
double d = xx*xx+yy*yy;
if(d<=1.0)
{
double zz = Math.sqrt(1-d);
double val = h.get(xx, yy, zz);
int v = (int)(val*255)&0xFF;
int c = g.colors[v];
double l = xx*lx+yy*ly+zz*lz;
if(l<light) { l = light; }
int red = (int)(((c>>16)&0xFF)*l);
int green = (int)(((c>>8)&0xFF)*l);
int blue = (int)(((c)&0xFF)*l);
int alpha = c&0xFF000000;
img.setRGB(x,y, alpha+(red<<16)+(green<<8)+(blue));
}
else
{
img.setRGB(x, y, 0x00000000);
}
}
}
return img;
}
}
Class Gradiant
package net.bonbonchan.planet;
/**
*
* @author Bonbon-Chan
*/
public class Gradiant
{
public int colors[];
public int index;
public int oldColor;
public Gradiant()
{
colors = new int[256];
}
public void start(int c)
{
oldColor = c;
index = 0;
}
public void add(int i,int c)
{
for(int j=index;j<=i;j++)
{
colors[j] = interpol(oldColor,c, ((j-index)*255)/(i-index) );
}
index = i;
oldColor = c;
}
public int interpol(int c1,int c2,int a)
{
int r1 = c1&0x00FF;
int r2 = c2&0x00FF;
int g1 = (c1>>8)&0x00FF;
int g2 = (c2>>8)&0x00FF;
int b1 = (c1>>16)&0x00FF;
int b2 = (c2>>16)&0x00FF;
int a1 = (c1>>24)&0x00FF;
int a2 = (c2>>24)&0x00FF;
r1 = ((r1*(255-a))/255+(r2*a)/255)&0xFF;
g1 = ((g1*(255-a))/255+(g2*a)/255)&0xFF;
b1 = ((b1*(255-a))/255+(b2*a)/255)&0xFF;
a1 = ((a1*(255-a))/255+(a2*a)/255)&0xFF;
return (a1<<24)+(b1<<16)+(g1<<8)+r1;
}
}
Interface for rendering data
package net.bonbonchan.planet;
/**
*
* @author Bonbon-Chan
*/
public interface Height
{
double get(double x,double y,double z);
}
Dotted planet
package net.bonbonchan.planet;
import java.util.Random;
/**
*
* @author Bonbon-Chan
*/
public class Dotted implements Height
{
private double x[];
private double y[];
private double z[];
private double w[];
private int nb;
private Random random;
public Dotted(long seed)
{
random = new Random(seed);
nb = random.nextInt(100)+50;
x = new double[nb];
y = new double[nb];
z = new double[nb];
w = new double[nb];
for(int i=0;i<nb;i++)
{
x[i] = random.nextDouble()*2-1;
y[i] = random.nextDouble()*2-1;
z[i] = random.nextDouble()+0.2;
double dist = Math.sqrt(x[i]*x[i]+y[i]*y[i]+z[i]*z[i]);
x[i] /= dist;
y[i] /= dist;
z[i] /= dist;
w[i] = random.nextDouble()*0.3+0.1;
}
}
@Override
public double get(double px, double py, double pz)
{
double v = 0;
for(int i=0;i<nb;i++)
{
double dx = px-x[i];
double dy = py-y[i];
double dz = pz-z[i];
double dist = (w[i]-Math.sqrt(dx*dx+dy*dy*2+dz*dz))/w[i];
if(dist>v) { v = dist; }
}
return v;
}
}
Stripped planet
package net.bonbonchan.planet;
import java.util.Random;
/**
*
* @author Bonbon-Chan
*/
public class Stripped implements Height
{
private double x[];
private double y[];
private double z[];
private double w[];
private int nb;
private Random random;
private Perlin1D perlin;
public Stripped(long seed)
{
random = new Random(seed);
perlin = new Perlin1D(random.nextLong(),6,0.8);
nb = random.nextInt(10);
x = new double[nb];
y = new double[nb];
z = new double[nb];
w = new double[nb];
for(int i=0;i<nb;i++)
{
x[i] = random.nextDouble()*2-1;
y[i] = random.nextDouble()*1.5-0.75;
z[i] = random.nextDouble();
w[i] = random.nextDouble()*0.3+0.1;
}
}
@Override
public double get(double px, double py, double pz)
{
double v2 = Math.sin(perlin.getRaw(py*0.5+0.5)*5);
double v = 0;
for(int i=0;i<nb;i++)
{
double dx = px-x[i];
double dy = py-y[i];
double dz = pz-z[i];
double dist = (w[i]-Math.sqrt(dx*dx+dy*dy*2+dz*dz))/w[i];
if(dist>v) { v = dist; }
}
return v2 + v;
}
}
Earth planet
package net.bonbonchan.planet;
/**
*
* @author Bonbon-Chan
*/
public class Earth implements Height
{
Perlin3D p;
public Earth()
{
p = new Perlin3D(System.currentTimeMillis(),7,0.6);
}
@Override
public double get(double x, double y, double z)
{
double v = Math.sin(p.getRaw(x*0.5+0.5, y*0.5+0.5, z*0.5+0.5)*20)*0.48+0.5;
if(v>1) { v = 1; }
return v;
}
}
Clouds
package net.bonbonchan.planet;
import java.util.Random;
/**
*
* @author Bonbon-Chan
*/
public class Cloud implements Height
{
private static final double COEF = 0.5/Math.exp(1)*Math.PI;
Perlin3D p;
private double x[];
private double y[];
private double z[];
private double w[];
private Random random;
private int nb;
public Cloud(long seed)
{
random = new Random(seed);
nb = random.nextInt(5)+5;
p = new Perlin3D(System.currentTimeMillis(),6,0.9);
x = new double[nb];
y = new double[nb];
z = new double[nb];
w = new double[nb];
for(int i=0;i<nb;i++)
{
x[i] = Math.random()*2-1;
y[i] = Math.random()*2-1;
z[i] = Math.random()+0.2;
double dist = Math.sqrt(x[i]*x[i]+y[i]*y[i]+z[i]*z[i]);
x[i] /= dist;
y[i] /= dist;
z[i] /= dist;
w[i] = Math.random()*0.2+0.1;
}
}
@Override
public double get(double px, double py, double pz)
{
double v = p.getRaw(px*0.5+0.5, py*0.5+0.5, pz*0.5+0.5);
double v2 = 0;
for(int i=0;i<nb;i++)
{
double dx = px-x[i];
double dy = py-y[i];
double dz = pz-z[i];
double dist = (w[i]-Math.sqrt(dx*dx+dy*dy*3+dz*dz))/w[i];
v2 += Math.sin(Math.exp(dist));
}
if(v2>1) { v2 = 1; }
v2 = v2*v;
if(v2>1) { v2 = 1; }
return v2;
}
}
My perlin classes
package net.bonbonchan.planet;
import java.util.Random;
public class Perlin1D
{
protected int rnd_size;
protected double rnd[];
protected double persistance = 0.7f;
protected int octave = 5;
private double totalPersistance;
public Perlin1D(long seed,int octave,double persistance)
{
rnd_size = 1<<octave;
rnd = new double[rnd_size];
Random random = new Random();
random.setSeed(seed);
this.persistance = persistance;
this.octave = octave;
for(int x=0;x<rnd_size;x++)
{
rnd[x] = random.nextDouble();
}
totalPersistance = 0;
double c = 1;
for(int i=0;i<octave;i++)
{
totalPersistance += c;
c = c*persistance;
}
}
public double getRandom(double x)
{
int ix = (int)(Math.floor(x));
double dx = x-ix;
double v1 = rnd[ix];
double v2 = rnd[ix+1];
return interpole(v1,v2,dx);
}
public double getRaw(double x)
{
double value = 0;
double c = 1;
for(int i=0;i<octave;i++)
{
int size = 1<<i;
double v = getRandom(x*size);
value = value + v*c;
c = c*persistance;
}
return value/totalPersistance;
}
public double interpole(double a,double b,double x)
{
float y = (float)Math.sin((x-0.5)*Math.PI)*0.5f+0.5f;
return a*(1-y) + b*y;
}
}
package net.bonbonchan.planet;
import java.util.Random;
public class Perlin3D
{
protected int rnd_size;
protected double rnd[][][];
protected double persistance = 0.7f;
protected int octave = 5;
private double totalPersistance;
public Perlin3D(long seed,int octave,double persistance)
{
rnd_size = 1<<octave;
rnd = new double[rnd_size][rnd_size][rnd_size];
Random random = new Random();
random.setSeed(seed);
this.persistance = persistance;
this.octave = octave;
for(int x=0;x<rnd_size;x++)
{
for(int y=0;y<rnd_size;y++)
{
for(int z=0;z<rnd_size;z++)
{
rnd[x][y][z] = random.nextDouble();
}
}
}
totalPersistance = 0;
double c = 1;
for(int i=0;i<octave;i++)
{
totalPersistance += c;
c = c*persistance;
}
}
public double getRandom(double x,double y,double z)
{
int ix = (int)(Math.floor(x));
double dx = x-ix;
int iy = (int)(Math.floor(y));
double dy = y-iy;
int iz = (int)(Math.floor(z));
double dz = z-iz;
double v1 = rnd[ix][iy][iz];
double v2 = rnd[ix+1][iy][iz];
double v3 = rnd[ix][iy+1][iz];
double v4 = rnd[ix+1][iy+1][iz];
double v12 = interpole(v1,v2,dx);
double v34 = interpole(v3,v4,dx);
double vv = interpole(v12,v34,dy);
double w1 = rnd[ix][iy][iz+1];
double w2 = rnd[ix+1][iy][iz+1];
double w3 = rnd[ix][iy+1][iz+1];
double w4 = rnd[ix+1][iy+1][iz+1];
double w12 = interpole(w1,w2,dx);
double w34 = interpole(w3,w4,dx);
double ww = interpole(w12,w34,dy);
return interpole(vv,ww,dz);
}
public double getRaw(double x,double y,double z)
{
double value = 0;
double c = 1;
for(int i=0;i<octave;i++)
{
int size = 1<<i;
double v = getRandom(x*size,y*size,z*size);
value = value + v*c;
c = c*persistance;
}
return value/totalPersistance;
}
public double interpole(double a,double b,double x)
{
float y = (float)Math.sin((x-0.5)*Math.PI)*0.5f+0.5f;
return a*(1-y) + b*y;
}
}
And finally how I use all this
Gradiant g = new Gradiant();
Height h = null;
float hsv[] = new float[3];
int type = (int)(Math.random()*3);
hsv[0] = (float)Math.random()*206f/360f;
hsv[1] = (float)(Math.random()*0.2+0.8);
hsv[2] = (float)(Math.random()*0.1+0.9);
switch(type)
{
case 0:
h = new Stripped(System.currentTimeMillis());
g.start( Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) );
g.add( 128, Color.HSBtoRGB(hsv[0],
hsv[1]*(float)(Math.random()*0.25+0.75),
hsv[2]*(float)(Math.random()*0.75+0.25)) );
g.add(255, Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) );
lbImage.setIcon(
new ImageIcon(planet.gen(g, h, 90))
);
break;
case 1:
h = new Earth();
g.start( Color.HSBtoRGB(0.608f, 0.52f, 0.77f) );
fillRandom(g,5,100,0.608f,0.52f,0.77f);
fillRandom(g,105,115,0.15f,0.64f,1.00f);
fillRandom(g,120,180,0.28f,0.47f,0.99f);
fillRandom(g,185,215,0.28f,0.69f,0.68f);
fillRandom(g,220,245,0.055f,0.62f,0.61f);
g.add( 250, 0xFFFFFFFF );
g.add( 255, 0xFFFFFFFF );
BufferedImage img1 = planet.gen(g,h,85);
h = new Cloud(System.currentTimeMillis());
g.start( 0x00000000 );
g.add( 10, 0x00d4d4d4 );
g.add( 64, 0xFFd4d4d4 );
g.add( 125, 0xFFFFFFFF );
g.add( 255, 0xFFFFFFFF );
BufferedImage img2 = cloud.gen(g,h,90);
Graphics g2d = img1.getGraphics();
g2d.drawImage(img2, 0, 0, null);
g2d.dispose();
lbImage.setIcon(
new ImageIcon(img1)
);
break;
default:
h = new Dotted(System.currentTimeMillis());
g.start( Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) );
g.add( 255, Color.HSBtoRGB(hsv[0], hsv[1]*0.75f, hsv[2]*0.6f) );
lbImage.setIcon(
new ImageIcon(planet.gen(g, h, 90))
);
}
private void fillRandom(Gradiant gradiant,int a,int b,float h,float v,float s)
{
for(int i=a;i<=b;i+=5)
{
gradiant.add(i, Color.HSBtoRGB(h,
s*(float)(Math.random()*0.1+0.9),
v*(float)(Math.random()*0.2+0.8)));
}
}
If it give you new idea to make your planets :D.