Calculadora en Ruby con Shoes

Iniciado por ANTRAX, Febrero 24, 2010, 04:16:07 PM

Tema anterior - Siguiente tema

0 Miembros y 2 Visitantes están viendo este tema.

Febrero 24, 2010, 04:16:07 PM Ultima modificación: Julio 31, 2014, 10:14:55 PM por Expermicid
La interfaz visual (hecha con Shoes) no esta muy alli pero algo es algo :P

Código: ruby
#Calculadora con funciones logar?tmicas y trigonom?tricas
#by Sh4van3
Shoes.app(:title=>"Calculadora", :width=>200, :height=> 300, :resizable=> false) do
stack :margin=>10 do
@box=edit_box(:width=> 150,:height=>30)
end
@r=""
@a=String.new
button("//", :width=>50) do
@[email protected]_f
@sq=Math.sqrt(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
button("**", :width=>50) do
@[email protected]_f
@sq=@a**2
@a=@sq
@[email protected]_s
@box.text=@sq
end
button("exp", :width=>50) do
@[email protected]_f
@sq=Math.exp(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
stack do
end
button("log", :width=>75) do
@[email protected]_f
@sq=Math.log(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
button("nep", :width=>75) do
@[email protected]_f
@sq=Math.log10(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
stack do
end
button "sin" do
@[email protected]_f
@sq=Math.sin(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
button "cos" do
@[email protected]_f
@sq=Math.cos(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
button "tan" do
@[email protected]_f
@sq=Math.tan(@a)
@a=@sq
@[email protected]_s
@box.text=@sq
end
stack do
end
button "1" do
@a<<"1"
@box.text= @a
end
button "2" do
@a<< "2"
@box.text=@a
end
button "3" do
@a<< "3"
@box.text=@a
end
button "+" do
case @r
when ""
@[email protected]_f
@a=""
@r="+"
when "+"
@r="+"
when "-"
@r="+"
when "x"
@r="+"
when "/"
@r="+"
end
end
stack do
end
button "4" do
@a<<"4"
@box.text=@a
end
button "5" do
@a<<"5"
@box.text=@a
end
button "6" do
@a<<"6"
@box.text=@a
end
button "-" do
case @r
when ""
@[email protected]_f
@a=""
@r="-"
when "-"
@r="-"
when "+"
@r="-"
when "x"
@r="-"
when "/"
@r="-"
end
end
stack do
end
button "7" do
@a<<"7"
@box.text=@a
end
button "8" do
@a<<"8"
@box.text=@a
end
button "9" do
@a<< "9"
@box.text=@a
end
button "x" do
case @r
when ""
@[email protected]_f
@a=""
@r="x"
when "+"
@r="x"
when "-"
@r="x"
when "x"
@r="x"
when "/"
@r="x"
end
end
stack do
end
button "0" do
@a<<"0"
@box.text=@a
end
button("=", :width=>75) do
case @r
when "+"
@[email protected]_f
@sol=@b+@a
@[email protected]_s
@box.text=@sol
@a=@sol
@b=""
when "-"
@[email protected]_f
@sol=@b-@a
@[email protected]_s
@box.text=@sol
@a=@sol
@b=""
when "x"
@[email protected]_f
@sol=@b*@a
@[email protected]_s
@box.text=@sol
@a=@sol
@b=""
when "/"
@[email protected]_f
@sol=@b/@a
@[email protected]_s
@box.text=@sol
@a=@sol
@b=""
end
end
button "/" do
case @r
when ""
@[email protected]_f
@a=""
@r="+"
when "+"
@r="+"
when "-"
@r="+"
when "x"
@r="+"
when "/"
@r="+"
end
end
stack do
end
button("DEL", :width=>150) do
@box.text=""
@a=""
@b=""
@sol=""
@sq=""
end
end