Drawing Triangle Help!

Im working on a Calculator that can determine the Hypotanuse length and the base and Height of a triangle simply by adjusting the values, but im trying to get it so the line adapts to a parameter.integer input, Can anyone make it work?

Height = TriangleHeight
Base = TriangleBase
Base = 100
Height = 100
Hypotanuse = Base/2*Base/2+Height*Height
Area = Base*Height/2
function setup()
saveProjectInfo("Description", "A Calculator that Finds The Hypotanuse and Area of a Triangle")
readProjectInfo("Description")
parameter.watch("Base")
parameter.watch("Height")
parameter.watch("Hypotanuse")
parameter.number("Base",1,99,Base)
parameter.integer("Height",0,99,Height)
parameter.action("Clear Calculations", output.clear)
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color 
spriteMode(CENTER)
sprite("Cargo Bot:Opening Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
stroke(0, 0, 0, 255)
line(Base,Height)
-- This sets the line thickness
strokeWidth(2)
-- Do your drawing here
fill(255, 255, 255, 255)
textMode(CORNER)
textAlign(CENTER)
font("AmericanTypewriter-Light")
fontSize(25)
text("Double Tap to Calculate", 10, HEIGHT-50)
pushMatrix()
lineCapMode(ROUND)
strokeWidth(8)
stroke(255, 255, 255, 255)
smooth()
noFill()
line(Base, Base, Base, Base)
line(Height, Height, Height, Height)

popMatrix()
end
function touched(touch)
if touch.tapCount == 2 and touch.state == ENDED then
print("--------------")
print("Base: "..Base)
print("Height: "..Height)
print("Hypotanuse: "..Hypotanuse)
print("Calculations are in Centimeters, Assuming the numbers are also Centimeters")
end 
end

2 things:

  1. You dont need to declare a parameter.watch if you already have that same variable in another parameter
  2. Your not drawing the line correctly! The line function takes four parameters: x1, x2, y1, y2.
    To draw the line correctly, you need to identify a starting point where the base and height lines intersect (I would reccomend the middle of the screen) Here’s one way of going about doing that:
function draw()
   --Add whatever styles you want here
   translate(WIDTH/2, HEIGHT/2) --Moves the drawing of all graphics to the middle of the screen
   line(0, 0, Base, 0) -- Line for the base
   line(0, 0, 0, Height) -- Line for the height
   line(Base, 0, 0, Height) -- Line for the Hypotanuse
end

But how come the parameter.number() isnt showing up in the parameters?

CodeaNoob

I don’t think you can use parameter.watch and parameter.number on the same thing.

I think the below is what you’re after.

Also, “hypotenuse” has an e in it, not a. I would recommend fixing spelling


--# Main
Height = TriangleHeight
Base = TriangleBase
Base = 100
Height = 100
Hypotanuse = Base/2*Base/2+Height*Height
Area = Base*Height/2

function setup()
    saveProjectInfo("Description", "A Calculator that Finds The Hypotanuse and Area of a Triangle")
    readProjectInfo("Description")
    --parameter.watch("Base")
    --parameter.watch("Height")
    parameter.watch("Hypotanuse")
    parameter.integer("Base", 1, 300, Base)
    parameter.integer("Height", 0, 300, Height)
    parameter.action("Clear Calculations", output.clear)
end

-- This function gets called once every frame
function draw()
    -- Calculate Hypotenuse
    Hypotanuse = math.sqrt(Base*Base + Height*Height)
    
    -- This sets a dark background color 
    spriteMode(CENTER)
    sprite("Cargo Bot:Opening Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
    stroke(0, 0, 0, 255)
    
    -- This sets the line thickness
    strokeWidth(2)
    
    -- Do your drawing here
    fill(255, 255, 255, 255)
    textMode(CORNER)
    textAlign(CENTER)
    font("AmericanTypewriter-Light")
    fontSize(25)
    text("Double Tap to Calculate", 10, HEIGHT-50)
    
    pushMatrix()
    translate(WIDTH/2,HEIGHT/2)
    lineCapMode(ROUND)
    strokeWidth(8)
    stroke(255, 255, 255, 255)
    smooth()
    noFill()
    
    -- Draw hypontenuse
    line(0, 0, Base, Height)
    
    -- Draw a
    line(0, 0, Base, 0)
    
    -- Draw b
    line(Base, Height, Base, 0)
    popMatrix()
end

function touched(touch)
    if touch.tapCount == 2 and touch.state == ENDED then
        
        print("--------------")
        print("Base: "..Base)
        print("Height: "..Height)
        print("Hypotanuse: "..Hypotanuse)
        print("Calculations are in Centimeters, Assuming the numbers are also Centimeters")
   end 
end