Last active
January 17, 2021 17:07
-
-
Save mutterer/84dfd841f4f1c0e047030c42644d342f to your computer and use it in GitHub Desktop.
A demo of how tool icons can be animated.
This file contains 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
// this example uses the Toolbar.setIcon(toolName,icon) method | |
// This example action tool uses the Toolbar.setIcon() method, | |
// added in v1.53h, to dynamically update its icon. | |
// uses extended hex icon coordinates | |
var icons = newArray( "Ca30N44V00nn","C037N44F00nn"); | |
var colors = newArray( "Cf00","C0f0","C00f","Cf0f"); | |
var xs = newArray(4); | |
var ys = newArray(4); | |
var xbs = newArray(4); | |
var ybs = newArray(4); | |
var state = 0; | |
macro "Toggle Icon Action Tool - C037N44F00nn" { | |
if (state<2) { | |
call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", icons[state]); | |
state++; | |
} else { | |
bouncingLine(); | |
state = 0; | |
call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", icons[state]); | |
} | |
} | |
function bouncingLine () { | |
x=5; y=5; vx =1; vy = -2; | |
bx=7; by=2; vbx =2; vby =1.3; | |
startTime=getTime(); | |
while (getTime()-startTime<10000) { | |
x=x+vx; | |
y=y+vy; | |
if ((x<1)||(x>=23)) vx = -vx; | |
if ((y<1)||(y>=23)) vy = -vy; | |
bx=bx+vbx; | |
by=by+vby; | |
if ((bx<1)||(bx>=23)) vbx = -vbx; | |
if ((by<1)||(by>=23)) vby = -vby; | |
call("ij.gui.Toolbar.setIcon", "Toggle Icon Action Tool", getIcon(x,y,bx,by)); | |
wait(50); | |
} | |
} | |
function getIcon(i,j,k,l) { | |
xs = Array.slice(xs,1,4); | |
xs = Array.concat(xs,i); | |
xbs = Array.slice(xbs,1,4); | |
xbs = Array.concat(xbs,k); | |
ys = Array.slice(ys,1,4); | |
ys = Array.concat(ys,j); | |
ybs = Array.slice(ybs,1,4); | |
ybs = Array.concat(ybs,l); | |
icon = "N44"; | |
for (z=0;z<xs.length;z++) { | |
icon = icon+colors[z]+"L"+h(xs[z])+h(ys[z])+h(xbs[z])+h(ybs[z]); | |
} | |
return icon; | |
} | |
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