Circle Calculator: Reposted

This is my circle calculator with some modifications to the previous version, please try it and leave me feedback on its usefulness, how easy it is to use, and ways to make it better.


-- 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", "Austin")
readProjectInfo("Description")
readProjectInfo("Author")
parameter.watch("Circumference")
parameter.watch("Diameter")
parameter.integer("CircleSize",1,1000)
parameter.watch("Radius")
parameter.watch("Area")
parameter.action("Clear Calculation Data", output.clear)
end
function draw()
background(67, 67, 67, 255)
textMode(CORNER)
textAlign(CENTER)
font("AmericanTypewriter-Light")
fontSize(25)
fill(255, 0, 37, 255)
text("Double Tap to Print Results", 10, HEIGHT-50)
fill(255, 255, 255, 255)
ellipseMode(CENTER)
ellipse( HEIGHT/2,WIDTH/2,CircleSize)
Diameter  = CircleSize
Circumference = math.pi * CircleSize
Radius = CircleSize/2
Area = math.pi * math.pow(Radius,2)
end
function touched(t)
if t.tapCount == 2 and t.state == ENDED then
print("-----------------")
print("Diameter: "..Diameter)
print("Area: "..Area)
print("Circumference: "..Circumference)
print("Radius: "..Radius)
print("Circle Calculator by: Austin W/CodeaNoob")
end
end

@CodeaNoob Interesting little program. Here’s some changes. Indentation and spaces between the functions make the code easier to read. Removeing lines of code that aren’t needed make the program smaller. Changing the ellipse() command to use WIDTH/2 as the x value and HEIGHT/2 as the y value allows it be use in portrait or landscape mode. Adding the default value (WIDTH) to parameter.integer eliminates a line of code (CircleSize=WIDTH). Displaying the circle information as the CircleSize changes eliminates having to double tap the screen and always shows the current information in the output area.

PS. Maybe you could add a line for sphere volume for a circle that size.


-- Circle Calculator
-- By: CodeaNoob
-- March 10th, 2013

function setup()
    saveProjectInfo("Description", "A Calculator to find Circumference, Diameter, and Area of a Circle")
    saveProjectInfo("Author", "Austin")
    readProjectInfo("Description")
    readProjectInfo("Author")
    parameter.integer("CircleSize",1,1000,WIDTH)
    hCircleSize=0
end

function draw()
    background(67, 67, 67, 255)
    fill(255, 255, 255, 255)
    ellipse( WIDTH/2,HEIGHT/2,CircleSize)
    Diameter = CircleSize
    Circumference = math.pi * CircleSize
    Radius = CircleSize/2
    Area = math.pi * math.pow(Radius,2)
    if hCircleSize~=CircleSize then
        printInfo()
        hCircleSize=CircleSize
    end
end

function printInfo()
    output.clear()
    print("Diameter: "..Diameter)
    print("Area: "..Area)
    print("Circumference: "..Circumference)
    print("Radius: "..Radius)
    print("Circle Calculator by: Austin W/CodeaNoob")
end

@dave1707, thanks for the feed back