Skip to content

Instantly share code, notes, and snippets.

@dscho
Created June 24, 2017 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscho/953e012a7fab390c00ce216ab19e8423 to your computer and use it in GitHub Desktop.
Save dscho/953e012a7fab390c00ce216ab19e8423 to your computer and use it in GitHub Desktop.
dim = 256; /* width / height */
frames = 20;
red = 101;
green = 164;
blue = 227;
zoomIntoX = 4;
zoomIntoY = 4;
newImage("Fiji Fractal", "RGB", dim, dim, frames);
id = getImageID();
setBatchMode(true);
bigdim = 9;
while (bigdim < 8 * dim)
bigdim *= 8;
offset = bigdim / 9;
newImage("Fiji Fractal (the big picture)", "RGB", bigdim, bigdim, 1);
big = getImageID();
setPixel(offset, offset, (red << 16) | (green << 8) | blue);
function pasteAtScale(x, y, scale)
{
makeRectangle(offset + x * scale, offset + y * scale, scale, scale);
run("Paste");
}
function fijiAtScale(scale)
{
makeRectangle(offset, offset, scale, scale);
run("Copy");
for (i = 1; i < 7; i++) {
// upper bar of the F
pasteAtScale(i, 0, scale);
// left bar of the F
pasteAtScale(0, i, scale);
}
for (i = 0; i < 3; i++) {
// left i
pasteAtScale(2, 2 + i, scale);
// vertical part of j
pasteAtScale(4, 2 + i, scale);
// horizontal part of j
pasteAtScale(2 + i, 6, scale);
// right i
pasteAtScale(6, 2 + i, scale);
}
// remaining gap in j
pasteAtScale(4, 5, scale);
run("Select None");
}
for (scale = 1; 9 * scale <= bigdim; scale *= 8)
fijiAtScale(scale);
for (frame = 1; frame <= frames; frame++) {
factor = pow(8, frame / frames);
dim2 = bigdim / factor;
off2x = offset + (offset * 8 - dim2) * zoomIntoX / 7;
off2y = offset + (offset * 8 - dim2) * zoomIntoY / 7;
selectImage(big);
makeRectangle(off2x, off2y, dim2, dim2);
run("Duplicate...", "title=dup");
run("Size...", "width=" + dim + " height=" + dim + " constrain average interpolation=Bicubic");
/*
* Note: the fractal has holes in it, and we want the *downsampled* image to be Fiji blue.
* Hence we adjust the contrast a little.
*/
setMinAndMax(225 - 42 * frame / frames, 251 - 7 * frame / frames);
makeRectangle(0, 0, dim, dim);
run("Copy");
run("Close");
selectImage(id);
setSlice(frame);
makeRectangle(0, 0, dim, dim);
run("Paste");
run("Select None");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment