Scripts/Viewmat Spy

From J Wiki
Jump to navigation Jump to search

Viewmat Spy shows the mouse position, and current RGB color with its components.

The snippet is run once anywhere any time to dynamically patch viewmat.

require 'viewmat'

jvm_g_mmove_jviewmat_=: 3 : 0
  'X Y W H'=. 4{.0 ".sysdata
  Y=. <:H-Y
  p=. |.&.((3#256)&#:){.glqpixels X,Y,1 1
  wd 'pn *',TITLE,' ',":X,Y,p,(3#256)#:p
)

For example, from Plot:

steps=: {. + (1&{ - {.) * (i.@>: % ])@{:
gamma=: ! @ <:
real=: {. @ +.
x=. steps _3.5 4.5 60
y=. steps _1 1 60
z=. real gamma x j./ y
viewmat 'Gamma';~_3 >. 12 <. z

Spy.png


Contributed by Oleg Kobchenko


Thank you for the code, but with simple data I can see the mouse xy position isn't reported correctly -- move over the mouse pointer around the white box with the following example:

viewmat  1 (<4 4)} 10 10 $0

The xy position is vertically flipped. The flipping line(Y=. <:H-Y) should be ignored. The code should be:

jvm_g_mmove_jviewmat_=: 3 : 0
  'X Y W H'=. 4{.0 ".sysdata
  NB. Y=. <:H-Y
  p=. |.&.((3#256)&#:){.glqpixels X,Y,1 1
  wd 'pn *',TITLE,' ',":X,Y,p,(3#256)#:p
)

--JuneKim


If you want to get the current location(row,col) and raw value on the data matrix:

require 'viewmat'

jvm_g_mmove_jviewmat_=: 3 : 0
  'X Y W H'=. 4{.0 ".sysdata
  uhw=.(H,W) % $MAT
  croco=.<.(Y,X)%uhw
  cval=.(<croco){tomatrix DAT
  wd 'pn *',TITLE,' ',":croco,cval
)

--JuneKim