更好用的自定义绘图交互
This commit is contained in:
@@ -9,9 +9,11 @@ local FIELD=FIELD
|
|||||||
local scene={}
|
local scene={}
|
||||||
|
|
||||||
local sure
|
local sure
|
||||||
local penColor--Pen color
|
local keyHold
|
||||||
local penMode--Pen mode (false=unavailable, else=mouse button)
|
local penType--Color, air, or smart
|
||||||
local penX,penY--Pen position
|
local penMode
|
||||||
|
local penPath={}
|
||||||
|
local penX,penY
|
||||||
local demo--If show x
|
local demo--If show x
|
||||||
local page
|
local page
|
||||||
|
|
||||||
@@ -52,60 +54,72 @@ local minoPosCode={
|
|||||||
[3]=28,[33]=28,--I2
|
[3]=28,[33]=28,--I2
|
||||||
[1]=29,--O1
|
[1]=29,--O1
|
||||||
}
|
}
|
||||||
local SPmode
|
local function pTouch(x,y)
|
||||||
local SPlist={}--Smart pen path list
|
if not keyHold then return end
|
||||||
local function SPpath(x,y)
|
for i=1,#penPath do
|
||||||
if not penMode then return end
|
if x==penPath[i][1]and y==penPath[i][2]then
|
||||||
for i=1,#SPlist do
|
|
||||||
if x==SPlist[i][1]and y==SPlist[i][2]then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ins(SPlist,{x,y})
|
if #penPath==0 then
|
||||||
if #SPlist==1 then
|
penMode=
|
||||||
SPmode=FIELD[page][y][x]==0 and 0 or 1
|
penType>0 and(FIELD[page][y][x]~=penType and 0 or 1)or
|
||||||
|
penType==0 and 1 or
|
||||||
|
penType==-1 and 0 or
|
||||||
|
penType==-2 and (FIELD[page][y][x]<=0 and 0 or 1)
|
||||||
end
|
end
|
||||||
|
ins(penPath,{x,y})
|
||||||
end
|
end
|
||||||
local function SPdraw()
|
local function pDraw()
|
||||||
local l=#SPlist
|
local l=#penPath
|
||||||
if l==0 then return end
|
if l==0 then return end
|
||||||
|
|
||||||
local C--pen color
|
local C--Color
|
||||||
if SPmode==0 then
|
if keyHold==1 then
|
||||||
if l<=5 then
|
if penMode==0 then
|
||||||
local sum=0
|
if penType==-2 then
|
||||||
local x,y={},{}
|
if l<=5 then
|
||||||
for i=1,l do
|
local sum=0
|
||||||
ins(x,SPlist[i][1])
|
local x,y={},{}
|
||||||
ins(y,SPlist[i][2])
|
for i=1,l do
|
||||||
end
|
ins(x,penPath[i][1])
|
||||||
local minY,minX=min(unpack(y)),min(unpack(x))
|
ins(y,penPath[i][2])
|
||||||
for i=1,#y do
|
end
|
||||||
sum=sum+2^((11-(y[i]-minY))*(y[i]-minY)/2+(x[i]-minX))
|
local minY,minX=min(unpack(y)),min(unpack(x))
|
||||||
end
|
for i=1,#y do
|
||||||
if minoPosCode[sum]then
|
sum=sum+2^((11-(y[i]-minY))*(y[i]-minY)/2+(x[i]-minX))
|
||||||
C=SETTING.skin[minoPosCode[sum]]
|
end
|
||||||
|
if minoPosCode[sum]then
|
||||||
|
C=SETTING.skin[minoPosCode[sum]]
|
||||||
|
end
|
||||||
|
else
|
||||||
|
C=20
|
||||||
|
end
|
||||||
|
else
|
||||||
|
C=penType
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
C=20
|
C=0
|
||||||
end
|
end
|
||||||
elseif SPmode==1 then
|
elseif keyHold==2 then
|
||||||
|
C=-1
|
||||||
|
elseif keyHold==3 then
|
||||||
C=0
|
C=0
|
||||||
end
|
end
|
||||||
|
|
||||||
if C then
|
if C then
|
||||||
for i=1,l do
|
for i=1,l do
|
||||||
FIELD[page][SPlist[i][2]][SPlist[i][1]]=C
|
FIELD[page][penPath[i][2]][penPath[i][1]]=C
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
SPlist={}
|
penPath={}
|
||||||
SPmode=0
|
penMode=0
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.sceneInit()
|
function scene.sceneInit()
|
||||||
sure=0
|
sure=0
|
||||||
penColor=-2
|
keyHold=false
|
||||||
penMode=false
|
penType,penMode=-2,0
|
||||||
penX,penY=1,1
|
penX,penY=1,1
|
||||||
demo=false
|
demo=false
|
||||||
page=1
|
page=1
|
||||||
@@ -115,44 +129,30 @@ function scene.mouseMove(x,y)
|
|||||||
local sx,sy=int((x-200)/30)+1,20-int((y-60)/30)
|
local sx,sy=int((x-200)/30)+1,20-int((y-60)/30)
|
||||||
if sx>=1 and sx<=10 and sy>=1 and sy<=20 then
|
if sx>=1 and sx<=10 and sy>=1 and sy<=20 then
|
||||||
penX,penY=sx,sy
|
penX,penY=sx,sy
|
||||||
if penMode then
|
if keyHold then pTouch(sx,sy)end
|
||||||
if penColor==-2 and penMode==1 then
|
|
||||||
SPpath(sx,sy)
|
|
||||||
else
|
|
||||||
FIELD[page][sy][sx]=
|
|
||||||
penMode==1 and penColor or
|
|
||||||
penMode==2 and -1 or
|
|
||||||
-- penMode==3 and 0
|
|
||||||
0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
penX,penY=nil
|
penX,penY=nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.mouseDown(x,y,k)
|
function scene.mouseDown(x,y,k)
|
||||||
if not penMode then
|
if not keyHold then
|
||||||
penMode=k
|
keyHold=k
|
||||||
elseif penMode~=k then
|
elseif keyHold~=k then
|
||||||
penMode=false
|
keyHold=false
|
||||||
if penColor==-2 then
|
penPath={}
|
||||||
SPlist={}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
scene.mouseMove(x,y)
|
scene.mouseMove(x,y)
|
||||||
end
|
end
|
||||||
function scene.mouseUp(_,_,k)
|
function scene.mouseUp(_,_,k)
|
||||||
if penMode==k then
|
if keyHold==k then
|
||||||
penMode=false
|
pDraw()
|
||||||
if penColor==-2 then
|
keyHold=false
|
||||||
SPdraw()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function scene.wheelMoved(_,y)
|
function scene.wheelMoved(_,y)
|
||||||
if penColor>0 then
|
if penType>0 then
|
||||||
penColor=(penColor+(y<0 and 1 or -1)-1)%24+1
|
penType=(penType+(y<0 and 1 or -1)-1)%24+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.touchDown(x,y)scene.mouseDown(x,y,1)end
|
function scene.touchDown(x,y)scene.mouseDown(x,y,1)end
|
||||||
@@ -176,12 +176,8 @@ function scene.keyDown(key)
|
|||||||
end
|
end
|
||||||
elseif key=="space"then
|
elseif key=="space"then
|
||||||
if penX and penY then
|
if penX and penY then
|
||||||
penMode=1
|
keyHold=1
|
||||||
if penColor==-2 then
|
pTouch(penX,penY)
|
||||||
SPpath(penX,penY)
|
|
||||||
else
|
|
||||||
FIELD[page][penY][penX]=penColor
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
elseif key=="delete"then
|
elseif key=="delete"then
|
||||||
if sure>20 then
|
if sure>20 then
|
||||||
@@ -248,17 +244,20 @@ function scene.keyDown(key)
|
|||||||
page=min(page+1,#FIELD)
|
page=min(page+1,#FIELD)
|
||||||
end
|
end
|
||||||
elseif key=="escape"then
|
elseif key=="escape"then
|
||||||
SCN.back()
|
if keyHold then
|
||||||
|
keyHold=false
|
||||||
|
penPath={}
|
||||||
|
else
|
||||||
|
SCN.back()
|
||||||
|
end
|
||||||
else
|
else
|
||||||
penColor=penKey[key]or penColor
|
penType=penKey[key]or penType
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function scene.keyUp(key)
|
function scene.keyUp(key)
|
||||||
if key=="space"then
|
if key=="space"then
|
||||||
if penColor==-2 then
|
pDraw()
|
||||||
SPdraw()
|
keyHold=false
|
||||||
end
|
|
||||||
penMode=false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -295,10 +294,10 @@ function scene.draw()
|
|||||||
--Draw pen
|
--Draw pen
|
||||||
if penX and penY then
|
if penX and penY then
|
||||||
local x,y=30*penX,600-30*penY
|
local x,y=30*penX,600-30*penY
|
||||||
if penMode==1 or penMode==2 then
|
if keyHold==1 or keyHold==2 then
|
||||||
gc.setLineWidth(5)
|
gc.setLineWidth(5)
|
||||||
gc.rectangle("line",x-30,y,30,30,4)
|
gc.rectangle("line",x-30,y,30,30,4)
|
||||||
elseif penMode==3 then
|
elseif keyHold==3 then
|
||||||
gc.setLineWidth(3)
|
gc.setLineWidth(3)
|
||||||
gc.line(x-15,y,x-30,y+15)
|
gc.line(x-15,y,x-30,y+15)
|
||||||
gc.line(x,y,x-30,y+30)
|
gc.line(x,y,x-30,y+30)
|
||||||
@@ -311,21 +310,51 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--Draw smart pen path
|
--Draw smart pen path
|
||||||
if #SPlist>0 then
|
if #penPath>0 then
|
||||||
gc.setLineWidth(4)
|
gc.setLineWidth(4)
|
||||||
if SPmode==0 then
|
if keyHold==1 then
|
||||||
if #SPlist<=5 then
|
if penMode==0 then
|
||||||
gc.setColor(COLOR.rainbow_light(TIME()*6.2))
|
if penType==-2 then
|
||||||
|
if #penPath<=5 then
|
||||||
|
gc.setColor(COLOR.rainbow_light(TIME()*6.2))
|
||||||
|
else
|
||||||
|
gc.setColor(.9,.9,.9,.7+.2*math.sin(TIME()*12.6))
|
||||||
|
end
|
||||||
|
for i=1,#penPath do
|
||||||
|
gc.rectangle("line",30*penPath[i][1]-30+2,600-30*penPath[i][2]+2,30-4,30-4,3)
|
||||||
|
end
|
||||||
|
elseif penType==-1 then
|
||||||
|
gc.setColor(1,1,0,.7+.3*math.sin(TIME()*12.6))
|
||||||
|
for i=1,#penPath do
|
||||||
|
gc.draw(cross,30*penPath[i][1]-30,600-30*penPath[i][2])
|
||||||
|
end
|
||||||
|
elseif penType==0 then
|
||||||
|
gc.setColor(1,0,0)
|
||||||
|
for i=1,#penPath do
|
||||||
|
gc.draw(cross,30*penPath[i][1]-30+math.random(-1,1),600-30*penPath[i][2]+math.random(-1,1))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
local c=minoColor[penType]
|
||||||
|
gc.setColor(c[1],c[2],c[3],.7+.2*math.sin(TIME()*12.6))
|
||||||
|
for i=1,#penPath do
|
||||||
|
gc.rectangle("line",30*penPath[i][1]-30+2,600-30*penPath[i][2]+2,30-4,30-4,3)
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
gc.setColor(.9,.9,.9,.7+.2*math.sin(TIME()*12.6))
|
gc.setColor(1,0,0)
|
||||||
|
for i=1,#penPath do
|
||||||
|
gc.draw(cross,30*penPath[i][1]-30+math.random(-1,1),600-30*penPath[i][2]+math.random(-1,1))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
for i=1,#SPlist do
|
elseif keyHold==2 then
|
||||||
gc.rectangle("line",30*SPlist[i][1]-30+2,600-30*SPlist[i][2]+2,30-4,30-4,3)
|
gc.setColor(1,1,0,.7+.3*math.sin(TIME()*12.6))
|
||||||
|
for i=1,#penPath do
|
||||||
|
gc.draw(cross,30*penPath[i][1]-30,600-30*penPath[i][2])
|
||||||
end
|
end
|
||||||
else
|
elseif keyHold==3 then
|
||||||
gc.setColor(1,0,0)
|
gc.setColor(1,0,0)
|
||||||
for i=1,#SPlist do
|
for i=1,#penPath do
|
||||||
gc.draw(cross,30*SPlist[i][1]-30+math.random(-1,1),600-30*SPlist[i][2]+math.random(-1,1))
|
gc.draw(cross,30*penPath[i][1]-30+math.random(-1,1),600-30*penPath[i][2]+math.random(-1,1))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -346,21 +375,21 @@ function scene.draw()
|
|||||||
gc.line(52,5,75,35)
|
gc.line(52,5,75,35)
|
||||||
gc.line(75,5,52,35)
|
gc.line(75,5,52,35)
|
||||||
--Left mouse button
|
--Left mouse button
|
||||||
if penColor>0 then
|
if penType>0 then
|
||||||
gc.setColor(minoColor[penColor])
|
gc.setColor(minoColor[penType])
|
||||||
gc.rectangle("fill",5,5,23,30)
|
gc.rectangle("fill",5,5,23,30)
|
||||||
elseif penColor==-1 then
|
elseif penType==-1 then
|
||||||
gc.line(5,5,28,35)
|
gc.line(5,5,28,35)
|
||||||
gc.line(28,5,5,35)
|
gc.line(28,5,5,35)
|
||||||
elseif penColor==-2 then
|
elseif penType==-2 then
|
||||||
if SPmode==1 then
|
if penMode==0 then
|
||||||
gc.setColor(1,0,0)
|
|
||||||
gc.line(5,5,28,35)
|
|
||||||
gc.line(28,5,5,35)
|
|
||||||
else
|
|
||||||
gc.setLineWidth(13)
|
gc.setLineWidth(13)
|
||||||
gc.setColor(COLOR.rainbow(TIME()*12.6))
|
gc.setColor(COLOR.rainbow(TIME()*12.6))
|
||||||
gc.rectangle("fill",5,5,23,30)
|
gc.rectangle("fill",5,5,23,30)
|
||||||
|
else
|
||||||
|
gc.setColor(1,0,0)
|
||||||
|
gc.line(5,5,28,35)
|
||||||
|
gc.line(28,5,5,35)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--Draw mouse
|
--Draw mouse
|
||||||
@@ -392,7 +421,7 @@ function scene.draw()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function setPen(i)return function()penColor=i end end
|
local function setPen(i)return function()penType=i end end
|
||||||
scene.widgetList={
|
scene.widgetList={
|
||||||
WIDGET.newText{name="title", x=1020,y=5,font=70,align="R"},
|
WIDGET.newText{name="title", x=1020,y=5,font=70,align="R"},
|
||||||
WIDGET.newText{name="subTitle", x=1030,y=50,font=35,align="L",color="grey"},
|
WIDGET.newText{name="subTitle", x=1030,y=50,font=35,align="L",color="grey"},
|
||||||
|
|||||||
Reference in New Issue
Block a user