|
Post by andyweil on Jul 8, 2018 15:02:34 GMT
I wish to move (re-arrange) letter characters in a display matrix. This is part of the 'Beale Treasure Cipher" solution. the display matrix is a character display of width 40 and highth of 13. The squares in the matrix are numbered from 1 to 520 (the number of characters in the Beale Cipher #1). I don,t need to use as a matrix per-se, only the numbered squares that I can input characters to, will be swapped. Each cell will display only one letter. It would also be helpful to change the background of each square also. Any help is appreciated! Would this make a challenging program?
|
|
|
Post by Rod on Jul 8, 2018 16:12:28 GMT
It isn’t challenging for Just BASIC but it is a good challenge for readers. If the sun wasn’t splitting the sky and drawing me outdoors you would get an instant solution. But let’s see what members post, give it a little time.
|
|
|
Post by B+ on Jul 8, 2018 16:25:27 GMT
Hi Do you want to print characters or numbers into a grid 40 cells wide and 13 cells high? Maybe fit up to 3 digits in a cell? If so here it is. ( I am already sun burnt!) 'grid 40 x 13 3 character cells
for row = 1 to 13 for col = 1 to 40 rCnt = int(rnd(0) * 3) + 1 s$ = "" for i = 1 to rCnt s$ = s$ + rChar$() next call show col, row, s$ next next
function rChar$() rChar$ = mid$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890", int(rnd(0)*62) + 1, 1) end function
sub show col, row, c3$ locate col * 5 + 1, 2 * row + 1 : print mid$(c3$, 1, 3) end sub
|
|
|
Post by B+ on Jul 9, 2018 14:01:55 GMT
And here is a colorized version using a graphics window and 40 x 13 Matrix example. PLUS! I added a message and "coded" it by reversing it. 'Graphics Matrix with color 40x13 example.txt for Just Basic v2 B+ started 2018-07-09
'grid 40 x 13 1 character cells with custom colors for fore and back
global xmax, ymax 'workspace in the screen xmax = 1020 ymax = 500
'sample matrix 40 x 13 use global "constants" for procedure global lrow, lcol, maxC0ol, maxRow, minRC, cellWidth, cellHeight, matrixOffsetX, matrixOffsetY maxCol = 40 'matrix Columns maxRow = 13 'martrix Rows minRC = 1 'minimum row or col is 1
'give our matrix a margin of 10 pixels down from top and 10 from left matrixOffsetX = 10 matrixOffsetY = 10
'decide cell dimensions cellWidth = 25 cellHeight = 25
nomainwin WindowWidth = xmax + 8 WindowHeight = ymax + 32 UpperLeftX = (1200 - xmax) / 2 UpperLeftY = (700 - ymax) / 2
open "Graphics Matrix with color 40 x 13 example" for graphics_nsb_nf as #gr #gr "setfocus" #gr "trapclose quit" #gr "when leftButtonUp lButtonUp" #gr "when characterInput charIn" #gr "down"
'some test code for row = minRC to maxRow for col = minRC to maxCol lNum = (row - 1) * maxCol + (col - 1) l$ = mid$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890", (lNum mod 62) + 1 , 1) if col mod 2 then if row mod 2 then rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) else rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) * 10 end if else if row mod 2 = 0 then rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) else rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) * 10 end if end if call show col, row, 000, rColor, l$ next next
'show a message message$ = "So how do you like the colored Matrix?" fc = 000 : bc = 008 for i = 1 to len(message$) l$ = mid$(message$, i, 1) call show i, 16, fc, bc, l$ next
'code message by reversing it fc = 999 : bc = 800 : col = 1 for i = len(message$) to 1 step -1 l$ = mid$(message$, i, 1) call show col, 18, fc, bc, l$ col = col + 1 next #gr "flush" wait
' ====================================== procedures this window
sub quit H$ close #gr end end sub
sub lButtonUp H$, mx, my call quit H$ end sub
sub charIn H$, c$ if c$ = "q" then call quit H$ end sub
sub show col, row, fc, bc, l$ ' fill cell at (row, col) with fore color = fc and back color = bc and letter = l$ 'set color using rgb numbering system call frgb fc call brgb bc x = (col - 1) * cellWidth + matrixOffsetX y = (row - 1) * cellHeight + matrixOffsetY call fbox x, y, x + cellWidth, y + cellHeight call frgb 999 #gr "place ";x+.5*cellWidth-4;" ";y+.5*cellHeight+7;";\";l$ end sub
' ====================================== JB Library of procedures
'rgb color system for 3 digit numbers
' red level = digit 0 to 9 X 100 'green level = digit 0 to 9 X 10 ' blue level = digit 0 to 9 X 1
'example yellow = max red + max green + 0 blue ' 900 + 90 + 0 = 990 is yellow in rgb system
sub rgb n3 'both fore and back colors s3$ = right$("000";str$(n3), 3) r = 28 * val(mid$(s3$, 1, 1)) + 3 g = 28 * val(mid$(s3$, 2, 1)) + 3 b = 28 * val(mid$(s3$, 3, 1)) + 3 #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub frgb n3 'only fore color s3$ = right$("000";str$(n3), 3) r = 28 * val(mid$(s3$, 1, 1)) + 3 g = 28 * val(mid$(s3$, 2, 1)) + 3 b = 28 * val(mid$(s3$, 3, 1)) + 3 #gr "color ";r;" ";g;" ";b end sub
sub brgb n3 'only back color s3$ = right$("000";str$(n3), 3) r = 28 * val(mid$(s3$, 1, 1)) + 3 g = 28 * val(mid$(s3$, 2, 1)) + 3 b = 28 * val(mid$(s3$, 3, 1)) + 3 #gr "backcolor ";r;" ";g;" ";b end sub
sub fbox x0, y0, x1, y1 'fill a box #gr "place ";x0;" ";y0 #gr "boxfilled ";x1 + 1;" ";y1 + 1 end sub
|
|
|
Post by tsh73 on Jul 9, 2018 19:27:50 GMT
OK, now try clicking inside colored matrix. Letters are swapped (colors are lost, alas ) 'Graphics Matrix with color 40x13 example.txt for Just Basic v2 B+ started 2018-07-09
'grid 40 x 13 1 character cells with custom colors for fore and back
global xmax, ymax 'workspace in the screen xmax = 1020 ymax = 500
'sample matrix 40 x 13 use global "constants" for procedure global lrow, lcol, maxCol, maxRow, minRC, cellWidth, cellHeight, matrixOffsetX, matrixOffsetY maxCol = 40 'matrix Columns maxRow = 13 'martrix Rows dim text$(maxRow, maxCol) minRC = 1 'minimum row or col is 1 global selCol,selRow
'give our matrix a margin of 10 pixels down from top and 10 from left matrixOffsetX = 10 matrixOffsetY = 10
'decide cell dimensions cellWidth = 25 cellHeight = 25
nomainwin WindowWidth = xmax + 8 WindowHeight = ymax + 32 UpperLeftX = (1200 - xmax) / 2 UpperLeftY = (700 - ymax) / 2
open "Graphics Matrix with color 40 x 13 example" for graphics_nsb_nf as #gr #gr "setfocus" #gr "trapclose quit" #gr "when leftButtonUp lButtonUp" #gr "when characterInput charIn" #gr "down"
'some test code for row = minRC to maxRow for col = minRC to maxCol lNum = (row - 1) * maxCol + (col - 1) l$ = mid$("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890", (lNum mod 62) + 1 , 1) text$(row, col)=l$ if col mod 2 then if row mod 2 then rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) else rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) * 10 end if else if row mod 2 = 0 then rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) else rColor = (col mod 5 + 1) * 100 + (row mod 5 + 1) * 10 end if end if call show col, row, 000, rColor, text$(row, col) next next
'show a message message$ = "So how do you like the colored Matrix?" fc = 000 : bc = 008 for i = 1 to len(message$) l$ = mid$(message$, i, 1) call show i, 16, fc, bc, l$ next
'code message by reversing it fc = 999 : bc = 800 : col = 1 for i = len(message$) to 1 step -1 l$ = mid$(message$, i, 1) call show col, 18, fc, bc, l$ col = col + 1 next #gr "flush"
selection$="" wait
' ====================================== procedures this window
sub quit H$ close #gr end end sub
sub lButtonUp H$, mx, my 'call quit H$ 'get col, row out of mouseX mouseY 'reverse this 'x = (col - 1) * cellWidth + matrixOffsetX 'y = (row - 1) * cellHeight + matrixOffsetY col=int((mx- matrixOffsetX)/cellWidth+1) row=int((my- matrixOffsetY)/cellHeight+1) if (row < minRC) or (row > maxRow) then exit sub 'out of matrix if (col < minRC) or (col > maxCol) then exit sub 'out of matrix if selCol = 0 then 'if not set selCol=col: selRow=row call show col, row, 999, 000, text$(row, col) else 'swap tmp$=text$(row, col) text$(row, col) = text$(selRow, selCol) text$(selRow, selCol)=tmp$ call show selCol, selRow, 000, 555, text$(selRow, selCol) call show col, row, 000, 555, text$(row, col) selCol = 0 'selection off end if end sub
sub charIn H$, c$ if c$ = "q" then call quit H$ end sub
sub show col, row, fc, bc, l$ ' fill cell at (row, col) with fore color = fc and back color = bc and letter = l$ 'set color using rgb numbering system call frgb fc call brgb bc x = (col - 1) * cellWidth + matrixOffsetX y = (row - 1) * cellHeight + matrixOffsetY call fbox x, y, x + cellWidth, y + cellHeight call frgb 999 #gr "place ";x+.5*cellWidth-4;" ";y+.5*cellHeight+7;";\";l$ end sub
' ====================================== JB Library of procedures
'rgb color system for 3 digit numbers
' red level = digit 0 to 9 X 100 'green level = digit 0 to 9 X 10 ' blue level = digit 0 to 9 X 1
'example yellow = max red + max green + 0 blue ' 900 + 90 + 0 = 990 is yellow in rgb system
sub rgb n3 'both fore and back colors s3$ = right$("000";str$(n3), 3) r = 28 * val(mid$(s3$, 1, 1)) + 3 g = 28 * val(mid$(s3$, 2, 1)) + 3 b = 28 * val(mid$(s3$, 3, 1)) + 3 #gr "color ";r;" ";g;" ";b #gr "backcolor ";r;" ";g;" ";b end sub
sub frgb n3 'only fore color s3$ = right$("000";str$(n3), 3) r = 28 * val(mid$(s3$, 1, 1)) + 3 g = 28 * val(mid$(s3$, 2, 1)) + 3 b = 28 * val(mid$(s3$, 3, 1)) + 3 #gr "color ";r;" ";g;" ";b end sub
sub brgb n3 'only back color s3$ = right$("000";str$(n3), 3) r = 28 * val(mid$(s3$, 1, 1)) + 3 g = 28 * val(mid$(s3$, 2, 1)) + 3 b = 28 * val(mid$(s3$, 3, 1)) + 3 #gr "backcolor ";r;" ";g;" ";b end sub
sub fbox x0, y0, x1, y1 'fill a box #gr "place ";x0;" ";y0 #gr "boxfilled ";x1 + 1;" ";y1 + 1 end sub
|
|
|
Post by andyweil on Jul 18, 2018 1:49:09 GMT
Thanks for the help with my "matrix" project. I'll have to experiment with these programs a little as I am just beginning to work with Just Basic. As I work full time, I can only spare moments a day to work on this. Hope to master Just Basic in the future. Andy
|
|