Created
January 18, 2012 08:25
-
-
Save cellfusion/1631965 to your computer and use it in GitHub Desktop.
極座標変換用の displacementMap 画像作成
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 map:BitmapData = new BitmapData(w, h, false, 0xFF808080); | |
map.lock(); | |
var center:Point = new Point(w / 2, h / 2); | |
var rmax:Number = Math.sqrt(Math.pow(center.x, 2) + Math.pow(center.y, 2)); | |
for (var x:int = 0; x < w; x++) { | |
for (var y:int = 0; y < h; y++) { | |
var xpos:Number = center.x - x; | |
var ypos:Number = center.y - (h-y); | |
var radius:Number = Math.sqrt(xpos * xpos + ypos * ypos); | |
var theta:Number = 0; | |
if (xpos != 0) { | |
theta = Math.atan(ypos / xpos); | |
if (xpos < 0) theta = theta + Math.PI; | |
} else if (ypos != 0) { | |
theta = 2 * Math.atan(1) - Math.atan(xpos / ypos); | |
} | |
var r:Number = 0x7f * (theta / (Math.PI * 2)) + 0x80; | |
var g:Number = 0x80; | |
// TODO 色の変換が間違ってるっぽい | |
var b:Number = 0xFF * (radius / rmax); | |
var color:Number = r << 16 | g << 8 | b; | |
map.setPixel(x, y, color); | |
} | |
} | |
map.unlock(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment