Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.css" integrity="sha384-Um5gpz1odJg5Z4HAmzPtgZKdTBHZdw8S29IecapCSB31ligYPhHQZMIlWLYQGVoc" crossorigin="anonymous">

    <!-- The loading of KaTeX is deferred to speed up page rendering -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/katex.min.js" integrity="sha384-YNHdsYkH6gMx9y3mRkmcJ2mFUjTd0qNQQvY9VYZgQd7DcN7env35GzlmFaZ23JGp" crossorigin="anonymous"></script>

    <!-- To automatically render math in text elements, include the auto-render extension: -->
    <script defer src="https://cdn.jsdelivr.net/npm/katex@0.13.11/dist/contrib/auto-render.min.js" integrity="sha384-vZTG03m+2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl" crossorigin="anonymous"
        onload="renderMathInElement(document.body);"></script>
  </head>
              
            
!

CSS

              
                
              
            
!

JS

              
                let tex
let p1
let p2


function setup() {
	createCanvas(window.innerWidth, window.innerHeight)
	p1 = Strive.createMovableCircle(100, 100, 10)
  p2 = Strive.createMovableCircle(250, 200, 10)
  
  tex = createP();
  tex.style('font-size', '18px');
  tex.position(200, 520);
}


function draw() {
	background("black")
	//Strive.drawTickAxes()

	p1.draw()
  p2.draw()
  
  stroke("yellow")
  strokeWeight(5)
  line(p1.x,p1.y,p2.x,p2.y)
  
  let p3x = p1.x
  let p3y = p2.y
  noFill()
  triangle(p1.x,p1.y,p2.x,p2.y,p3x,p3y)
  
  let width = abs(p2.x-p1.x)
  let height = abs(p2.y-p1.y)
  
  let widthXPos = (p1.x + p2.x)/2 
  let widthYPos = p3y
  
  let heightXPos = p3x
  let heightYPos = (p1.y+p2.y)/2
  
  
  
  stroke("white")
  textSize(18)
  strokeWeight(2)
  //text(height, widthXPos, widthYPos)
  //text(width, heightXPos, heightYPos)
  
  
  fill("green")
  rect(p1.x-height, p1.y, height,height)
  fill("blue")
  rect(p3x,p3y,width,width)
  
  let areaOfHypotonuse = width**2+height**2
  let hypotonuse = round(Math.sqrt(areaOfHypotonuse),3)
  let hypXPos = (p1.x+p2.x)/2
  let hypYPos = (p1.y+p2.y)/2
  //text(hypotonuse,hypXPos,hypYPos)
  
  /**
  fill("green")
  let spacing = 16
  rect(100,650, height,height)
  
  let plusXPos = 100+height+spacing
  text("+", plusXPos, 650+height/2)
  
  fill("yellow")
  let yellowRectXPos = plusXPos+spacing+spacing
  rect(yellowRectXPos,650,width,width)
  
  fill("red")
  let equalsXPos = yellowRectXPos+width+spacing
  text("=", equalsXPos, 650+height/2)
  rect(equalsXPos+spacing+spacing,650, hypotonuse,hypotonuse)
  */
  
  let rotateAngle = acos(height/hypotonuse);
  translate(p1.x, p1.y)
  rotate(-rotateAngle);
  translate(-p1.x, -p1.y);
  fill("red")
  rect(p1.x, p1.y, hypotonuse, hypotonuse);
  
  translate(p1.x, p1.y);
  rotate(rotateAngle)
  translate(-p1.x, -p1.y);

  fill("white");
  //noFill()
  noStroke()
  //stroke("white")
  textSize(18)
  strokeWeight(1)
  text(width, widthXPos-10, widthYPos+25);
  text(height, heightXPos-35, heightYPos);
  text(hypotonuse, hypXPos, hypYPos-10);
  
  katex.render(`\\sf\\textcolor{white}{${hypotonuse}^2 = ${height}^2 + ${width}^2}`, tex.elt)
  
  //katex.render(`\\rm\\textcolor{white}{^2 = \\ ^2}`, tex.elt)
}


// Distance formula
function getDistance(p1x, p1y, p2x, p2y) {
	return round(sqrt((p1y - p2y) ** 2 + (p1x - p2x) ** 2), 2)
}


//Midpoint Formula
function getMid(p1, p2) {
	return (p1 + p2) / 2
}


              
            
!
999px

Console