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 aInput, bInput, cInput;
let tex, tex2

function setup() {
  createCanvas(600, 600);

	createP('a')
  aInput = createSlider(-0.5, 0.5, 0.01, 0.0005);

	createP('b')
  bInput = createSlider(-10, 10, 0, 0.25);

	createP('c')
  cInput = createSlider(-200, 200, 0, 1);
  //frameRate(1)
  
  aInput.position(650, 10)
  bInput.position(650, 50)
  cInput.position(650, 90)
  
  tex = createP();
  tex.style('font-size', '18px');
  tex.position(25, 425);
  tex2 = createP();
  tex2.style('font-size', '18px');
  tex2.position(25, 390);
}

function draw() {

  //Setup graph
  background("black");
  Strive.translate(300, 300);
  Strive.scale(1, -1);
  //Strive.drawTickAxes();
  
  //axis
  stroke('#039be5');
  strokeWeight(3)
  line(-300, 0, 300, 0);
  line(0, -300, 0, 300);
  for(let i = -300; i < 300; i = i + 50) {
    stroke('#039be5');
    strokeWeight(3)
    //x axis
    line(i, -5, i, 5);
    //y axis
    line(-5, i, 5, i);
 
    noStroke()
    fill("white")
    striveText(`${i}`, i, 8);
    striveText(`${i}`, 8, i);
  }

  //get values of equation
  a = aInput.value();
  b = bInput.value();
  c = cInput.value();

  //graph the line
  stroke("white");

  let step = 1
  for (let x1 = -300; x1 < 300; x1=x1+step) {
    let x2 = x1 + step
    let y1 = f(x1)
    let y2 = f(x2)
    line(x1,y1,x2,y2)
  }
  
	// Plotting the x intercepts
  noStroke()
  fill("orange")
  let r1 = root1(a,b,c)
  let r2 = root2(a,b,c)
  circle(r1, f(r1), 20);
  circle(r2, f(r1), 20);
  
  noStroke()
  // Plotting the y intercept
  fill('red')
  circle(0, c, 20);

	// Printing the values of a,b and c
  fill('cyan')
  noStroke()
  //striveText(
	//	`a: ${a.toFixed(2)}  b: ${b.toFixed(2)}  c: ${c.toFixed(2)}`, -195, -30
	//)
  
  // Plotting the vertex
  fill('magenta')
  let vX = vertexX(a,b,c)
  let vY = f(vX)
  circle(vX, vY, 15);
  
	// Printing the solutions
  let discriminant = b**2-4*a*c
  
  fill('white')
  if(discriminant > 0) {
    //striveText(`Two solutions: ${r1.toFixed()}, ${r2.toFixed()}`, -285, -100);
    katex.render(`\\sf\\textcolor{white}{Two\\space{}Solutions: ${r1.toFixed()}, ${r2.toFixed()}}`, tex2.elt)
  } else if(discriminant == 0) {
    //r1 = r1.toFixed()
    //striveText(`Unique solution: ${r1.toFixed()}`, -285, -100);
    katex.render(`\\sf\\textcolor{white}{Unique\\space{}Solution: ${r1.toFixed()}}`, tex2.elt)
  } else {
    //striveText("No solution", -285, -100);
    katex.render(`\\sf\\textcolor{white}{No\\space{}Solution}`, tex2.elt)
  }
  
  // Printing the y-intercept
  fill('red')
  //striveText("Y Intercept: (0, " + c.toFixed(2) + ")", -195, -70);
  
  // Printing the vertex
  // fill('magenta')
  // striveText(`Vertex:(${vX.toFixed()},${vY.toFixed()})`, -195, -90)
  
  // Printing the various forms of equations
  
  fill('white')
  // y = ax^2 + bx + c
  let eqn1 = `y = ${a.toFixed(2)}x^2 + ${b.toFixed(2)}x + ${c.toFixed(0)}`

  // y = a(x-r1)(x-r2)
  let eqn2 = `y = ${a.toFixed(2)}(x - ${r1.toFixed(2)})(x - ${r2.toFixed(2)})`

  // y = a(x-h)^2 + k
  let eqn3 = `y = ${a.toFixed(2)}(x - ${vX.toFixed(2)})^2 + ${vY.toFixed(2)}`

  //striveText(`Equation: ` + eqn1, -285, -80);
  // striveText(`Equation: ` + eqn2, -195, -130)
  // striveText(`Equation: ` + eqn3, -195, -150)
  
  a = a.toFixed(2)
  katex.render(`\\sf\\textcolor{white}{y = ${a}x^2 + ${b}x + ${c}}`, tex.elt)
  
  textSize(18)
}

function f(x) {
  let y = a * x ** 2 + b * x + c
  return y
}

function root1(a,b,c) {
  let r1 = (-b + Math.sqrt(b ** 2 - 4 * a * c)) / (2 * a);
  return r1;
}

function root2(a,b,c) {
  let r2 = (-b - Math.sqrt(b ** 2 - 4 * a * c)) / (2 * a);
  return r2;
}

function vertexX(a, b) {
	let vX = -b / (2 * a);
  return vX;
}

function striveText(str,xpos,ypos){
  push()
  scale(1, -1);
  text(str,xpos,-ypos)
  pop()
}
              
            
!
999px

Console