Advertisement
Eliaseeg

Dibujar líneas y círculos

Apr 9th, 2014
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. -- Recordad cambiar los nombres de "Eliaseeg" por el suyo.
  2. -- Si queréis dibujar una línea abajo del else de la función eventMouse colocar "dibujarLinea", te debería quedar así:                 dibujarLinea(data[name].primerCheck,{x=xCursor,y=yCursor},1).
  3. -- Si queréis dibujar un círculo colocar "dibujarCirculo", que quedaría así: dibujarCirculo(data[name].primerCheck,{x=xCursor,y=yCursor},1)    
  4.      
  5. data={}
  6. data["Eliaseeg"]={
  7.         primerCheck=nil
  8. };
  9.  
  10. system.bindMouse("Eliaseeg",true)
  11. id=1
  12.  
  13. function dibujarLinea(punto1,punto2,res)
  14.         a=(punto1.y-punto2.y)/(punto1.x-punto2.x)
  15.         b=punto1.y-a*punto1.x
  16.         if(punto1.x>punto2.x) then punto1,punto2=punto2,punto1 end
  17.         for i=punto1.x,punto2.x,res do
  18.                 ui.addTextArea(id,"",nil,i,a*i+b, 1, 1, "0x2E9AFE", "0x2E9AFE")
  19.                 id=id+1
  20.         end
  21. end
  22.  
  23. function dibujarCirculo(point1,point2)
  24.         r=math.sqrt(math.pow((point1.x-point2.x),2)+math.pow((point1.y-point2.y),2))
  25.         res=1-r*math.pow(10,-2)
  26.         if(res<0.1)then res =0.1 end
  27.         for i=0,2*math.pi,res do
  28.                 ui.addTextArea(id,"",nil,point1.x+r*math.cos(i),point1.y+r*math.sin(i), 1, 1, "0x2E9AFE", "0x2E9AFE")
  29.                 id=id+1
  30.         end
  31. end
  32.  
  33. function eventMouse(name,xCursor,yCursor)
  34.         if(not data[name].primerCheck)then
  35.                 data[name].primerCheck={x=xCursor,y=yCursor}
  36.         else
  37.                 dibujarLinea(data[name].primerCheck,{x=xCursor,y=yCursor},1)    
  38.                 data[name].primerCheck = nil
  39.         end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement