When using "paint" programs, I have often been frustrated by the UI
used to present the color palette.

Here's a rough draft of what I think a proper color palette should
look like.  It uses j602 wd. It's also twice as big as it needs to be
(because j602 wd uses a unit which is two pixels wide and I did not
see any reason to fight that for a rough draft).

Also beware email induced line wrap, especially for the definitions of
'giftwrap' and 'CORNERSETS'. Ideally, these should be simplified, but
I'm feeling lazy about that right now.

To use: copy and paste into a file, fix any wrapped lines, load the
file (should cause no errors if you have fixed all the line wrapping
problems) then run:

''conew'colourchoice'

You should get a window with a scrollbar on the left. All you can do
with it in this implementation is play with the scrollbar.  If you are
using windows you will only get a scroll event when you release the
scrollbar. If you are using mac you should get smooth scrolling. You
may run into other issues (64 bit windows does not support opengl
until you copy the 32 bit implementation to the 64 bit implementation,
for example).

Anyways, here it is, if anyone wants to play with it (or port it, or
make it into something useful, or whatever):


coclass 'colourchoice'
require 'jzopengl'
coinsert 'jzopengl'

Note 'wd'
  p - parent window
  s - scrollbar -- S will be numeric value 0..255
      repesents distance along white/black diagonal
  c - color display
)

NB. object constructor
create=:3 :0
  ogl=: ''conew'jzopengl'
  wd 'pc p;'
  wd 'xywh 0 0 10 256; cc s scrollbarv bottommove; set s 0 127 255 39;'
  S=: 127
  wd 'xywh 10 0 256 256; cc c isigraph opengl rightmove bottommove;'
  wd 'pas 0 0; pshow;'
)

NB. event handlers
p_close=: destroy

p_c_paint=: 3 :0
  rc__ogl''
  glClear GL_COLOR_BUFFER_BIT
  C=: S {:: CORNERSETS
  select. #C
    case. 1 do.
      if. C do. 1 1 1 tri 254 {:: CORNERSETS
      else.     0 0 0 tri 1   {:: CORNERSETS end.
    case. 3 do.
      tri C
    case. 6 do.
      tri C
  end.
  show__ogl''
)

p_s_button=: 3 :0
  S=: 0 ". s
  wd 'setinvalid c'
)

NB. implementation

destroy=: 3 :0
  destroy__ogl''
  wd'pclose'
  codestroy''
)

X0=: 1 _1 1 * %: 1 5 1%6
Y0=: _1 0 1 * %: %2
coords=: +/ .*"1&(X0,:Y0)"1

giftwrap=: (,&>/@[ i. 0 {:: (((0&{::@[,]) ; 1&{::@[ -. ]) 1&{:: #~ [:
(= >./) {:@+.@(r.inv)@j./"1@(1&{:: (-"1) _1 {
0&{::))^:5)@(,:@{.;}.)@:coords
CORNERSETS=: ((+/&.:*:"1) <@(({~ giftwrap)^:(6=#))@~./. ]) ,/(([ +"1
(85%~i.86) */ -~)/)"2 ((#~ </"1)8 8 #:I. ,/1=|+/&.:  *:"1 -"1/~ #:i.8)
{ #:i.8

corner=: 4 :0
  glColor3d x
  glVertex2d y
)

tri=: 3 :0"2
  y tri y
:
  glBegin GL_POLYGON
    x corner"1 coords y
  glEnd''
)


Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to