## load with command like ## ## slim ReadSlimFile /home/mach/junk/SRT2008/Grid3.slim ## slim CreatePalette -new ## [slim GetPalettes] CreateAppearance -template personal,Grid#1 ## ## (or create manually through: Right Click -> Colors -> (All Colors) -> Grid) ## ## load with command like "slim ReadSlimFile ./Grid.slim" ## and then create manually through: Right Click -> Colors -> (All Colors) -> Grid ## ## ed. note: the k-browser is actually a great way to find and create this ## appearance ## slim 1 extensions personal { extensions personal personal { customui ButtonInterface { TclTkSource { proc BuildUI {canvas currentWidth args} { set canvasHeight 200 # appearance info set i [lsearch $args -parent] if {$i == -1} return; incr i set parent [lindex $args $i] set apph [$parent GetAppearance] # canvas and frame canvas $canvas \ -width $currentWidth \ -height $canvasHeight set buttonFrame $canvas.buttonFrame frame $buttonFrame \ -width $currentWidth \ -height $canvasHeight set i 0 #for {set x 0} {$x<10} {incr x} { # puts "x is $x" #} for {set y 0} {$y < 10} {incr y} { for {set x 0} {$x < 10} {incr x} { set buttonCheck $buttonFrame.check_${x}_${y} ::RAT::Checkbutton $buttonCheck -command [::RAT::PackageCode [namespace code "toggle $apph grid_${x}_${y}"]] grid $buttonCheck -column $y -row $x } } ### set buttonCheck0 $buttonFrame.check0 ### set buttonCheck1 $buttonFrame.check1 ### set buttonCheck2 $buttonFrame.check2 ### set buttonCheck3 $buttonFrame.check3 ### ### ::RAT::Checkbutton $buttonCheck0 -command [::RAT::PackageCode [namespace code "toggle $apph y_$i"]] ### ::RAT::Checkbutton $buttonCheck1 ### ::RAT::Checkbutton $buttonCheck2 ### ::RAT::Checkbutton $buttonCheck3 ### ### ### # pack ### grid $buttonCheck0 -row 0 -column 0 ### grid $buttonCheck1 -row 0 -column 1 ### grid $buttonCheck2 -row 1 -column 0 ### grid $buttonCheck3 -row 1 -column 1 pack $buttonFrame -anchor nw return [$canvas cget -height] } proc toggle {CDapph parm} { foreach CDph [$CDapph GetProperties -access input] { if {[$CDph GetName] == $parm} { if {[$CDph GetValue] == 0} { $CDph SetValue 1 } else { $CDph SetValue 0 } } } set proph [$CDapph GetProperties -access input -name y_0] if {[$proph GetValue] == 0} { $proph SetValue 1 } else { $proph SetValue 0 } } } } templateV color Grid 1 { label "Grid" description { Grid of buttons } parameter float y_0 { provider variable detail uniform subtype switch default 1 } collection customuiFullWidth ElementHolder { drawmode children customui personal ButtonInterface # customui studio ButtonFloat subtype propertycreator state open # label Minimal; # a signal to the customui } parameter float grid_0_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_0_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_1_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_2_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_3_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_4_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_5_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_6_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_7_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_8_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_0 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_1 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_2 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_3 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_4 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_5 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_6 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_7 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_8 { provider variable detail uniform subtype switch display hidden default 0 } parameter float grid_9_9 { provider variable detail uniform subtype switch display hidden default 0 } parameter float seed { provider variable detail uniform default 0 } parameter color result { access output display hidden } RSLSource StaticFunction { void personalGrid( uniform float y_0; uniform float grid_0_0, grid_1_0, grid_2_0, grid_3_0, grid_4_0, grid_5_0, grid_6_0, grid_7_0, grid_8_0, grid_9_0; uniform float grid_0_1, grid_1_1, grid_2_1, grid_3_1, grid_4_1, grid_5_1, grid_6_1, grid_7_1, grid_8_1, grid_9_1; uniform float grid_0_2, grid_1_2, grid_2_2, grid_3_2, grid_4_2, grid_5_2, grid_6_2, grid_7_2, grid_8_2, grid_9_2; uniform float grid_0_3, grid_1_3, grid_2_3, grid_3_3, grid_4_3, grid_5_3, grid_6_3, grid_7_3, grid_8_3, grid_9_3; uniform float grid_0_4, grid_1_4, grid_2_4, grid_3_4, grid_4_4, grid_5_4, grid_6_4, grid_7_4, grid_8_4, grid_9_4; uniform float grid_0_5, grid_1_5, grid_2_5, grid_3_5, grid_4_5, grid_5_5, grid_6_5, grid_7_5, grid_8_5, grid_9_5; uniform float grid_0_6, grid_1_6, grid_2_6, grid_3_6, grid_4_6, grid_5_6, grid_6_6, grid_7_6, grid_8_6, grid_9_6; uniform float grid_0_7, grid_1_7, grid_2_7, grid_3_7, grid_4_7, grid_5_7, grid_6_7, grid_7_7, grid_8_7, grid_9_7; uniform float grid_0_8, grid_1_8, grid_2_8, grid_3_8, grid_4_8, grid_5_8, grid_6_8, grid_7_8, grid_8_8, grid_9_8; uniform float grid_0_9, grid_1_9, grid_2_9, grid_3_9, grid_4_9, grid_5_9, grid_6_9, grid_7_9, grid_8_9, grid_9_9; uniform float seed; output color result; ) { float grid[] = { grid_0_0, grid_1_0, grid_2_0, grid_3_0, grid_4_0, grid_5_0, grid_6_0, grid_7_0, grid_8_0, grid_9_0, grid_0_1, grid_1_1, grid_2_1, grid_3_1, grid_4_1, grid_5_1, grid_6_1, grid_7_1, grid_8_1, grid_9_1, grid_0_2, grid_1_2, grid_2_2, grid_3_2, grid_4_2, grid_5_2, grid_6_2, grid_7_2, grid_8_2, grid_9_2, grid_0_3, grid_1_3, grid_2_3, grid_3_3, grid_4_3, grid_5_3, grid_6_3, grid_7_3, grid_8_3, grid_9_3, grid_0_4, grid_1_4, grid_2_4, grid_3_4, grid_4_4, grid_5_4, grid_6_4, grid_7_4, grid_8_4, grid_9_4, grid_0_5, grid_1_5, grid_2_5, grid_3_5, grid_4_5, grid_5_5, grid_6_5, grid_7_5, grid_8_5, grid_9_5, grid_0_6, grid_1_6, grid_2_6, grid_3_6, grid_4_6, grid_5_6, grid_6_6, grid_7_6, grid_8_6, grid_9_6, grid_0_7, grid_1_7, grid_2_7, grid_3_7, grid_4_7, grid_5_7, grid_6_7, grid_7_7, grid_8_7, grid_9_7, grid_0_8, grid_1_8, grid_2_8, grid_3_8, grid_4_8, grid_5_8, grid_6_8, grid_7_8, grid_8_8, grid_9_8, grid_0_9, grid_1_9, grid_2_9, grid_3_9, grid_4_9, grid_5_9, grid_6_9, grid_7_9, grid_8_9, grid_9_9 }; uniform float segment0[10] = {1, 0, 0, 0, 1, 1, 1, 0, 1, 1}; uniform float segment1[10] = {1, 0, 1, 0, 0, 0, 1, 0, 1, 0}; uniform float segment2[10] = {1, 0, 1, 1, 0, 1, 1, 1, 1, 1}; uniform float segment3[10] = {0, 0, 1, 1, 1, 1, 1, 0, 1, 1}; uniform float segment4[10] = {1, 0, 1, 1, 0, 1, 1, 0, 1, 1}; uniform float segment5[10] = {1, 1, 1, 1, 1, 0, 0, 1, 1, 1}; uniform float segment6[10] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 1}; float dist(uniform float aX, aY, bX, bY; float cX, cY;) { uniform float aaX = mix(aX, bX, .15); uniform float aaY = mix(aY, bY, .15); uniform float bbX = mix(aX, bX, .85); uniform float bbY = mix(aY, bY, .85); uniform float tanX = bbX - aaX; uniform float tanY = bbY - aaY; uniform float tanLength = sqrt(tanX * tanX + tanY * tanY); tanX /= tanLength; tanY /= tanLength; uniform float normalX = -tanY; uniform float normalY = tanX; uniform float aDotTan = (aaX * tanX) + (aaY * tanY); uniform float bDotTan = (bbX * tanX) + (bbY * tanY); float cDotTan = (cX * tanX) + (cY * tanY); float tanDist; if (cDotTan < aDotTan) tanDist = aDotTan - cDotTan; else if (cDotTan > bDotTan) tanDist = cDotTan - bDotTan; else tanDist = 0; uniform float aDotNormal = (aaX * normalX) + (aaY * normalY); float cDotNormal = (cX * normalX) + (cY * normalY); float normalDist = abs(cDotNormal - aDotNormal); return sqrt(tanDist * tanDist + normalDist * normalDist); } #define x0 (.2) #define x1 (.8) #define y0 (.15) #define y1 (.40) #define y2 (.85) uniform float segmentX0[7] = {x0, x0, x0, x0, x0, x1, x1}; uniform float segmentY0[7] = {y0, y1, y0, y1, y2, y0, y1}; uniform float segmentX1[7] = {x0, x0, x1, x1, x1, x1, x1}; uniform float segmentY1[7] = {y1, y2, y0, y1, y2, y1, y2}; // do demo stuff if (seed < 3) { float thisU = mod(10 * u, 1); float thisV = mod(10 * v, 1); float thisX = clamp(floor(10 * u), 0, 9); float thisY = clamp(floor(10 * v), 0, 9); float thisXY = thisX + 10 * thisY; if (seed == 0) { if (grid[thisXY] == 1) { result = (0, 1, 0); } else { result = (0, 0, 0); } } else if (seed == 1) { if (grid[thisXY] == 1) { result = cellnoise(thisXY); } else { result = (0, 0, 0); } } else { float uRamp = .5 * smoothstep(0, .2, thisU) + .5 * smoothstep(.8, 1, thisU); float vRamp = .5 * smoothstep(0, .2, thisV) + .5 * smoothstep(.8, 1, thisV); if (grid[thisXY] == 1) { result = cellnoise(thisXY); result *= uRamp * vRamp; } else { result = (1, 1, 1); result *= (1 - uRamp) * (1 - vRamp); } } } // do minesweeper game else { // place bombs uniform float bombs[100]; uniform float i, ix, iy, jx, jy; for (i = 0; i < 100; i += 1) { bombs[i] = cellnoise(i, seed) < .1 ? 1 : 0; } // calculate values uniform float values[100] = { 3,1,4,1,5,9,2,6,5,3, 5,8,9,7,9,3,2,3,8,4, 6,2,6,4,3,3,8,3,2,7, 9,5,0,2,8,8,4,1,9,7, 1,6,9,3,9,9,3,7,5,1, 0,5,8,2,0,9,7,4,9,4, 4,5,9,2,3,0,7,8,1,6, 4,0,6,2,8,6,2,0,8,9, 9,8,6,2,8,0,3,4,8,2, 5,3,4,2,1,1,7,0,6,7 }; for (ix = 0; ix < 10; ix += 1) for (iy = 0; iy < 10; iy += 1) { values[ix + 10 * iy] = 0; for (jx = max(0, ix - 1); jx <= min(9, ix + 1); jx += 1) for (jy = max(0, iy - 1); jy <= min(9, iy + 1); jy += 1) { values[ix + 10 * iy] += bombs[jx + 10 * jy]; } } float thisU = mod(10 * u, 1); float thisV = mod(10 * v, 1); float thisX = clamp(floor(10 * u), 0, 9); float thisY = clamp(floor(10 * v), 0, 9); float thisXY = thisX + 10 * thisY; // if button pressed if (grid[thisXY] == 1) { if (bombs[thisXY] == 0) { // background float uRamp = .5 * smoothstep(0, .2, thisU) + .5 * smoothstep(.8, 1, thisU); float vRamp = .5 * smoothstep(0, .2, thisV) + .5 * smoothstep(.8, 1, thisV); float n = floor(10 * cellnoise(10 * u, 10 * v)); n = values[thisXY]; float segmentOn[7] = { segment0[n], segment1[n], segment2[n], segment3[n], segment4[n], segment5[n], segment6[n] }; float dist = 1; float thisDist; for (i = 0; i < 7; i += 1) { thisDist = dist(segmentX0[i], segmentY0[i], segmentX1[i], segmentY1[i], thisU, thisV); if (segmentOn[i] == 1 && dist > thisDist) dist = thisDist; } dist = smoothstep(.05, 0.08, dist); result = uRamp * vRamp; result = mix(color(1,1,1) * uRamp * vRamp, color(0, 1, 0), 1 - dist); } else { result = (.8, 0, 0); } } // else button not pressed else { float uRamp = 1 - .5 * smoothstep(0, .2, thisU) - .5 * smoothstep(.8, 1, thisU); float vRamp = 1 - .5 * smoothstep(0, .2, thisV) - .5 * smoothstep(.8, 1, thisV); result = uRamp * vRamp; } float bombed = 0; for (i = 0; i < 100; i += 1) { if (bombs[i] == 1 && grid[i] == 1) { bombed = 1; } } if (bombed == 1) { result = mix(result, color(1, 0, 0), .5); } } } } } } }