@Crumble Here’s a quick calculator I put together just to give you an example, so it’s still has bugs. Try calculations like
x * y =
x / y =
x + y =
x - y =
x ^ y =
x sin
x cos
…
displayMode(FULLSCREEN)
rectMode(CENTER)
function setup()
b1tab={}
table.insert(b1tab,button(100,600,100,50,"1"))
table.insert(b1tab,button(200,600,100,50,"2"))
table.insert(b1tab,button(300,600,100,50,"3"))
table.insert(b1tab,button(100,550,100,50,"4"))
table.insert(b1tab,button(200,550,100,50,"5"))
table.insert(b1tab,button(300,550,100,50,"6"))
table.insert(b1tab,button(100,500,100,50,"7"))
table.insert(b1tab,button(200,500,100,50,"8"))
table.insert(b1tab,button(300,500,100,50,"9"))
table.insert(b1tab,button(200,450,100,50,"0"))
table.insert(b1tab,button(100,450,100,50,"*"))
table.insert(b1tab,button(300,450,100,50,"+"))
table.insert(b1tab,button(100,400,100,50,"/"))
table.insert(b1tab,button(200,400,100,50,"^"))
table.insert(b1tab,button(300,400,100,50,"-"))
table.insert(b1tab,button(300,350,100,50,"="))
table.insert(b1tab,button(100,350,100,50,"sin"))
table.insert(b1tab,button(200,350,100,50,"cos"))
str=""
t1,t2=0,0
end
function draw()
background(40, 40, 50)
for a,b in pairs(b1tab) do
b:draw()
end
fill(255)
rect(200,650,300,50)
fill(255,0,0)
text(str,200,650)
end
function touched(t)
if t.state==BEGAN then
if done then
done=false
str=""
t1=0
t2=0
end
for a,b in pairs(b1tab) do
b:touched(t)
end
end
end
button=class()
function button:init(x,y,w,h,desc)
self.x=x
self.y=y
self.w=w
self.h=h
self.d=desc
end
function button:draw()
fill(255)
rect(self.x,self.y,self.w,self.h)
fill(255,0,0)
text(self.d,self.x,self.y)
end
function button:touched(t)
if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 then
if t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
if self.d=="sin" then
str=math.sin(math.rad(t2))
done=true
return
end
if self.d=="cos" then
str=math.cos(math.rad(t2))
done=true
return
end
if self.d=="*" or self.d=="^" or self.d=="/" or
self.d=="+" or self.d=="-" then
m=self.d
t1=t2
t2=""
str=str..self.d
return
end
if self.d== "=" then
if m=="*" then
str=t1*t2
end
if m== "^" then
str=t1^t2
end
if m== "/" then
str=t1/t2
end
if m== "+" then
str=t1+t2
end
if m== "-" then
str=t1-t2
end
done=true
return
end
if self.d>="0" and self.d<="9" then
str=str..self.d
t2=t2..self.d
end
end
end
end