Advertisement
xerpi

Untitled

Apr 1st, 2011
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.65 KB | None | 0 0
  1. azul =  0xFFFF0000
  2. verde =  0xFF00FF00
  3. rojo =  0xFF0000FF
  4. blanco =  0xFFFFFFFF
  5. cian =  0xFFFFFF00
  6. magenta =  0xFF00FFFF
  7. amarillo =  0xFF00FFFF
  8. negro =  0xFF000000
  9. gris =  0xFF808080
  10. rosa =  0xFF8080FF
  11. violeta =  0xFF800080
  12. celeste =  0xFF80FFFF
  13. marron =  0xFF800000
  14. naranja =  0xFFFF8000
  15. lavanda =  0xFF8000FF
  16. turquesa =  0xFF00FF80
  17. oro =  0xFFBBBB20
  18.  
  19. dofile("teclado.lua")
  20.  
  21. xesigual= image.load("imagenes/xesigual.png")
  22. elevadoa2= image.load("imagenes/elevadoa2.png")
  23. raizmasmenos= image.load("imagenes/raizmasmenos.png")
  24. eqvacia= image.load("imagenes/eqvacia.png")
  25. fondo= image.load("imagenes/fondo.png")
  26.  
  27. xeq=50
  28. yeq=125
  29.  
  30. a= 4
  31. b= 3
  32. c= 9
  33. --[[° se hace con Alt+248
  34. ¹ se hace con Alt+251
  35. ² se hace con Alt+253
  36. ³ se hace con Alt+252
  37. ± se hace con alt+0177
  38. v  se hace con Alt+8730]]
  39.  
  40.  
  41. resultado1=nil
  42. resultado2=nil
  43.  
  44. squared=nil
  45.  
  46. function isinteger(number)
  47. if number > 0 then
  48.     if number - math.floor(number) == 0 then
  49.         return true
  50.     else return false
  51. end
  52. end
  53. if number < 0 then
  54.     if number + math.abs(math.floor(number)) == 0 then
  55.         return true
  56.     else return false
  57. end
  58. end
  59. if number == 0 then
  60.     return true
  61. end
  62. end
  63.  
  64.  
  65. while true do
  66. controls.read()
  67. fondo:blit(0,0)
  68.  
  69. squared = ((b^2)-(4*a*c))
  70.  
  71. if squared >=0 then
  72. resultado1 = (-(b) + math.sqrt(squared))/(2*a)
  73. resultado2 = (-(b) - math.sqrt(squared))/(2*a)
  74.  
  75. if isinteger(math.sqrt(squared)) then
  76. if not isinteger(resultado1) then
  77.     resultado1= (-(b) + math.sqrt(squared)).."/"..(2*a)
  78. end
  79. if not isinteger(resultado2) then
  80.     resultado2= (-(b) - math.sqrt(squared)).."/"..(2*a)
  81. end
  82.  
  83. end
  84.  
  85. if not isinteger(math.sqrt(squared)) then
  86.  
  87. resultado1 = "("..-(b).."+v"..squared..")".."/"..(2*a).." = "..((-(b) + math.sqrt(squared))/(2*a))
  88. resultado2 = "("..-(b).."-v"..squared..")".."/"..(2*a).." = "..((-(b) - math.sqrt(squared))/(2*a))
  89.  
  90. end
  91.  
  92. if resultado1 != resultado2 then
  93. screen.print(5,5,"Resultado 1:  "..resultado1,0.9,0xFFFF0000,0x0)
  94. screen.print(5,25,"Resultado 2:  "..resultado2,0.9,rojo,0x0)
  95. screen.print(5,45,"Radicando = "..squared,0.9,amarillo,0x0)
  96. screen.print(5,65,a.."x²+"..b.."x+"..c.."=0",0.9,verde,0x0)
  97. elseif resultado1 == resultado2 then
  98. screen.print(5,20,"Solo tiene una solución:  "..resultado1,0.9,0xFFFF0000,0x0)
  99. screen.print(5,45,"Radicando = "..squared,0.9,amarillo,0x0)
  100. screen.print(5,65,a.."x²+"..b.."x+"..c.."=0",0.9,verde,0x0)
  101. end
  102. end
  103.  
  104. if squared <0 then
  105. screen.print(5,25,"No tiene solución real",0.9,rojo,0x0)
  106. screen.print(5,45,"Radicando = "..squared,0.9,amarillo,0x0)
  107.  
  108. end
  109.  
  110. --screen.textwidth("",0.9)
  111. xesigual:blit(xeq,yeq)
  112.  
  113. draw.line(xeq+xesigual:width(),yeq+xesigual:height()/2,xeq+50+raizmasmenos:width()+screen.textwidth("-("..b..")        "..b.."-4*"..a.."*"..c.." ",0.9),yeq+xesigual:height()/2,negro)
  114.  
  115. raizmasmenos:blit(xeq+50+screen.textwidth("-("..b.." ",0.9),yeq-30)
  116. draw.line(xeq+50+raizmasmenos:width()+screen.textwidth("-("..b.." ",0.9),yeq-30,xeq+50+raizmasmenos:width()+screen.textwidth("-("..b..")        "..b.."-4*"..a.."*"..c.." ",0.9),yeq-30,negro)
  117. --screen.print(xeq+197,yeq+12,a,0.9,rojo,0x0)
  118.  
  119. screen.print(xeq+50-7,yeq-13,"-("..b..")        "..b,0.9,0xFFFF0000,0x0)
  120. elevadoa2:blit(xeq+50+screen.textwidth("-("..b..")        "..b,0.9)-3,yeq-25)
  121. screen.print(20+xeq+50-7+screen.textwidth("-("..b..")        "..b,0.9),yeq-13,"-4*",0.9,negro,0x0)
  122. screen.print(20+xeq+50-7+screen.textwidth("-("..b..")        "..b.."-4*",0.9),yeq-13,a,0.9,rojo,0x0)
  123. screen.print(20+xeq+50-7+screen.textwidth("-("..b..")        "..b.."-4*"..a,0.9),yeq-13,"*",0.9,negro,0x0)
  124. screen.print(20+xeq+50-7+screen.textwidth("-("..b..")        "..b.."-4*"..a.."*",0.9),yeq-13,c,0.9,verde,0x0)
  125. screen.print((xeq+50+raizmasmenos:width()+screen.textwidth("-("..b..")        "..b.."-4*"..a.."*"..c.." ",0.9))/2,yeq+15,"2*",0.9,negro,0x0)
  126. screen.print((xeq+50+raizmasmenos:width()+screen.textwidth("-("..b..")        "..b.."-4*"..a.."*"..c.." ",0.9))/2+screen.textwidth("2*",0.9),yeq+15,a,0.9,rojo,0x0)
  127.  
  128.  
  129. screen.print(20,200,"A:Triangulo = "..a,0.9,rojo,0x0)
  130. screen.print(20,240,"C:Cruz = "..b,0.9,verde,0x0)
  131. screen.print(20,220,"B:Cuadrado = "..c,0.9,azul,0x0)
  132.  
  133.  
  134. if controls.press("triangle") then
  135. a = tonumber(xkeyboard(480-peke.img:width(),272-peke.img:height(),240,165,a,"A: ",1))
  136. --os.osk("introduce el numero A",a,10,3,1)
  137. if a== nil then a = 0 end
  138. end
  139. if controls.press("square") or controls.press("circle") then
  140. b = tonumber(xkeyboard(480-peke.img:width(),272-peke.img:height(),240,165,b,"B: ",1))
  141. if b== nil then b = 0 end
  142. end
  143. if controls.press("cross") then
  144. c = tonumber(xkeyboard(480-peke.img:width(),272-peke.img:height(),240,165,c,"C: ",1))
  145. if c== nil then c = 0 end
  146. end
  147.  
  148. if controls.press("select") then
  149.     xerpi()
  150. end
  151.  
  152. screen.flip()
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement