Skip to content

Instantly share code, notes, and snippets.

@craigmccauley
Created March 20, 2020 09:12
Show Gist options
  • Save craigmccauley/f060cf0ed9cf1cc49df5746f62bbfa8e to your computer and use it in GitHub Desktop.
Save craigmccauley/f060cf0ed9cf1cc49df5746f62bbfa8e to your computer and use it in GitHub Desktop.
//macro "Penguin Action Tool - C800C080C880C008C808C088CcccD1bD41D48D50D53D63D72D73D75D82D85D8fD93Da0Da3Db1Db8DebCcdcD0aD3dD55D56D6eD7fD9eDa5Da6DcdDfaCacfC420C620C820Ca20Cc20Ce20C040C240C440C640C840Ca40Cc40Ce40C060C260C460C660C860Ca60Cc60Ce60C080C280C480C680C880Ca80Cc80Ce80C0a0C2a0C4a0C6a0C8a0Caa0Cca0Cea0C0c0C2c0C4c0C6c0C8c0Cac0Ccc0Cec0C0e0C2e0C4e0C6e0C8e0Cae0Cce0Cee0C004C204C404C604C804Ca04Cc04Ce04C024C224D1aD38D39D3aD3bD45D46Db5Db6Dc8Dc9DcaDcbDeaC424C624C824Ca24Cc24Ce24C044C244D19D27D28D36D37D70D80Dc6Dc7Dd7Dd8De9C444D29D44D51D60D71D81D90Da1Db4Dd9C644C844Ca44Cc44Ce44C064C264C464C664D3cD42Db2DccC864Ca64Cc64Ce64C084C284C484C684C884Ca84Cc84Ce84C0a4C2a4C4a4C6a4C8a4Caa4Cca4Cea4D4fD5fD74D84D9fDafDbfC0c4C2c4C4c4C6c4C8c4Cac4Ccc4Cec4C0e4C2e4C4e4C6e4C8e4Cae4Cce4Cee4C008C208C408C608C808Ca08Cc08Ce08C028C228C428C628C828Ca28Cc28Ce28C048C248C448C648C848Ca48Cc48Ce48C068C268C468C668D43D4dD61D91Db3DbdC868Ca68Cc68Ce68C088C288C488C688C888D18D47D5eDaeDb7De8Ca88Cc88Ce88C0a8C2a8C4a8C6a8C8a8Caa8Cca8Cea8D3fD4eD6fDbeC0c8C2c8C4c8C6c8C8c8Cac8Ccc8Cec8DcfC0e8C2e8C4e8C6e8C8e8Cae8Cce8Cee8C00cC20cC40cC60cC80cCa0cCc0cCe0cC02cC22cC42cC62cC82cCa2cCc2cCe2cC04cC24cC44cC64cC84cCa4cCc4cCe4cC06cC26cC46cC66cC86cCa6cCc6cCe6cC08cC28cC48cC68cC88cCa8cCc8cCe8cC0acC2acC4acC6acC8acCaacD83CcacCeacC0ccC2ccC4ccC6ccC8ccCaccD4cDbcCfffD0bD17D2bD34D3eD49D4aD4bD52D54D57D5cD5dD64D65D66D6dD76D7eD86D8eD94D95D96D9dDa2Da4Da7DacDadDb9DbaDbbDc4DceDdbDe7DfbCaaaD26D2aD35Dc5Dd6DdaC888Cf00C0f0Cff0C00fCf0fC0ffCfffD00D01D02D03D04D05D06D07D08D09D0cD0dD0eD0fD10D11D12D13D14D15D16D1cD1dD1eD1fD20D21D22D23D24D25D2cD2dD2eD2fD30D31D32D33D40D58D59D5aD5bD62D67D68D69D6aD6bD6cD77D78D79D7aD7bD7cD7dD87D88D89D8aD8bD8cD8dD92D97D98D99D9aD9bD9cDa8Da9DaaDabDb0Dc0Dc1Dc2Dc3Dd0Dd1Dd2Dd3Dd4Dd5DdcDddDdeDdfDe0De1De2De3De4De5De6DecDedDeeDefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfcDfdDfeDff"{
getLine(x1, y1, x2, y2, lineWidth);
if (x1 == -1 || y1 == -1 || x2 == -1 || y2 == -1) {
showMessageWithCancel(
"No Line Detected",
"In order to rotate the image, a line needs to be drawn on it from the base to the mouth.\n" +
'Click "Cancel" to cancel this Macro to draw the line. If you do not wish to rotate the image, click OK'
);
}
var isVertical = x1 == x2;
var isHorizontal = y1 == y2;
var isLeftToRight = x1 < x2;
if (isVertical && isHorizontal) {
//line is a dot, do not rotate
angle = 0;
} else if (isVertical) {
//line is vertical, if user draws from top to bottom, flip image
var isTopToBottom = y1 < y2;
if (isTopToBottom) {
angle = 180;
} else {
angle = 0;
}
} else if (isHorizontal) {
//line is horizontal, if user draws from left to right rotate 90 otherwise -90
if (isLeftToRight) {
angle = -90;
} else {
angle = 90;
}
} else {
var rads = atan((y2 - y1) / (x2 - x1));
var degrees = (rads * 180) / PI;
if (isLeftToRight) {
angle = degrees * -1 - 90;
} else {
angle = degrees * -1 + 90;
}
}
getDimensions(w, h, channels, slices, frames);
Dialog.create("Specify Slices");
Dialog.addMessage("Specify the slices to use:");
Dialog.addNumber("Start Slice #: ", 1);
Dialog.addNumber("Stop Slice # (Max " + slices + "): ", slices);
Dialog.show();
var mystart = Dialog.getNumber();
var mystop = Dialog.getNumber();
while (mystart < 1 || mystart > mystop || mystop > slices) {
Dialog.create("Invalid slices specified");
if (mystart < 1) {
Dialog.addMessage("Start slice must be greater than 0.");
}
if (mystart > mystop) {
Dialog.addMessage("Start slice must be less than or equal to stop slice.");
}
if (mystop > slices) {
Dialog.addMessage(
"Stop slice must be equal to or less than the last slice number."
);
}
Dialog.addNumber("Start Slice #: ", mystart);
Dialog.addNumber("Stop Slice # (Max " + slices + "): ", mystop);
Dialog.show();
mystart = Dialog.getNumber();
mystop = Dialog.getNumber();
}
setSlice(1);
run("Copy");
run(
"Z Project...",
"start=" + mystart + " stop=" + mystop + " projection=[Max Intensity]"
);
run("Add Slice");
run("Paste");
run(
"Rotate... ",
"angle=" + angle + " grid=2 interpolation=Bilinear enlarge stack"
);
run("Save");
close();
run("Open Next");
setTool("line");
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment