0 Members and 1 Guest are viewing this topic.
----------block1------------- block1=class()bw,bh=80,70cc=20 ff=25 t1="start" t2="stop" tp=0.02st=1n=1/2.5-----st must =ff or ff≥st+1------function block1:init()endfunction block1:set()wbx,wby=platform.window:width(),platform.window:height()bx=wbx/2-bw/2by=wby/2-bh/2endfunction block1:setc1()block1:set()c1x,c1y,c1w,c1h=bx,by+bh/2-cc/2,bw,ccendfunction block1:setc2()block1:set()c2x,c2y,c2w,c2h=bx+bw/2-cc/2,by,cc,bhendfunction block1:paint(gc)gc:setColorRGB(150,200,100)block1:set()gc:fillRect(bx,by,bw,bh)-------c1------gc:setColorRGB(0,0,0)block1:setc1()gc:fillRect(c1x,c1y,c1w,c1h)-----c2-------gc:setColorRGB(0,0,0)block1:setc2()gc:fillRect(c2x,c2y,c2w,c2h)endfunction block1:timer()platform.window:invalidate()end--------mouse------Mouse=class()mx=0my=0function Mouse:init()endfunction Mouse:paint(gc)gc:setFont("sansserif","i",10)gc:drawString("MouseLocation : ( "..mx.." , "..my.." )",60,0,"top")endfunction on.mouseMove(x,y)mx=xmy=yendfunction Mouse:send() --Ox=mx end function Mouse:timer()platform.window:invalidate()end----------------------------[[function ST()if B1x<140 or B1x>171then st=1elseif B1x>140 and B1x<171 then st=1end end--]]-----------Steps----------function step1() if B1x==c2x-ff --and B2y==c1y then t1="start"endif B1x==c2x+ff then t1="stop"return step2() end --ST()B1x=B1x+st B2y=B1y-(ff^2-(B1x-B2x)^2)^0.5 --B2y=math.eval("round("..B2y..",0)")end function step2() if B1x==c2x+ff --and B2y==c1y then t2="start"endif B1x==c2x-ff then t2="stop" B1x=c2x-ff--timer.stop()return step1() end --ST()B1x=B1x-st B2y=B1y+(ff^2-(B1x-B2x)^2)^0.5--B2y=math.eval("round("..B2y..",0)")endB1=class()block1:setc1() block1:setc2()B1x,B1y,B2x,B2y=c2x-ff,c1y,c2x,c1yfunction B1:paint(gc)step1()gc:fillArc(B1x,B1y,cc,cc,0,360)gc:fillArc(B2x,B2y,cc,cc,0,360)endB2=class()block1:setc1() block1:setc2()function B2:paint(gc)step2()gc:fillArc(B1x,B1y,cc,cc,0,360)gc:fillArc(B2x,B2y,cc,cc,0,360)end-----------------------function on.paint(gc)block1():paint(gc)Mouse():paint(gc)gc:setColorRGB(255,255,255)if t1=="start" thenB1():paint(gc)endif t2=="start" thenB2():paint(gc)endgc:setColorRGB(0,0,0)gc:setFont("sansserif","i",10)gc:drawString(t1.." "..t2,0,0,"top")gc:drawString("( "..B1x.." , "..B1y.." )",100,199)gc:drawString(" ( "..B2x.." , "..B2y.." )",100,212)d=((B1x-B2x)^2+(B1y-B2y)^2)^0.5d=math.eval("iPart("..d..")")gc:drawString(d..st,100,180)-------o---------Mouse:send()--l=math.eval("linsolve("..B1y.."=k*"..B1x.."+b and "..B2y.." =k*"..B2x.."+b,{k,b})")Ox=(B2x*(1+n)-B1x)/nOy=(B2y*(1+n)-B1y)/ngc:fillArc(Ox,Oy,cc,cc,0,360)endfunction on.timer()timer.start(tp)block1():timer()Mouse():timer()platform.window:invalidate()endon.timer()
l'm leaning the lua. l want to make a prgm to draw the oval.