Hi @Dave1707! Here is my version: my idea is a bit different: i just want to get the list of unicode characters that can be useful for me. So i can browse the unicode characters (buttons and top row), select/deselect then (touch the chars) and save them in the ‘output’ tab in a string. (save button). Nowni can copy the output tab in another project.
--# Main
-- test char
-- build by JMV38, on top of others posts (see below)
displayMode(FULLSCREEN)
strOut = ""
function setup()
t = 0
base = 0
ni,nj = 20,40
h = 40
i0,j0 = 100,70
iOffset = -30
yInfoBase = HEIGHT -25
yBase = HEIGHT -75
ni = math.floor((HEIGHT-2*i0)/h)
nj = math.floor((WIDTH-2*j0)/h)
init0()
refreshChars = true
charlist()
x0,y0,r0 = WIDTH/2,50,25
xL,yL,r0 = 25,100,25
xR,yR,r0 = WIDTH-25,100,25
tBase=0
changeBase=0
color1 = color(255, 0, 0, 255)
color2 = color(0, 23, 255, 255)
c = color1
rColor = color1
lColor = color1
rectMode(RADIUS)
img0 = image(h,h)
setContext(img0)
background(127, 127, 127, 255)
fill(0, 0, 0, 255)
rect(h/2,h/2,h/2-1,h/2-1)
setContext()
img1 = image(h,h)
setContext(img1)
background(127, 127, 127, 255)
fill(24, 27, 161, 255)
rect(h/2,h/2,h/2-1,h/2-1)
setContext()
spriteMode(CENTER)
end
function drawList()
for i = 1,ni do
for j = 1,nj do
local k = 1 + (i-1)*nj + j-1
if list[k] then sprite(img1, j0+j*h-h/2, i0+i*h + iOffset)
else sprite(img0, j0+j*h-h/2, i0+i*h + iOffset) end
end
end
end
function drawChar()
for i = 1,ni do
for j = 1,nj do
local k = 1 + (i-1)*nj + j-1
text(charTable[k], j0+j*h-h/2, i0+i*h + iOffset)
end
end
end
function drawBase()
for j = 1,nj do
if baseList[j] then sprite(img1, j0+j*h-h/2, yBase)
else sprite(img0, j0+j*h-h/2, yBase) end
text(baseChar[j], j0+j*h-h/2, yBase)
end
end
function checkCharTouched(t)
local j,i = math.floor((t.x-j0)/h+1) , math.floor((t.y-i0-iOffset)/h+0.5)
if (i>0) and (i<=ni) and (j>0) and (j<=nj) then
local k = 1 + (i-1)*nj + j-1
if ElapsedTime < wait[k] then return end
v = list[k]
v = not v
list[k] = v
wait[k] = ElapsedTime + 0.5
end
end
function checkBaseTouched(t)
if ElapsedTime < tBase then return end
local j,y = math.floor((t.x-j0)/h+1) , (t.y-yBase)
if math.abs(y)<h/2 and (j>0) and (j<=nj) then
local k = 1 + j-1
base = baseValue[k]
refreshChars = true
tBase = ElapsedTime + 0.5
for p = 1,nj do
if baseValue[p] == base
then baseList[p] = true
else baseList[p] = false
end
end
end
end
function charlist()
if not refreshChars then return end
local new={}
for i = 1,ni do
for j = 1,nj do
table.insert(new,unicode2UTF8(base*ni*nj+1+(i-1)*nj+(j-1)))
end
end
refreshChars = false
charTable = new
init0()
end
function init0()
list={}
wait = {}
baseList = {}
baseChar = {}
baseValue = {}
collectgarbage()
for i = 1,ni do
for j = 1,nj do
table.insert(list,false)
table.insert(wait,0)
end
end
local dbase = ni*nj
local base0 = base - math.floor(nj/2)
local v,jbase
if base0<0 then base0=0 end
for j = 1,nj do
jbase = (j-1) + base0
table.insert(baseValue,jbase)
table.insert(baseChar,unicode2UTF8( jbase*dbase +1 ) )
v = false
if jbase == base then v = true end
table.insert(baseList,v)
end
end
function save()
c = color2
t = ElapsedTime + 1
local temp = {}
local lines = {}
local buf
for i=1,#list do
if list[i] then table.insert(temp,charTable[i])
end
if #temp>=20 then
buf = "strOut = strOut .. '" .. table.concat(temp,"") .. "'\\r"
table.insert(lines,buf)
temp = {}
end
end
if #temp>0 then
buf = "strOut = strOut .. '" .. table.concat(temp,"") .. "'\\r"
table.insert(lines,buf)
temp = {}
end
local tab = "output"
strOut = readProjectTab(tab)
strOut = strOut .. table.concat(lines,"")
saveProjectTab(tab,strOut)
end
function checkBase()
if ElapsedTime < tBase then return end
if changeBase~=0 then
base = base + changeBase
if changeBase == 1 then rColor = color2 end
if changeBase == -1 then lColor = color2 end
refreshChars = true
tBase = ElapsedTime + 0.5
end
end
function touched(touch)
if touch.state == BEGAN then
if math.abs(touch.x-xL)<r0 and math.abs(touch.y-yL)<r0*2 then
changeBase = -1
lColor = color2
end
if math.abs(touch.x-xR)<r0 and math.abs(touch.y-yR)<r0*2 then
changeBase = 1
rColor = color2
end
if math.abs(touch.x-x0)<r0*2 and math.abs(touch.y-y0)<r0
then save() end
end
checkCharTouched(touch)
checkBaseTouched(touch)
if touch.state == ENDED or touch.state == CANCELLED then
changeBase = 0
rColor = color1
lColor = color1
end
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
drawList()
drawChar()
drawBase()
if ElapsedTime>t then c = color1 end
fill(c)
rect(x0,y0,r0*2,r0)
fill(lColor)
rect(xL,yL,r0,r0*2)
fill(rColor)
rect(xR,yR,r0,r0*2)
fill(255, 255, 255, 255)
text("SAVE",x0,y0)
text("<<",xL,yL)
text(">>",xR,yR)
-- This sets the line thickness
--strokeWidth(5)
noStroke()
fontSize(20)
font("AppleColorEmoji")
-- Do your drawing here
fill(253, 253, 253, 255)
textWrapWidth(WIDTH*0.95)
text(tostring(base*ni*nj+1).." - "..tostring((base+1)*ni*nj),WIDTH/2,yInfoBase)
checkBase()
charlist()
end
-- Unicode code point to UTF-8 format string of bytes
--
-- Bit Last point Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
-- 7 U+007F 0xxxxxxx
-- 11 U+07FF 110xxxxx 10xxxxxx
-- 16 U+FFFF 1110xxxx 10xxxxxx 10xxxxxx
-- 21 U+1FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-- 26 U+3FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
-- 31 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
--
-- However, largest integer in Codea's Lua is 0x7FFFFF (23 bit)
-- With acknowledgement also to Andrew Stacey's UTF-8 library
function unicode2UTF8(u)
u = math.max(0, math.floor(u)) -- A positive integer
local UTF8
if u < 0x80 then -- less than 8 bits
UTF8 = string.char(u)
elseif u < 0x800 then -- less than 12 bits
local b2 = u % 0x40 + 0x80
local b1 = math.floor(u/0x40) + 0xC0
UTF8 = string.char(b1, b2)
elseif u < 0x10000 then -- less than 16 bits
local b3 = u % 0x40 + 0x80
local b2 = math.floor(u/0x40) % 0x40 + 0x80
local b1 = math.floor(u/0x1000) + 0xE0
UTF8 = string.char(b1, b2, b3)
elseif u < 0x200000 then -- less than 22 bits
local b4 = u % 0x40 + 0x80
local b3 = math.floor(u/0x40) % 0x40 + 0x80
local b2 = math.floor(u/0x1000) % 0x40 + 0x80
local b1 = math.floor(u/0x40000) + 0xF0
UTF8 = string.char(b1, b2, b3, b4)
elseif u < 0x800000 then -- less than 24 bits
local b5 = u % 0x40 + 0x80
local b4 = math.floor(u/0x40) % 0x40 + 0x80
local b3 = math.floor(u/0x1000) % 0x40 + 0x80
local b2 = math.floor(u/0x40000) % 0x40 + 0x80
local b1 = math.floor(u/0x1000000) + 0xF8
UTF8 = string.char(b1, b2, b3, b4, b5)
else
print("Error: Code point too large for Codea's Lua.")
end
return UTF8
end
--# output
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????'
strOut = strOut .. '??????'
strOut = strOut .. '??'
strOut = strOut .. '????????????????????'
strOut = strOut .. '?????????????'
strOut = strOut .. '???????????'
strOut = strOut .. '??????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '?????????????????'
strOut = strOut .. '??'
strOut = strOut .. '???????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '??????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '???????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '????????????????????'
strOut = strOut .. '??????????????'
strOut = strOut .. '?'
strOut = strOut .. '?'
strOut = strOut .. '?'