Here's a script I'm very proud of. It was written for and dedicated to - cj's, Jochen's and my children. It the old standard, you may remember: LiteBrite by Milton Bradley ...



; BRITE.KIX
;
; KIXTART 4.01
; KIXFORMS BUILD 4
;
;====================================
;
; This script is dedicated to:
;
; Jessica and Christopher (Tassie)
; Sonja, Jan and Lara (Polster)
; Frances (Matheson)
;
;====================================
;


break on


$CELLWIDTH = 12
$CELLHEIGHT = 12
$CIRCLERADIUS = 5
$MAXCOL = 50
$MAXROW = 28
$XOFFSET = 20
$YOFFSET = 20
$MAXX = $MAXCOL * $CELLWIDTH + $XOFFSET
$MAXY = $MAXROW * $CELLHEIGHT + $YOFFSET
$CRLF = CHR(13)+CHR(10)


$drawing = 0


;======
; FORM
;======

$form = createobject("kixtart.form")
$form.caption = "Lite Brite - KiXtart"
$form.width = 725
$form.height = 405
$form.top = ($form.screenheight - $form.height ) / 2
$form.left = ($form.screenwidth - $form.width ) / 2
$form.borderstyle=1
$form.forecolor = $form.rgb(100,100,100)
$form.backcolor = 0
$form.fontsize = 9
$form.fontname = "courier new"
$form.backstyle = 1


;==========
; CONTROLS
;==========


$clear = $form.commandbutton(635,20,70,25,"Clear")


$save = $form.commandbutton(635,50,70,25,"Save")


$load = $form.commandbutton(635,80,70,25,"Load")


;======
; GRID
;======


dim $row[$MAXROW-1]
global $grid[$MAXCOL-1]
for $i = 0 to ubound($grid)
$grid[$i] = $row
for $j = 0 to ubound($grid[$i])
$grid[$i][$j] = 0 ; black
next
next


$form.forecolor = &646464
$form.fillstyle = 1
for $y = $YOFFSET to $MAXY step $CELLHEIGHT
$form.line($XOFFSET,$y,$MAXX+1,$y)
next
for $x = $XOFFSET to $MAXX step $CELLWIDTH
$form.line($x,$YOFFSET,$x,$MAXY+1)
next


;=========
; PALETTE
;=========


global $palette[15]
$palette[0] = 0
$palette[1] = 8388608
$palette[2] = 32768
$palette[3] = 8421376
$palette[4] = 128
$palette[5] = 8388736
$palette[6] = 32896
$palette[7] = 12632256
$palette[8] = 8421504
$palette[9] = 16711680
$palette[10] = 65280
$palette[11] = 16776960
$palette[12] = 255
$palette[13] = 16711935
$palette[14] = 65535
$palette[15] = 16777215


$color=0
$form.fillstyle = 1
$form.forecolor = &FFFFFF
for $x = 0 to 15
$form.fillcolor = $palette[$x]
$form.rectangle(635,118+($x*15),70,15)
next


$color = $form.rgb(255,0,0)


;====
; START
;====


load_click("brite.spl")


$form.show


while $form.getevent


select


case $clear.click


clear_click()


case $load.click


load_click("brite.spl")


case $save.click


save_click("brite.spl")


case $form.mousedown


mouse_down($form.mousebutton,$form.mousex,$form.mousey)


case $form.mouseup


mouse_up($form.mousebutton,$form.mousex,$form.mousey)


case $form.mousemove


mouse_move($form.mousebutton,$form.mousex,$form.mousey)

case 1

endselect

loop

exit 1


function mouse_down($button,$x,$y)
$drawing = 1
addcell($x,$y,$color)
endfunction


function mouse_move($button,$x,$y)
$form.forecolor = &FFFF00
$form.moveto(20,360)
$form.print(" ")
$c = $form.pixel($x,$y)
$form.print("x:$x y:$y c:$c")
if $drawing
addcell($x,$y,$color)
endif
endfunction


function mouse_up($button,$x,$y)
$drawing = 0
endfunction


function addcell($x,$y,$c)


dim $col,$row


if ( $x > 637 and $x < 704 and $y > 46 and $y < 357 )
$color = $form.pixel($x,$y)
return
endif


if $drawing
if ( $x > $XOFFSET and $x < $MAXX and $y > $YOFFSET and $y < $MAXY )
$row = ($y - $YOFFSET) / $CELLHEIGHT
$col = ($x - $XOFFSET) / $CELLWIDTH
drawcell($row,$col,$c)
$grid[$col][$row] = $c
endif
endif

endfunction


function drawcell($row,$col,$c)
$form.forecolor = $c
$form.fillstyle = 1 ; solid
$form.fillcolor = $c
$cx = $col*$CELLWIDTH+$XOFFSET+$CELLWIDTH/2
$cy = $row*$CELLHEIGHT+$YOFFSET+$CELLHEIGHT/2
$form.circle($cx,$cy,$CIRCLERADIUS)
if $c
$form.forecolor = &FFFFFF
$form.fillcolor = &FFFFFF
$form.circle($cx,$cy-1,2)
endif
endfunction


function clear_click()
$form.forecolor = 0 ;$form.backcolor
$form.fillcolor = 0 ;$form.backcolor
$form.fillstyle = 1 ; solid
for $col = 0 to ubound($grid)
for $row = 0 to ubound($grid[$col])
if $grid[$col][$row] ; not black
$form.circle( $col*$CELLWIDTH+$XOFFSET+$CELLWIDTH/2,
$row*$CELLHEIGHT+$YOFFSET+$CELLHEIGHT/2,
$CIRCLERADIUS)
$grid[$col][$row] = 0
endif
next
next
endfunction


function save_click($filename)
dim $row,$col,$c
del "@curdir\$filename"
if open(1,"@curdir\$filename",5) = 0
for $col = 0 to ubound($grid)
for $row = 0 to ubound($grid[$col])
if $grid[$col][$row] ; not black
$c = $grid[$col][$row]
$=writeline(1,"$col,$row,$c"+$crlf)
endif
next
next
$=close(1)
endif
endfunction


function load_click($filename)
clear_click()
if open(1,"@curdir\$filename") = 0
$drawing=1
$line = readline(1)
while $line and not @error
if $line
$data = split($line,",")
$col = val($data[0])
$row = val($data[1])
$c = val($data[2])
drawcell($row,$col,$c)
$grid[$col][$row] = $c
endif
$line = readline(1)
loop
$=close(1)
$drawing=0
endif
endfunction

-Shawn

[ 19 December 2001: Message edited by: Shawn ]