forked from: Mountain
forked from Mountain (diff: 52)
Mountain class part1 作りかけ
ActionScript3 source code
/**
* Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vEQY
*/
// forked from shohei909's Mountain
// Mountain class part1
// 作りかけ
package {
import flash.display.*;
public class FlashTest extends Sprite {
public function FlashTest() {
var w:int = 465;
var h:int = 465;
var mount:Mountmap = new Mountmap(w,h);
mount.setMountain( new BitmapData(465,465,false,0x668866) );
addChild( mount );
}
}
}
import flash.display.*;
import mx.utils.ColorUtil;
import flash.geom.*;
class Mountmap extends Bitmap{
private var colormap:BitmapData;
private var map:BitmapData;
private var sun:Point3D;
private var camera:Point3D;
private var thickness:int=2;
public function Mountmap(w:int,h:int){
sun = new Point3D(w/2,0,100);
camera = new Point3D(w/2,h,100);
super( new BitmapData(465,465,false,0xFF000000) );
}
//山の模様を指定するbitmapData,山の高さ,フルクタル生成の最小値,フルクタル生成の回数,ランダムシードを指定
public function setMountain( colorData:BitmapData,tall:int=50,scale:int=128,numOctaves:int=8,seed:int=0):void{
colormap = colorData;
var w:int = bitmapData.width;
var h:int = bitmapData.height;
map = new BitmapData(w,h+1);
map.perlinNoise(scale,scale,numOctaves,seed,false,true,4);
bitmapData.lock();
for(var i:int=0;i<w;i++){
for(var j:int=0;j<h;j++){
var l:int = map.getPixel(i,j)*tall/0x100;
var deg:Number = Math.atan( (map.getPixel(i,j)-map.getPixel(i,j+10))/3 );
var color:uint = ColorUtil.adjustBrightness2( colormap.getPixel(i,j), Math.sin(deg)*50-50 );
bitmapData.fillRect(new Rectangle(i,j-l,1,l),color);
}
}
bitmapData.unlock();
}
}
class Point3D{
public var x:Number,y:Number,z:Number;
public function Point3D(x:Number,y:Number,z:Number):void{
this.x=x;this.y=y;this.y=y;
}
}