borderWidth = 10 edgeColor = {127,127,127} screenWidth = 300 screenHeight = 400 usedWidth = 0 usedHeight = 0 maxCols = 4 maxRows = 4 colWidth = {} rowHeight = {} cols = {} borderPen = 1 function border(v) borderWidth = v end function edgesize(v) borderPen = v end function edgergb(er,eg,eb) -- set the edge RGB assuming gl-style (0.-1.) color edgeColor = {er*255,eg*255,eb*255} end function loadbang() -- this sets up the two-dimensional matrix colWidth with enough spaces for a 10 x 10 comic page for i = 1,10 do colWidth[i] = {} for j = 1,10 do colWidth[i][j] = 0 --print("setup:",i,j,colWidth[i][j]) end end end function go() usedHeight = 0 usedWidth = 0 x1,y1 = borderWidth,borderWidth -- inset the top left by the border width rows = math.random(2,maxRows) -- create a random number of rows --print("rows:",rows) for row = 1,rows do -- step through each row if row ~= rows then -- if it's not the last row, choose a random height, not more than 1/2 of the unused space, and not less than 1/4 rowHeight[row] = math.random(math.floor((screenHeight-usedHeight)/4),math.floor((screenHeight-usedHeight)/2)) usedHeight = usedHeight + rowHeight[row] -- add this to the total used height of the page else rowHeight[row] = screenHeight - usedHeight - borderWidth -- if it is the last row, use up the rest of the space on the page end y2 = rowHeight[row] -- y2 is always equal to the height of the current row cols[row] = math.random(1,maxCols) -- create a random number of columns in this row --print("columns in row",row,":",cols[row]) for col = 1,cols[row] do -- for each column in this row: if col ~= cols[row] then -- if it's not the last column, choose a random width, not more than 1/2 of the unused space, and not less than 1/4 colWidth[row][col] = math.random(math.floor((screenWidth-usedWidth)/4),math.floor((screenWidth-usedWidth)/2)) usedWidth = usedWidth + colWidth[row][col] -- add this to the total width used in this column else colWidth[row][col] = screenWidth - usedWidth - borderWidth -- if it is the last column, use up the rest of the width of the page usedWidth = 0 -- reset the usedWidth so that the next row begins at the left edge end x2 = colWidth[row][col] -- x2 is always the width of the current column --print(row,col,colWidth[row][col],rowHeight[row]) r,g,b=math.random(0,127),math.random(0,127),math.random(0,127) -- random fill color color={"frgb",r,g,b} outlet(0,color) fill={"paintrect",x1,y1,x1+x2-borderWidth,y1+y2-borderWidth} -- draw the filled rect outlet(0,fill) edge={"frgb",edgeColor[1],edgeColor[2],edgeColor[3]} -- set the edge color outlet(0,edge) pen={"pensize",borderPen,borderPen} -- set the pen size outlet(0,pen) output={"framerect",x1,y1,x1+x2-borderWidth,y1+y2-borderWidth} -- draw the edge outlet(0,output) outlet(0,"bang") -- bang to output the frame from the jit.lcd x1 = x1+x2 -- after drawing each box in the column, increment x1 by the width of the last column drawn end x1 = borderWidth -- after finishing a row, reset x1 y1 = y1+y2 -- after finishing a row, increment y1 end end