--# Datai function lademucon(ty) file=string.format(ty).."-lay"..lay..".mucon" txt=readGlobalData(file,0) output.clear() -- print ("lade..."..file) -- print(txt) if string.len(txt)>=60 then c=0 a=0 for y=1,8 do c=c+1 for x=1,8 do a=string.byte(string.sub(txt,c))-48 if a>= 0 then table.insert(panz[x],y,a) end c=c+1 end end -- tanz=panz for y=1,8 do for x=1,8 do tanz[x][y]=panz[x][y] end end for y=1,8 do for x=1,8 do panz[x][y]=tanz[x][9-y] end end end end function lademucont(ty) file=string.format(ty).."-lay"..lay..".mucon" txt=readGlobalData(file,0) if string.len(txt)>=60 then c=0 a=0 for y=1,8 do c=c+1 for x=1,8 do a=string.byte(string.sub(txt,c))-48 if a>= 0 and a<=4 then table.insert(tanz[x],y,a) end c=c+1 end end else for y=1,8 do for x=1,8 do tanz[x][y]=0 end end end end function speichermucon(ty) file=string.format(ty).."-lay"..lay..".mucon" saveGlobalData(file,tout) if tonline==1 then httpout(user,lay,ty,sout) end fuellegrid(-2) if gamestate==0 then machthumb((13*page)+1-ty) end end function saveanim() gout="" for q=1,600 do file=string.format(q).."-lay"..lay..".mucon" txt=readGlobalData(file,0) if string.len(txt)>=60 then gout=gout..txt end end print(gout) end function ladethumb() background(0, 0, 0, 255) strokeWidth(1) for h=13,1,-1 do lademucont((13*page)+1-h) machthumb(h) end end --# Funktionen function maketext() showText("MuConMaker Ver. "..version,3*stx,14*sty,18) showText("cls",3*stx,10*sty,18) showText("F1",4*stx,10*sty,18) showText("F2",5*stx,10*sty,18) showText("F3",6*stx,10*sty,18) showText("rnd",7*stx,10*sty,18) showText(mcol.."Col",8*stx,10*sty,18) showText("last",3*stx,11*sty,18) showText("+1",4*stx,11*sty,18) showText("up",5*stx,11*sty,18) showText("down",6*stx,11*sty,18) showText("left",7*stx,11*sty,18) showText("right",8*stx,11*sty,18) showText("Rot.",3*stx,12*sty,18) if mirv==1 then fill(153, 26, 138, 255) rect(4*stx,12*sty,50,50) end showText("MirV",4*stx,12*sty,18) if mirh==1 then fill(153, 26, 138, 255) rect(5*stx,12*sty,50,50) end showText("MirH",5*stx,12*sty,18) showText("MirA",6*stx,12*sty,18) showText("Add",7*stx,12*sty,18) for y=13,1,-1 do showText("Save",12*stx,y*sty,18) end showText("Play",13*stx,14*sty,18) showText("->",11*stx,14*sty,18) showText("<-",9*stx,14*sty,18) showText("Page",10*stx,14*sty,18) showText(page,12*stx,14*sty,18) showText("->",11*stx,13*sty,18) showText("<-",9*stx,13*sty,18) showText("Lay"..lay,10*stx,13*sty,18) end function timeaktion() timer=timer+DeltaTime if timer>0.08 then if abspielen<=13 * page and abspielen >=1 then lademucon(abspielen) abspielen=abspielen+1 timer=0 end end if timer>live and tonline==1 then ladeserver() timer=0 end end function fuellegrid(wert) for x=1,8 do for y=1,8 do if wert==-1 then tanz[x][y]=panz[x][y] elseif wert==-2 then tanz[x][y]=panz[x][9-y] elseif wert==-3 then tanz[x][y]=panz[9-x][y] elseif wert==-4 then panz[x][y]=tanz[x][y] elseif wert==-5 then panz[x][y]=pfb[x][y] else panz[x][y]=wert end end end end --# Inputbox function getuser(akt) doaktion=akt background(0,0,0) if doaktion=="user" then showTextout("Username ?",WIDTH/2,600,80,255 ) end if doaktion=="otheruser" then showTextout("Other Username ?",WIDTH/2,600,60,255 ) end if doaktion=="layer" then showTextout("Layer number \n 001-999?",WIDTH/2,600,60,255 ) end dl = dl + 1 --print(yourtext) buffer = keyboardBuffer() key=keyboard(key) if buffer then showTextout( buffer, WIDTH/2,400,100,255 ) end end function keyboard(key) -- Did the user press backspace? if key ~= nil then if string.byte(key) == 10 then l=string.len(yourtext) if doaktion=="user" then if l>=2 then user=yourtext yourtext="" hideKeyboard() dl=0 writeouser() gamestate=0 buffer=nil end end if doaktion=="otheruser" then if l>=2 then otheruser=yourtext yourtext="" buffer=nil dl=0 gamestate=3 hideKeyboard() end end if doaktion=="layer" then if l>=2 then otherlayer=yourtext yourtext="" hideKeyboard() dl=0 num=0 gamestate=4 end end elseif string.byte(key) == nil then --must be a backspace if string.len(yourtext) > 0 then yourtext = string.sub(yourtext, 1, string.len(yourtext) - 1) end else yourtext = yourtext..key end end end function showTextout(str , x , y , size, tx ) if size==0 then size=24 end pushStyle() fill(255, 255, 255, tx) font("Copperplate-Bold") fontSize(size) text(str,x,y) popStyle() end --# Main -------------------------------------------------------------- --Project: MuConMaker --Version: Beta 2.3 --Author: iTarum (iT) -------------------------------------------------------------- panz=nil panz={} tanz={} pfb={} stx=50 sty=50 pa=0 dk=100 tx=1 ty=13 dl=0 tout="" gout="" mirv=0 mirh=0 tcount=0 abspielen=0 timer=0 page=1 lay=1 mcol=3 dl=0 user="" tonline=0 oversion=0 gamestate=0 yourtext="" version="2.3" oversion="" doaktion="" num=0 dweiter=0 live=10 rpipath="http://www.tarum.net/rpi/rpi1action.php" facebot="http://www.tarum.net/rpi/facebot/action.php" function setup() saveProjectInfo("Project","MuConMaker") saveProjectInfo("Author","iTarum") saveProjectInfo("Description","8x8 BiColor LED Matrix editor") backingMode(RETAINED) supportedOrientations(LANDSCAPE_ANY) displayMode(STANDARD) hideKeyboard() machgitter() zeichnep() ladethumb() parameter.action("Online/Offline", function() if tonline==0 then readouser() tonline=1 print("Now online, you will see the last save of others or yourselfe") checkversion() else tonline=0 print("Offline") end end ) parameter.action("Load online", function() ladeserver() aktion(10) end ) parameter.action("Save Animation", function() saveanim() end ) parameter.action("Load other user", function() gamestate=2 end ) parameter.action("Pi Live / 1min sync", function() if live==10 then http.request(rpipath.."?action=start&python=/led/ledonline.py",didPutData) live=1 print("Live") else http.request("http://www.tarum.net/codea/codeacon.php?argmt=abort",didPutData) live=10 print("1min sync.") end end ) parameter.action("Pi ledadb.py", function() http.request(rpipath.."?action=start&python=/led/ledadb.py&cmd=D",didPutData) end ) end -- This function gets called once every frame function draw() if gamestate==0 then noSmooth() loeschen() strokeWidth(5) zeichnep() zeichnefinger() maketext() timeaktion() elseif gamestate ==1 then if dl==0 then showKeyboard() end if isKeyboardShowing()==false then showKeyboard() end dl=1 getuser("user") elseif gamestate ==2 then if dl==0 then showKeyboard() end if isKeyboardShowing()==false then showKeyboard() end dl=1 getuser("otheruser") elseif gamestate ==3 then if dl==0 then showKeyboard() end if isKeyboardShowing()==false then showKeyboard() end dl=1 getuser("layer") elseif gamestate==4 then if dweiter==0 then dweiter=1 makeotherlayer(num) end end end function zeichnefinger() if tx<=11 then stroke(255, 0, 0, 255) line(tx*stx,ty*sty,(tx*stx)+stx,ty*sty) line((tx*stx)+stx,ty*sty,(tx*stx)+stx,(ty*sty)+sty) line((tx*stx)+stx,(ty*sty)+sty,tx*stx,(ty*sty)+sty) line(tx*stx,(ty*sty)+sty,tx*stx,ty*sty) end end function zeichnep() stroke(0, 0, 0, 255) for x=1,8 do for y=1,8 do zeichnerec(x,y) end end end function zeichnerec(x,y) if panz[x][y]==1 then fill(100, 255, 0, 255) elseif panz[x][y]==2 then fill(255, 1, 0, 255) elseif panz[x][y]==3 then fill(255, 203, 0, 255) else fill(47, 44, 44, 255) end rect(x*stx,y*sty,stx,sty) -- stroke(0, 0, 0, 255) -- showText((panz[x][y]),minx[x][y],maxy[x][y]-50,30) end function machgitter() panz={} tanz={} pfb={} for x=0,9 do panz[x]={} tanz[x]={} pfb[x]={} for y=0,9 do panz[x][y]=0 pfb[x][y]=0 tanz[x][y]=0 end end end function touched() if gamestate==0 then tx=math.ceil(CurrentTouch.x /stx)-1 ty=math.ceil(CurrentTouch.y/sty) -1 if tx<1 then tx=1 end if ty<1 then ty= 1 end if CurrentTouch.state==ENDED then pruefepos(tx,ty,1) end end end function showText(str , x , y , size) pushStyle() fill(255, 255, 255, 255) stroke() font("Copperplate-Light") fontSize(size) text(str,x+25,y+25) popStyle() end function drehen() for y=1,8 do for x=1,8 do pfb[x][y]=panz[x][y] end end for x=1,8 do for y=8,1,-1 do panz[9-y][x]=pfb[x][y] end end end function machthumb(th) x0=(13*50)+10 y0=(th*50)+10 fill(0, 0, 0, 255) stroke(0, 0, 0, 255) rect(x0,y0,50,50) noStroke() for x=1,8 do for y=1,8 do if tanz[x][y]==0 then fill(31, 21, 21, 255) end if tanz[x][y]==1 then fill(0, 255, 24, 255) end if tanz[x][y]==2 then fill(255, 0, 0, 255) end if tanz[x][y]==3 then fill(255, 230, 0, 255) end rect(x0+((x-1)*5),y0+((9-y-1)*5),4,4) end end end function loeschen() fill(0, 0, 0, 255) stroke(0, 0, 0, 255) rect(0,0,WIDTH-100,HEIGHT-60) end --# Online function checkversion() loadhttp("version") oversion=loadhttpret end function readouser() user=readGlobalData("muconmaker.ini",0) if string.len(user) <2 then gamestate=1 else gamestate=0 print ("UserName="..user) writeouser() end end function writeouser() output.clear() http.request("http://www.tarum.net/codea/mucon/mucon.php?action=reguser&user="..user,didPutData) user=string.upper(user) if gamestate~=0 then saveGlobalData("muconmaker.ini",user) print ("UserName="..user) end end function httpout(user,lay,num,argm) http.request("http://www.tarum.net/codea/codeacon.php?argmt="..argm,didPutData) tlay=string.format(lay) if string.len(tlay)<3 then tlay="0"..tlay end if string.len(tlay)<3 then tlay="0"..tlay end tnum=string.format(num) if string.len(tnum)<3 then tnum="0"..tnum end if string.len(tnum)<3 then tnum="0"..tnum end -- print(tlay) http.request("http://www.tarum.net/codea/mucon/mucon.php?action=creat&user="..user.."&layer="..tlay.."&num="..tnum.."&argmt="..argm,didPutData) http.request("http://www.tarum.net/rpi/facebot/action.php?user="..user.."&action=makemucon&arg="..argm,didPutData) end function didPutData(data,status,headers) print(status) end function loadhttp(aktion) loadhttpret=aktion if aktion=="version" then file="mucon/version.txt" end http.request("http://www.tarum.net/codea/"..file,didGetData) end function didGetData(data,status,headers) --if status==200 then if loadhttpret=="version" then loadhttpret=data if version~=loadhttpret then print("New version is available "..loadhttpret) print("Visit www.tarum.net/codea and download the new version. Or play with the old version, what ever you like") end end -- end end function ladeserver() http.request("http://www.tarum.net/codea/dataFromCodea.txt",didDoData) end function didDoData(data,status,headers) if status==200 then x0=(6*50)+7 y0=(14*50)+7 fill(0, 0, 0, 255) stroke(0, 0, 0, 255) rect(x0-10,y0-10,60,60) noStroke() xt=0 for y=1,8 do for x=1,8 do xt=xt+1 d=string.sub(data,xt,xt) if d=="0" then fill(31, 21, 21, 255) end if d=="1" then fill(0, 255, 24, 255) end if d=="2" then fill(255, 0, 0, 255) end if d=="3" then fill(255, 230, 0, 255) end if d~="" then pfb[x][9-y]=string.byte(d)-48 rect(x0+((x-1)*5),y0+((9-y-1)*5),4,4) end end end if gamestate==4 then dweiter=0 end else if gamestate==4 then output.clear() print("Mucon is saved in LAY0") gamestate=0 tonline=1 ladethumb() dweiter=0 end end end function makeotherlayer() num = num + 1 tnum=string.format(num) if string.len(tnum)<3 then tnum="0"..tnum end if string.len(tnum)<3 then tnum="0"..tnum end file="http://www.tarum.net/codea/mucon/mu-"..string.upper(otheruser).."-"..otherlayer.."-"..tnum..".mucon" http.request(file,didDoData) print(file) lay=0 tonline=0 fuellegrid(-5) tout="" for y=1,8 do for x=1,8 do tout=tout..string.format(panz[x][9-y]) end tout=tout.."\n" end speichermucon(num-1) end --# Touchaktion function aktion(index) if index~=10 then for x=1,8 do for y=1,8 do pfb[x][y]=panz[x][y] end end end if index>=0 and index <=3 then for x=1,8 do for y=1,8 do panz[x][y]=index end end if index==0 then fill(0, 0, 0, 255) strokeWidth(5) stroke(0, 0, 0, 255) rect(0,0,WIDTH-150,HEIGHT) end end if index==4 then for x=1,8 do for y=1,8 do panz[x][y]=math.random(0,3) end end end if index==5 then for x=1,8 do for y=1,8 do a=panz[x][y] a = a + 1 if a>=4 then a=0 end panz[x][y]=a end end end if index==15 then for x=1,8 do for y=1,8 do a=panz[x][y] if a~=0 then a = a + 1 end if a>=4 then a=1 end panz[x][y]=a end end end -- up if index==6 then for x=1,8 do for y=8,1,-1 do a=panz[x][y-1] if a==nil then a=0 end panz[x][y]=a end end end -- down if index==7 then for x=1,8 do for y=1,8 do a=panz[x][y+1] if a==nil then a=0 end panz[x][y]=a end end end -- left if index==8 then for x=1,8 do for y=1,8 do a=panz[x+1][y] if a==nil then a=0 end panz[x][y]=a end end end -- right if index==9 then for x=8,1,-1 do for y=1,8 do a=panz[x-1][y] if a==nil then a=0 end panz[x][y]=a end end end -- last if index==10 then for x=1,8 do for y=1,8 do a=pfb[x][y] if a==nil then a=0 end panz[x][y]=a end end end pruefepos(0,0,1) end function pruefepos(xx,yy,index) if yy==10 and xx==3 then aktion(0) end if yy==10 and xx==4 then aktion(1) end if yy==10 and xx==5 then aktion(2) end if yy==10 and xx==6 then aktion(3) end if yy==10 and xx==7 then aktion(4) end if yy==10 and xx==8 then mcol = mcol -1 if mcol<=0 then mcol=3 end end if yy==11 and xx==3 then aktion(10) end if yy==11 and xx==4 then aktion(5) end if yy==11 and xx==5 then aktion(6) end if yy==11 and xx==6 then aktion(7) end if yy==11 and xx==7 then aktion(8) end if yy==11 and xx==8 then aktion(9) end if yy==12 and xx==3 then drehen() end if yy==12 and xx==7 then aktion(15) end if yy==12 and xx==4 then if mirv==0 then mirv=1 else mirv=0 end end if yy==12 and xx==5 then if mirh==0 then mirh=1 else mirh=0 end end if yy==12 and xx==6 then fuellegrid(-3) fuellegrid(-4) end if xx==13 then if yy==14 then abspielen=1 end if yy<=13 and yy>= 1 then lademucon((13*page)+1-yy) end end if xx==12 then if yy<=13 and yy>= 1 then speichermucon((13*page)+1-yy) end end if xx==11 and yy==14 then abspielen=0 page = page + 1 ladethumb() end if xx==9 and yy==14 then page = page - 1 abspielen=0 if page<=1 then page=1 end ladethumb() end if xx==9 and yy==13 then lay = lay - 1 abspielen=0 if lay<=0 then lay=0 end ladethumb() end if xx==11 and yy==13 then lay = lay +1 abspielen=0 if lay>= 20 then lay=20 end ladethumb() end if xx>=9 and xx<=11 and yy==1 then saveanim() end if yy<=8 and xx<=8 and yy>=1 and xx>=1 then panz[xx][yy] = panz[xx][yy] + 1 popStyle() if panz[xx][yy]>mcol then panz[xx][yy]=0 end if mirv==1 then panz[9-xx][yy]=panz[xx][yy] end if mirh==1 then panz[xx][9-yy]=panz[xx][yy] end if mirh==1 and mirv==1 then panz[9-xx][9-yy]=panz[xx][yy] end end tout="" sout="" for y=1,8 do for x=1,8 do tout=tout..string.format(panz[x][9-y]) sout=sout..string.format(panz[x][9-y]) end tout=tout.."\n" end if xx<=9 then output.clear() print(tout) end -- print(xx) -- print(yy) end