Hiya,
I’m working on generating some planets and moons for a 2d project im working on, these will generate planets procedurally that look somewhat realistic.
Anybody got any tips on improving this or optimising this?, it looks very flat i feel. any suggestions?
Here is what I have so far
Entire code below
/*
Render an Astral body, currently this code will only render and earthlike body
Passed in:Eventually will be passed in will be Size , Mass, color1, color2, color3, type
*/
package
{
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.BlendMode;
import flash.display.GradientType;
import flash.display.Sprite;
import flash.geom.*;
import flash.geom.Matrix;
import flash.display.GradientType;
public class DrawStar extends MovieClip
{
private var rect:Rectangle;
private var pt:Point;
public var circularMask:Sprite;
public var body:Sprite;
public var skyBody:Sprite;
private const earthColorArray:Array = new Array(0x000044,0x3255FF,0xFFFF99,0x33CF33,0x116611,0x666600,0xD4D0C8,0xFFFFFF); //land colours
private const skyColorArray:Array = new Array(0xFFFFFF,0xFFFFFF,0xFFFFFF,0xFFFFFF,0xEEEEEE,0xFFFFFF); // cloud/sky cover
private var paletteMapArray:Array;
private var paletteSkyArray:Array;
private var seed:uint;
public function DrawStar():void
{
var terrain:BitmapData = new BitmapData(250,250,false,0xCCCCCC); // my land texture
var terrainColorMap:BitmapData = new BitmapData(250,5,false,0xCCCCCC); // the place i will keep my land colour grandient
var sky:BitmapData = new BitmapData(250,250,true,0xCCCCCC); // my sky texture
var skyColorMap:BitmapData = new BitmapData(250,5,true,0xCCCCCC); // sky colour gradient
var matrix:Matrix = new Matrix();
var matrixColorSwap:Matrix = new Matrix();
matrix.createGradientBox(250, 250);
matrixColorSwap.createGradientBox(250,5);
var matrix1:Matrix = new Matrix();
var matrixColorSwap1:Matrix = new Matrix();
matrix1.createGradientBox(250, 250);
matrixColorSwap1.createGradientBox(250,5);
circularMask = new Sprite();
body = new Sprite();
skyBody = new Sprite();
rect = new Rectangle(0,0,terrain.width,terrain.height);
paletteMapArray = [];
paletteSkyArray = [];
body.graphics.beginGradientFill(GradientType.LINEAR,earthColorArray,[1,1,1,1,1,1,1,1],[0,139,142,143,180,210,225,240],matrixColorSwap);
body.graphics.drawRect(0 ,0 ,250 ,5);
body.graphics.endFill();
terrainColorMap.draw(body);
skyBody.graphics.beginGradientFill(GradientType.LINEAR,skyColorArray,[1,0.8,0.03,0.01,0.8,1],[0,45,60,130,150,240],matrixColorSwap1);
skyBody.graphics.drawRect(0 ,0 ,250 ,5);
skyBody.graphics.endFill();
skyColorMap.draw(skyBody);
for (var n:int = 0; n < 250; n++)
{
paletteMapArray.push(terrainColorMap.getPixel32( n,0));
paletteSkyArray.push(skyColorMap.getPixel32( n,0));
}
pt = new Point(0,0);
var bmp:Bitmap = new Bitmap(terrain);
addChild(bmp);
seed = Math.random() * 1000;
terrain.perlinNoise(75, 75, 1+(seed/100), seed, true, true, 2, true); //generate perlin map
terrain.paletteMap(terrain, terrain.rect, new Point(), paletteMapArray, [], []); //shift the colours to whats in paletteMapArray
seed = Math.random() * 1000;
sky.perlinNoise(75, 75, 4 + (seed/100), seed, true, true, 2, true);
sky.paletteMap(sky, sky.rect, new Point(), paletteSkyArray, [], []);
circularMask.graphics.beginGradientFill(GradientType.RADIAL, [0,0], [0,1], [249,250], matrix);
circularMask.graphics.drawRect(0,0,250,250);
circularMask.graphics.endFill();
terrain.copyPixels(sky, rect, pt, null, null, true); // copy the sky unto the land
terrain.draw(circularMask);
body.graphics.lineStyle( 1,0x000088); // create an outer halo around the planet
body.graphics.drawCircle( 125, 125, 120);
body.graphics.lineStyle( 2,0x558888FF);
body.graphics.drawCircle( 125, 125, 121);
body.graphics.lineStyle( 2,0x55CCCCFF);
body.graphics.drawCircle( 125, 125, 123);
body.graphics.lineStyle( 1,0xEEEEEEFF);
body.graphics.drawCircle( 125, 125, 124);
body.graphics.endFill();
terrain.draw(body);
}
}
}