修复fan背景坐标错误,整理代码提升性能

This commit is contained in:
MrZ626
2021-05-25 14:51:16 +08:00
parent 3d13c8ff2a
commit 6fa4cf17c7

View File

@@ -1,6 +1,11 @@
--UUZ's fan --UUZ's fan
local gc=love.graphics local gc=love.graphics
local polygon,ellipse=gc.polygon,gc.ellipse local gc_push,gc_pop,gc_clear,gc_origin=gc.push,gc.pop,gc.clear,gc.origin
local gc_translate=gc.translate
local gc_setColor,gc_setLineWidth=gc.setColor,gc.setLineWidth
local gc_line,gc_polygon=gc.line,gc.polygon
local gc_arc,gc_ellipse=gc.arc,gc.ellipse
local rnd=math.random local rnd=math.random
local max,min,sin=math.max,math.min,math.sin local max,min,sin=math.max,math.min,math.sin
local ins,rem=table.insert,table.remove local ins,rem=table.insert,table.remove
@@ -9,7 +14,7 @@ local back={}
local t local t
local fan,petal local fan,petal
function back.init() function back.init()
t=rnd(2600) t=0
fan=title_fan fan=title_fan
petal={} petal={}
end end
@@ -39,35 +44,33 @@ function back.update()
end end
end end
function back.draw() function back.draw()
gc.push('transform') gc_push('transform')
gc.translate(SCR.w/2,SCR.h/2+20*sin(t*.02)) gc.replaceTransform(SCR.xOy)
gc.scale(SCR.k) gc_translate(640,360+20*sin(t*.02))
gc.clear(.1,.1,.1) gc_clear(.1,.1,.1)
gc.setLineWidth(320) gc_setLineWidth(320)
gc.setColor(.3,.2,.3) gc_setColor(.3,.2,.3)
gc.arc('line','open',0,420,500,-.8*3.1416,-.2*3.1416) gc_arc('line','open',0,420,500,-.8*3.1416,-.2*3.1416)
gc.setLineWidth(4) gc_setLineWidth(4)
gc.setColor(.7,.5,.65) gc_setColor(.7,.5,.65)
gc.arc('line','open',0,420,660,-.799*3.1416,-.201*3.1416) gc_arc('line','open',0,420,660,-.799*3.1416,-.201*3.1416)
gc.arc('line','open',0,420,340,-.808*3.1416,-.192*3.1416) gc_arc('line','open',0,420,340,-.808*3.1416,-.192*3.1416)
gc.line(-281,224,-530,30.5) gc_line(-281,224,-530,30.5)
gc.line(281,224,530,30.5) gc_line(281,224,530,30.5)
gc.setLineWidth(6) gc_setLineWidth(6)
gc.setColor(.55,.5,.6) gc_setColor(.55,.5,.6)
for i=1,8 do for i=1,8 do gc_polygon('line',fan[i])end
polygon('line',fan[i])
end
gc.setLineWidth(2) gc_setLineWidth(2)
gc.setColor(.6,.3,.5) gc_setColor(.6,.3,.5)
gc.origin() gc_origin()
for i=1,#petal do for i=1,#petal do
local P=petal[i] local P=petal[i]
ellipse('fill',P.x,P.y,P.rx,P.ry) gc_ellipse('fill',P.x,P.y,P.rx,P.ry)
end end
gc.pop() gc_pop()
end end
function back.discard() function back.discard()
petal=nil petal=nil