Skip to content

Instantly share code, notes, and snippets.

@mutterer
Last active January 19, 2021 08:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mutterer/dde0f152abef221ef726a283fa375d2b to your computer and use it in GitHub Desktop.
Save mutterer/dde0f152abef221ef726a283fa375d2b to your computer and use it in GitHub Desktop.
Googly eyes tool
// this example uses the Toolbar.setIcon(toolName,icon) method
// added in v1.53h, to dynamically update its icon.
macro "Left Eye Action Tool - N44 C000 o00nn" {
setTool("Googly Eyes Tool")
}
macro "Right Eye Action Tool - N44 C000 o00nn" {
setTool("Googly Eyes Tool")
}
macro "Googly Eyes Tool - C000T0f16G" {
x0=0; y0=0;
getCursorLoc(x, y, z, modifiers); while (modifiers&16>0) {
getCursorLoc(x, y, z, modifiers);
x=constrain(x,0,getWidth);
if (x!=x0 || y!=y0) {
call("ij.gui.Toolbar.setIcon", "Left Eye Action Tool", getIcon(x));
call("ij.gui.Toolbar.setIcon", "Right Eye Action Tool", getIcon(x));
x0=x; y0=y;
}
wait(50);
}
call("ij.gui.Toolbar.setIcon", "Left Eye Action Tool", "N44 C000 o00nn");
call("ij.gui.Toolbar.setIcon", "Right Eye Action Tool", "N44 C000 o00nn");
}
function getIcon(x) {
blue = map(x,0,getWidth(),0,6);
black = map(x,0,getWidth(),1,15);
icon ="N44 C000 o00nn B11 Cfff o00ll C48f o"+h(blue)+"6ff C000 o"+h(black)+"c55";
return icon;
}
function map(a,in_min,in_max,out_min,out_max) {
return (a - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
function h(a) {
return ""+toExtHex(constrain(a,0,23));
}
function toExtHex(n) {
if (n>15) return fromCharCode(0x66+n-15);
else return toHex(n);
}
function constrain(a,min,max) {
if (a<min) a=min;
if (a>max) a=max;
return a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment