Created
January 19, 2019 08:18
-
-
Save kuy/e2ab2e4d9cad74d98c78f01b6dd4ba7b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// scatter-random-dots.jsx | |
// https://github.com/kuy | |
// Copyright(c) 2019 Yuki KODAMA / @kuy | |
// This script is distributed under the MIT License. | |
function precondition() { | |
if (documents.length === 0) { | |
alert("Please create a new document before running script."); | |
return false; | |
} | |
if (selection.length !== 1 || selection[0].typename !== 'PathItem') { | |
alert("Please select just 1 rectangle path."); | |
return false; | |
} | |
return true; | |
} | |
function createDot(x, y) { | |
var radius = 2; | |
var dot = activeDocument.activeLayer.pathItems.ellipse(y + radius, x - radius, radius, radius); | |
var black = new RGBColor(); | |
black.red = black.green = black.blue = 0; | |
dot.fillColor = black; | |
dot.filled = true; | |
} | |
function createRandomDot(baseTop, baseLeft, rangeHeight, rangeWidth) { | |
var x = baseLeft + Math.floor(Math.random() * rangeWidth); | |
var y = baseTop - Math.floor(Math.random() * rangeHeight); | |
createDot(x, y); | |
} | |
function main() { | |
var n = 100; | |
var offset = 10; | |
var frame = selection[0]; | |
for (var i = 0; i < n; i++) { | |
createRandomDot(frame.top, frame.left, frame.height - offset, frame.width - offset); | |
} | |
} | |
if (precondition()) { | |
main(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment