I was sitting in Math class, punching numbers into my clculator to get the Area, Diameter, Circumference, etc., when i came up with the idea for this Calculator. Just adjust the Circle Size to the desired size, and tap twice to calculate, its saved me lots of time! I plan
on adding lots more
-- Circle Calculator
-- By: CodeaNoob
-- March 10th, 2013
-- Use this function to perform your initial
CircleSize = WIDTH
function setup()
saveProjectInfo("Description", "A Calculator to find Circumference,Diameter, and Area of a Circle")
saveProjectInfo("Author", "CodeaNoob")
readProjectInfo("Description")
readProjectInfo("Author")
parameter.watch("Circumference")
parameter.watch("Diameter")
parameter.integer("CircleSize",1,999)
parameter.watch("Radius")
parameter.watch("Area")
end
-- This function gets called once every frame
function draw()
background(67, 67, 67, 255)
textMode(CORNER)
textAlign(CENTER)
font("AmericanTypewriter-Light")
fontSize(25)
fill(0, 0, 0, 255)
text("Drag to Calculate", 10, HEIGHT-50)
-- This sets a dark background color
fill(255, 255, 255, 255)
ellipseMode(CORNER)
ellipse( 100,100,CircleSize)
Diameter = CircleSize
Circumference = math.pi * CircleSize/2
Radius = CircleSize/2
Area = math.pi * Radius*Radius
end
-- This sets the line thickness
-- Do your drawing here
CodeaNoob, if you need some ideas to improve this program and perhaps learn more about Codea:
a1) Why double tap? Make calculations a live update.
a2) CircleSize is the same as the diameter, please make it obsolete, especially as the “size of a circle” is quite ambiguous. Will almost automatically be a result of solving a1.
b) Make it a bit more outstanding by adjusting the circle’s size by touching the screen and setting the radius to your finger’s position. This assumes you already know (or learn about) the circle equation.
Here’s some simple additions that add touch functionality
--# Main
-- Circle Calculator
-- By: Codea Noob (updated by edat44)
-- March 10th, 2013
-- Use this function to perform your initial
function setup()
saveProjectInfo("Description", "A Calculator to find Circumference,Diameter, and Area of a Circle")
saveProjectInfo("Author", "CodeaNoob")
readProjectInfo("Description")
readProjectInfo("Author")
parameter.watch("Circumference")
parameter.watch("Diameter")
parameter.number("Radius", 1, 350, 100) -- set Radius to 100 to start with a min value of 1, and
-- a max value of 350
parameter.watch("Area")
end
-- This function gets called once every frame
function draw()
Diameter = Radius*2 -- Set all values based off of Radius
Circumference = math.pi * Radius
Area = math.pi * math.pow(Radius, 2) -- A slightly more formal way to write Radius times itself
background(67, 67, 67, 255)
textMode(CENTER) -- Center mode is easier to allign in the middle
textAlign(CENTER)
font("AmericanTypewriter-Light")
fontSize(25)
fill(0, 0, 0, 255)
text("Drag to Calculate", WIDTH/2, HEIGHT-50)
fill(255, 255, 255, 255)
ellipseMode(RADIUS)
ellipse(WIDTH/2, HEIGHT/2, Radius) -- Draw circle with the Radius
end
function touched(t)
Radius = math.min(vec2(WIDTH/2, HEIGHT/2):dist(vec2(t.x, t.y)), 350)
--adjust cirlce size to the touch's distance from the circle'center
end
The circle can be updated by either physically dimensioning the circle on the screen, or by using the parameter slider to get a slightly more accurate dimension