/******************************************************************** Constraint-based Graphical Programming in B-Prolog % A palette of colors *********************************************************************/ go:- cgWindow(Win,"Palette"),Win^topMargin #= 50, Win^leftMargin #= 50, Win^width #>1000, handleWindowClosing(Win), palette("Red","Green","Blue",Palette1,Os1), palette("Green","Blue","Red",Palette2,Os2), palette("Blue","Red","Green",Palette3,Os3), cgLeft(Os1,Os2), cgLeft(Os2,Os3), cgSame(Os1,window,Win), cgSame(Os2,window,Win), cgSame(Os3,window,Win), handleWindowClosing(Win), cgStartRecord(palette), cgShow(Os1),cgShow(Os2),cgShow(Os3), cgStopRecord. handleWindowClosing(Win),{windowClosing(Win)} => cgClose(Win). palette(C1,C2,C3,Palette,Os):- cgLabel([L1,L2,L3],[C1,C2,C3]), % labels for colors cgTextField(Tf1),cgSetText(Tf1,"0"),Tf1^columns #= 4, new_array(Palette,[19,19]), createLabels(2,19,Palette), createSquares(2,19,Palette), cgGrid(Palette), Palette^[19,19] @= Grid, Grid^width #= 15,Grid^height #= 15, cgSameRow([L1,Tf1]), cgAbove(L1,L2), leftCenter(L2,Palette), topCenter(L3,Palette), % array_to_list(Palette,[_|Os1]), % ignore the square at [1,1] Os=[L1,L2,L3,Tf1|Os1], % changeColors(0,C1,C2,C3,Palette), handleColorInput(Tf1,C1,C2,C3,Palette,Os1). createLabels(I,N,Palette):-I= cgGetText(Tf,Text), catch(number_codes(Scale1,Text),Exception,true), %if malformed, ignore it (var(Scale1)->true; catch(changeColors(Scale1,C1,C2,C3,Palette),_,true), cgShow(Os)). changeColors(Scale1,C1,C2,C3,Palette):- changeColors(2,19,Scale1,C1,C2,C3,Palette). % for each I in 2..19 and J in 2..19, set the color for Palette^[I,J] changeColors(I,N,Scale1,C1,C2,C3,Palette):-I=