0
0

More than 1 year has passed since last update.

vistaでphotoshop その9

Last updated at Posted at 2022-02-10

概要

vistaでphotoshopやってみる。
キャンバス作って、マンデルブロー書いて、pngで出力やってみる。

写真

test8.png

サンプルコード

var v = [];
var pixelSize = 1;
var width = 300;
var height = 300;
var maxIterations = 100;
var mandelMin = -2.5;
var mandelMax = 2.5;
var infinity = 2;
var brightness;

function draw() {
    for (var y = 0; y < height; y++) 
    {
        for (var x = 0; x < width; x++) 
        {
            var map = function(num, in_min, in_max, out_min, out_max) {
                return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
            };
            var a = map(y, 0, height, mandelMin, mandelMax);
            var b = map(x, 0, width, mandelMin, mandelMax);
            var initialA = a;
            var initialB = b;
            var iterationCount = 0;
            while (iterationCount < maxIterations)
            {
                var aa = (a * a) - (b * b);
                var bb = (2 * a * b);
                a = aa + initialA;
                b = bb + initialB;
                var result = Math.abs(a + b);
                if (result >= infinity)
                {
                    brightness = 255;
                    break;
                }
                else
                {
                    brightness = 0;
                }
                iterationCount++;
            }
            if (brightness == 0) v.push([x, y]);
        }
    }
}
draw();
preferences.rulerUnits = Units.PIXELS;
var docObj = app.documents.add(300, 300);
var myColor = new SolidColor();
myColor.rgb.red = myColor.rgb.green = myColor.rgb.blue = 0;
myColor.rgb.red = 255;
for (var i = 0; i < v.length; i++) 
{
    var x = v[i][0];
    var y = v[i][1];
    var selReg = [[x, y], [x + 1, y], [x + 1, y + 1], [x, y + 1], [x, y]];
    activeDocument.selection.select(selReg);
    activeDocument.selection.fill(myColor, ColorBlendMode.NORMAL, 100, false);
}
var pngOpt = new ExportOptionsSaveForWeb();
pngOpt.format = SaveDocumentType.PNG;
pngOpt.optimized = true;
pngOpt.interlaced = false;
pngOpt.PNG8 = false;
var filePath = new File("/Users/ore/test8.png");
app.activeDocument.exportDocument(filePath, ExportType.SAVEFORWEB, pngOpt);
alert("ok");



以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0