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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <script>
/*
This file contains functions for drawing 2d primitives with a handy sketchy look in p5.js.

Author: Janneck Wullschleger in 07/2016
Web: http://itsjw.de
Mail: jw@itsjw.de

Updated: 24.02.2017 to use with a reference to the p5 instance.
Just put it in as param to the constructor.

Much of the source code is taken from the handy library for processing,
written by Jo Wood, giCentre, City University London based on an idea by Nikolaus Gradwohl.
The handy library is licensed under the GNU Lesser General Public License: http://www.gnu.org/licenses/.
*/

function Scribble(p) {
  this.sketch = p || window;
  this.bowing = 1;
  this.roughness = 1;
  this.maxOffset = 2;
  this.numEllipseSteps = 9;
  this.ellipseInc = (Math.PI*2)/this.numEllipseSteps;

  this.getOffset = function( minVal, maxVal ) {
    return this.roughness*(this.sketch.random()*(maxVal-minVal)+minVal);
  }

  this.buildEllipse = function( cx, cy, rx, ry, offset, overlap ) {
    var radialOffset = this.getOffset( -0.5, 0.5 )-Math.PI/2;

    this.sketch.beginShape();
    this.sketch.curveVertex( this.getOffset( -offset, offset )+cx+0.9*rx*Math.cos( radialOffset-this.ellipseInc ),
        this.getOffset( -offset, offset )+cy+0.9*ry*Math.sin( radialOffset-this.ellipseInc ) );

    for ( var theta = radialOffset; theta < Math.PI*2+radialOffset-0.01; theta+=this.ellipseInc ) {
      this.sketch.curveVertex( this.getOffset( -offset, offset )+cx+rx*Math.cos( theta ),
          this.getOffset( -offset, offset )+cy+ry*Math.sin( theta ) );
    }

    this.sketch.curveVertex( this.getOffset( -offset, offset )+cx+rx*Math.cos( radialOffset+Math.PI*2+overlap*0.5 ),
        this.getOffset( -offset, offset )+cy+ry*Math.sin( radialOffset+Math.PI*2+overlap*0.5 ) );

    this.sketch.curveVertex( this.getOffset( -offset, offset )+cx+0.98*rx*Math.cos( radialOffset+overlap ),
        this.getOffset( -offset, offset )+cy+0.98*ry*Math.sin( radialOffset+overlap ) );

    this.sketch.curveVertex( this.getOffset( -offset, offset )+cx+0.9*rx*Math.cos( radialOffset+overlap*0.5 ),
        this.getOffset( -offset, offset )+cy+0.9*ry*Math.sin( radialOffset+overlap*0.5 ) );
    this.sketch.endShape();
  }

  this.getIntersectingLines = function( lineCoords, xCoords, yCoords ) {
    var intersections = [];
    var s1 = new Segment( lineCoords[0], lineCoords[1], lineCoords[2], lineCoords[3] );

    for ( var i = 0; i < xCoords.length; i++ ) {
      var s2 = new Segment( xCoords[i], yCoords[i], xCoords[(i+1)%xCoords.length], yCoords[(i+1)%xCoords.length] );

      if ( s1.compare(s2) == Relation.INTERSECTS ) {
        intersections.push( [s1.getIntersectionX(), s1.getIntersectionY()] );
      }
    }
    return intersections;
  }

  this.scribbleLine = function( x1, y1, x2, y2 ) {
    var lenSq = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
    var offset = this.maxOffset;

    if ( this.maxOffset*this.maxOffset*100 > lenSq ) {
      offset = Math.sqrt( lenSq )/10;
    }

    var halfOffset = offset/2;
    var divergePoint = 0.2 + this.sketch.random()*0.2;
    var midDispX = this.bowing*this.maxOffset*(y2-y1)/200;
    var midDispY = this.bowing*this.maxOffset*(x1-x2)/200;
    midDispX = this.getOffset( -midDispX, midDispX );
    midDispY = this.getOffset( -midDispY, midDispY );

    this.sketch.noFill();

    this.sketch.beginShape();
    this.sketch.vertex(     x1 + this.getOffset( -offset, offset ), y1 + this.getOffset( -offset, offset ) );
    this.sketch.curveVertex(x1 + this.getOffset( -offset, offset ), y1 + this.getOffset( -offset, offset ) );
    this.sketch.curveVertex(midDispX+x1+(x2 -x1)*divergePoint + this.getOffset( -offset, offset ), midDispY+y1 + (y2-y1)*divergePoint + this.getOffset( -offset, offset ) );
    this.sketch.curveVertex(midDispX+x1+2*(x2-x1)*divergePoint + this.getOffset( -offset, offset ), midDispY+y1+ 2*(y2-y1)*divergePoint + this.getOffset( -offset,offset ) );
    this.sketch.curveVertex(x2 + this.getOffset( -offset, offset ), y2 + this.getOffset( -offset, offset ) );
    this.sketch.vertex(     x2 + this.getOffset( -offset, offset ), y2 + this.getOffset( -offset, offset ) );
    this.sketch.endShape();

    this.sketch.beginShape();
    this.sketch.vertex(     x1 + this.getOffset( -halfOffset, halfOffset ), y1 + this.getOffset( -halfOffset, halfOffset ) );
    this.sketch.curveVertex(x1 + this.getOffset( -halfOffset, halfOffset ), y1 + this.getOffset( -halfOffset, halfOffset ) );
    this.sketch.curveVertex(midDispX+x1+(x2 -x1)*divergePoint + this.getOffset( -halfOffset, halfOffset ), midDispY+y1 + (y2-y1)*divergePoint + this.getOffset( -halfOffset, halfOffset ) );
    this.sketch.curveVertex(midDispX+x1+2*(x2-x1)*divergePoint + this.getOffset( -halfOffset, halfOffset ), midDispY+y1+ 2*(y2-y1)*divergePoint + this.getOffset( -halfOffset, halfOffset ) );
    this.sketch.curveVertex(x2 + this.getOffset( -halfOffset, halfOffset ), y2 + this.getOffset( -halfOffset, halfOffset ) );
    this.sketch.vertex(     x2 + this.getOffset( -halfOffset, halfOffset ), y2 + this.getOffset( -halfOffset, halfOffset ) );
    this.sketch.endShape();
  }

  this.scribbleCurve = function( x1, y1, x2, y2, x3, y3, x4, y4 ) {
    this.sketch.bezier(  x1+this.getOffset( -2, 2 ), y1+this.getOffset( -2, 2 ),
             x3+this.getOffset( -4, 4 ), y3+this.getOffset( -3, 3 ),
             x4+this.getOffset( -3, 3 ), y4+this.getOffset( -3, 3 ),
             x2+this.getOffset( -1, 1 ), y2+this.getOffset( -1, 1 ) );

    this.sketch.bezier(  x1+this.getOffset( -2, 2 ), y1+this.getOffset( -2, 2 ),
             x3+this.getOffset( -3, 3 ), y3+this.getOffset( -3, 3 ),
             x4+this.getOffset( -3, 3 ), y4+this.getOffset( -4, 4 ),
             x2+this.getOffset( -2, 2 ), y2+this.getOffset( -2, 2 ) );
  }

  this.scribbleRect = function( x, y, w, h ) {
    var halfWidth = w/2;
    var halfHeight = h/2;
    var left   = Math.min( x-halfWidth, x+halfWidth );
    var right  = Math.max( x-halfWidth, x+halfWidth );
    var top    = Math.min( y-halfHeight, y+halfHeight );
    var bottom = Math.max( y-halfHeight, y+halfHeight );

      this.scribbleLine( left, top, right, top );
      this.scribbleLine( right, top, right, bottom );
      this.scribbleLine( right, bottom, left, bottom );
      this.scribbleLine( left, bottom, left, top );
  }

  this.scribbleRoundedRect = function( x, y, w, h, radius ) {
    var halfWidth = w/2;
    var halfHeight = h/2;

    if ( radius == 0 || radius > halfWidth || radius > halfHeight ) {
      this.scribbleRect( x, y, w, h );
      return;
    }

    var left   = Math.min( x-halfWidth, x+halfWidth );
    var right  = Math.max( x-halfWidth, x+halfWidth );
    var top    = Math.min( y-halfHeight, y+halfHeight );
    var bottom = Math.max( y-halfHeight, y+halfHeight );

    this.scribbleLine( left+radius, top, right-radius, top, 1.5 );
    this.scribbleLine( right, top+radius, right, bottom-radius, 1.5 );
    this.scribbleLine( right-radius, bottom, left+radius, bottom, 1.5 );
    this.scribbleLine( left, bottom-radius, left, top+radius, 1.5 );

    this.scribbleCurve( left+radius, top, left, top+radius, left+radius*0.1, top+radius*0.1, left+radius*0.1, top+radius*0.1 );
    this.scribbleCurve( right-radius, top, right, top+radius, right-radius*0.1, top+radius*0.1, right-radius*0.1, top+radius*0.1 );
    this.scribbleCurve( left+radius, bottom, left, bottom-radius, left+radius*0.1, bottom-radius*0.1, left+radius*0.1, bottom-radius*0.1 );
    this.scribbleCurve( right-radius, bottom, right, bottom-radius, right-radius*0.1, bottom-radius*0.1, right-radius*0.1, bottom-radius*0.1 );
  }

  this.scribbleEllipse = function( x, y, w, h ) {
    var rx = Math.abs(w/2);
    var ry = Math.abs(h/2);

    rx += this.getOffset( -rx*0.05, rx*0.05 );
    ry += this.getOffset( -ry*0.05, ry*0.05 );

    this.buildEllipse( x, y, rx, ry, 1, this.ellipseInc*this.getOffset( 0.1, this.getOffset( 0.4, 1 ) ) );
    this.buildEllipse( x, y, rx, ry, 1.5, 0 );
  }

  this.scribbleFilling = function( xCoords, yCoords, gap, angle ) {
    if ((xCoords == null) || (yCoords == null) || (xCoords.length == 0) || (yCoords.length == 0)) {
        return;
      }

    var hachureAngle = this.sketch.radians( angle%180 );
    var cosAngle = Math.cos( hachureAngle );
    var sinAngle = Math.sin( hachureAngle );
    var tanAngle = Math.tan( hachureAngle );

    var left   = xCoords[0];
    var right  = xCoords[0];
    var top    = yCoords[0];
    var bottom = yCoords[0];

    for ( var i = 1; i < xCoords.length; i++ ) {
      left   = Math.min( left, xCoords[i] );
      right  = Math.max( right, xCoords[i] );
      top    = Math.min( top, yCoords[i] );
      bottom = Math.max( bottom, yCoords[i] );
    }

    var it = new HachureIterator( top-1, bottom+1, left-1, right+1, gap, sinAngle, cosAngle, tanAngle );
    var rectCoords = null;

    while ( (rectCoords = it.getNextLine()) != null ) {
      var lines = this.getIntersectingLines( rectCoords, xCoords, yCoords );

      for ( var i = 0; i < lines.length; i+=2 ) {
        if ( i < lines.length-1 ) {
          var p1 = lines[i];
          var p2 = lines[i+1];
          this.scribbleLine( p1[0], p1[1], p2[0], p2[1], 2 );
        }
      }
    }
  }
}



function HachureIterator( _top, _bottom, _left, _right, _gap, _sinAngle, _cosAngle, _tanAngle ) {
  var sinAngle = _sinAngle;
  var tanAngle = _tanAngle;
  var top = _top;
  var bottom = _bottom;
  var left = _left;
  var right = _right;
  var gap = _gap;

  var pos;
  var deltaX, hGap;
  var sLeft, sRight;

  if (Math.abs(sinAngle) < 0.0001)  {
    pos = left+gap;
  } else if (Math.abs(sinAngle) > 0.9999) {
    pos = top+gap;
  } else {
    deltaX = (bottom-top)*Math.abs(tanAngle);
    pos = left-Math.abs(deltaX);
    hGap = Math.abs(gap / _cosAngle);
    sLeft = new Segment(left, bottom, left, top);
    sRight = new Segment(right, bottom, right, top);
  }

  this.getNextLine = function() {
  	if (Math.abs(sinAngle) < 0.0001) {
  		if (pos < right) {
  			var line = [pos, top, pos, bottom];
  			pos += gap;
  			return line;
  		}
  	}	else if (Math.abs(sinAngle) > 0.9999) {
  		if (pos<bottom)	{
  			var line = [left, pos, right, pos];
  			pos += gap;
  			return line;
  		}
  	}	else {
  		var xLower = pos-deltaX/2;
  		var xUpper = pos+deltaX/2;
  		var yLower = bottom;
  		var yUpper = top;

  		if (pos < right+deltaX)	{
  			while (((xLower < left) && (xUpper < left)) || ((xLower > right) && (xUpper > right)))	{
  				pos += hGap;
  				xLower = pos-deltaX/2;
  				xUpper = pos+deltaX/2;

  				if (pos > right+deltaX)	{
  					return null;
  				}
  			}

  			var s = new Segment(xLower, yLower, xUpper, yUpper);

  			if (s.compare(sLeft) == Relation.INTERSECTS) {
  				xLower = s.getIntersectionX();
  				yLower = s.getIntersectionY();
  			}
  			if (s.compare(sRight) == Relation.INTERSECTS)	{
  				xUpper = s.getIntersectionX();
  				yUpper = s.getIntersectionY();
  			}
  			if (tanAngle > 0)	{
  				xLower = right-(xLower-left);
  				xUpper = right-(xUpper-left);
  			}

  			var line = [xLower, yLower, xUpper, yUpper];
  			pos += hGap;
  			return line;
  		}
  	}
  	return null;
  }
}

function Segment( _x1, _y1, _x2, _y2 ) {
  var x1 = _x1;
  var y1 =_y1;
  var x2 = _x2;
  var y2 = _y2;
  var a, b, c;
  var undef;
  var xi = Number.MAX_VALUE;
  var yi = Number.MAX_VALUE;

  a=y2-y1;
  b=x1-x2;
  c=x2*y1-x1*y2;

  if ((a==0) && (b==0) && (c==0)) {
    undef = true;
  } else {
    undef = false;
  }

  this.compare = function( otherSegment ) {
    if ((this.isUndefined()) || (otherSegment.isUndefined())) {
      return Relation.UNDEFINED;
    }

    var grad1 = Number.MAX_VALUE;
    var grad2 = Number.MAX_VALUE;
    var int1 = 0;
    var int2 = 0;

    if (Math.abs(b) > 0.00001) {
      grad1 = -a/b;
      int1  = -c/b;
    }

    if (Math.abs(otherSegment.getB()) > 0.00001) {
      grad2 = -otherSegment.getA()/otherSegment.getB();
      int2  = -otherSegment.getC()/otherSegment.getB();
    }

    if (grad1 == Number.MAX_VALUE) {
      if (grad2 == Number.MAX_VALUE)  {
        if (-c/a != -otherSegment.getC()/otherSegment.getA()) {
          return Relation.SEPARATE;
        }

        if ((y1 >= Math.min(otherSegment.getPy1(),otherSegment.getPy2())) &&
            (y1 <= Math.max(otherSegment.getPy1(),otherSegment.getPy2()))) {
          xi = x1;
          yi = y1;
          return Relation.INTERSECTS;
        }

        if ((y2 >= Math.min(otherSegment.getPy1(),otherSegment.getPy2())) &&
            (y2 <= Math.max(otherSegment.getPy1(),otherSegment.getPy2()))) {
          xi = x2;
          yi = y2;
          return Relation.INTERSECTS;
        }

        return Relation.SEPARATE;
      }

      xi = x1;
      yi = grad2*xi+int2;

      if (((y1-yi)*(yi-y2) < -0.00001) || ((otherSegment.getPy1()-yi)*(yi-otherSegment.getPy2()) < -0.00001)) {
        return Relation.SEPARATE;
      }

      if (Math.abs(otherSegment.getA()) < 0.00001) {
        if ((otherSegment.getPx1()-xi)*(xi-otherSegment.getPx2()) < -0.00001) {
          return Relation.SEPARATE;
        }
        return Relation.INTERSECTS;
      }
      return Relation.INTERSECTS;
    }

    if (grad2 == Number.MAX_VALUE) {
      xi = otherSegment.getPx1();
      yi = grad1*xi+int1;

      if (((otherSegment.getPy1()-yi)*(yi-otherSegment.getPy2()) < -0.00001) || ((y1-yi)*(yi-y2) < -0.00001)) {
        return Relation.SEPARATE;
      }

      if (Math.abs(a) < 0.00001) {
        if ((x1-xi)*(xi-x2) < -0.00001) {
          return Relation.SEPARATE;
        }
        return Relation.INTERSECTS;
      }
      return Relation.INTERSECTS;
    }

    if (grad1 == grad2) {
      if (int1 != int2) {
        return Relation.SEPARATE;
      }

      if ((x1 >= Math.min(otherSegment.getPx1(),otherSegment.getPx2())) &&
        (x1 <= Math.max(otherSegment.getPy1(),otherSegment.getPy2()))) {
        xi = x1;
        yi = y1;
        return Relation.INTERSECTS;
      }

      if ((x2 >= Math.min(otherSegment.getPx1(),otherSegment.getPx2())) &&
        (x2 <= Math.max(otherSegment.getPx1(),otherSegment.getPx2()))) {
        xi = x2;
        yi = y2;
        return Relation.INTERSECTS;
      }

      return Relation.SEPARATE;
    }

    xi = (int2-int1)/(grad1-grad2);
    yi = grad1*xi + int1;

    if (((x1-xi)*(xi-x2) < -0.00001) || ((otherSegment.getPx1()-xi)*(xi-otherSegment.getPx2()) < -0.00001)) {
      return Relation.SEPARATE;
    }
    return Relation.INTERSECTS;
  }

  this.getPx1 = function() {
  	return x1;
  }

  this.getPy1 = function()	{
  	return y1;
  }

  this.getPx2 = function() {
  	return x2;
  }

  this.getPy2 = function() {
  	return y2;
  }

  this.isUndefined = function() {
  	return undef;
  }

  this.getA = function() {
  	return a;
  }

  this.getB = function() {
  	return b;
  }

  this.getC = function() {
  	return c;
  }

  this.getIntersectionX = function() {
  	return xi;
  }

  this.getIntersectionY = function() {
  	return yi;
  }

  this.getLength = function( tx1, ty1, tx2, ty2 ) {
    var dx = tx2 - tx1;
    var dy = ty2 - ty1;
  	return Math.sqrt(dx*dx + dy*dy);
  }

}

var Relation = { LEFT:1, RIGHT:2, INTERSECTS:3, AHEAD:4, BEHIND:5, SEPARATE:6, UNDEFINED:7 };
</script>
  

<h2>Wavetable Generator</h2>
<div id="canvas"></div>
<div class="input-group">
  <div class="input-group-prepend">
    <label class="input-group-text" for="inputGroupSelect01"><i>ƒ (x) =</i></label>
  </div>
  <input type="text" id="formula-inp" placeholder="" class="form-control" aria-label="Text input with segmented dropdown button">
  <div class="input-group-append">
    <button type="button" id="genBtn" class="btn btn-outline-secondary">Generate</button>
  </div>
</div>
  <div id="vars">
  </div>
<div class="mt-2">
      <button type="button" id="addBtn" class="btn btn-outline-success">Add Constant+</button>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"></script>


<div id="tst" style="top:0px; right: 5px; position: absolute;">


  
</div>
              
            
!

CSS

              
                @import 'https://fonts.googleapis.com/css?family=Fira+Sans:300,300i,400,400i,500,500i,700,700i&subset=latin-ext';
@import 'https://fonts.googleapis.com/css?family=Roboto+Mono:300,400&subset=latin-ext';
@import 'https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css';

:root {
    font-size: 20px;
}

body { /* TEXT PARENT */
    width: 35em;
    margin: 0 auto;
    font-family: "Fira Sans", "Verdana", "Geneva", sans-serif;
    font-weight: 300;
    line-height: 1.4;
    text-align: center;
}

body * {
  text-align: center;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    padding: 0;
    font-weight: normal;
}

h1 {
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-weight: 700;
    font-size: 3.25rem;
}

h2 {
    margin-top: 1rem;
    margin-bottom: 1rem;
    font-weight: 300;
    font-size: 2.5rem;
}

h3 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 400;
    font-size: 2rem;
}

h4 {
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 1.5rem;
}

h5 {
    margin-top: 1rem;
    font-weight: 700;
    font-size: 1.25rem;
}

h6 {
    margin-top: 1rem;
    font-weight: 700;
    font-size: 1rem;
}

p {
    margin-top: 0;
    margin-bottom: 1rem;
}

a {
    background-image: linear-gradient(#449, #449);
    background-size: 0.06em 0.06em;
    background-repeat: repeat-x;
    background-position-y: 93%;
    background-position-x: 0;
    color: #449;
    text-decoration: none;
    /* text-shadow: white 0.7px 0.7px 0.1px, white 0 1px 0.1px, white -.7px 0.7px 0.1px, white -.7px 0 0.1px, white -.7px -.7px 0.1px, white 0 -.7px 0.1px, white 0.7px -.7px 0.1px, white 0.7px 0 0.1px; */
    transition: 0.15s;
}

a:active {
    background-color: #eee;
    color: #555;
    text-decoration: none;
    /* text-shadow: #eee 0.7px 0.7px 0.1px, #eee 0 1px 0.1px, #eee -.7px 0.7px 0.1px, #eee -.7px 0 0.1px, #eee -.7px -.7px 0.1px, #eee 0 -.7px 0.1px, #eee 0.7px -.7px 0.1px, #eee 0.7px 0 0.1px; */
}

a:hover {
    background-image: linear-gradient(#66e, #66e);
    color: #66e;
}

b,
strong {
    font-weight: bolder;
}

em,
i {
    font-style: italic;
}

del,
s,
strike {
    text-decoration: none;
    background-image: linear-gradient(#000, #000);
    background-size: 0.06em 0.06em;
    background-repeat: repeat-x;
    background-position-y: 65%;
    background-position-x: 0;
}

code,
pre,
samp,
var {
    font-size: 95%;
    font-family: "Roboto Mono", monospace;
    font-weight: 300;
    color: #666;
}

pre {
    display: block;
    margin: 1rem -2rem;
    padding: 1rem 2rem;
    background-color: #eee;
    border-left: 0.1rem solid #888;
}

p code {
    padding: 0 0.2em 0.1em;
    background-color: #eee;
}

p var {
    padding: 0 0.2em 0.1em;
    background-color: #eee;
    font-weight: bolder;
    font-style: normal;
}

p samp {
  padding: 0 0.2em 0.1em;
  margin: 0 0.1em;
  background-color: #666;
  color: #eee;
}

kbd {
  position: relative;
  padding: 0.2em 0.2em 0.1em 0.2em;
  margin: 0 0.1em;
  bottom: 0.125em;
  font-family: "Fira Sans", "Verdana", "Geneva", sans-serif;
  font-size: 0.8em;
  background-color: #eee;
  border-radius: 0.2em;
  border-bottom: 0.05em solid #aaa;
}

blockquote {
    margin: 1rem -2rem;
    padding: 1rem 2rem;
    background-color: #eee;
    color: #666;
    font-size: 1.2rem;
    font-style: italic;
    line-height: 1.5;
}

blockquote::before {
    content: "\201C";
    display: block;
    position: relative;
    height: 0;
    left: -1.3rem;
    top: -0.5rem;
    font-size: 2em;
    color: #888;
}

blockquote::after {
    content: "\201D";
    display: inline-block;
    position: relative;
    height: 0;
    top: 1.6rem;
    left: 0.2rem;
    font-size: 2em;
    line-height: 0;
    color: #888;
}

abbr[title] {
    text-decoration: none;
    background-image: linear-gradient(90deg, gray 50%, transparent 50%);
    background-size: 0.1em 0.06em;
    background-repeat: repeat-x;
    background-position-y: 100%;
    background-position-x: 0;
    font-feature-settings: "smcp";
}

ul {
    list-style: none;
    margin-left: -2em;
    padding-left: 2em;
}

ul > li {
    padding-left: 0;
}

ul > li::before {
    content: "»";
    display: block;
    position: relative;
    height: 0;
    width: 2em;
    margin-left: -2.5em;
    font-weight: bolder;
    color: #888;
    text-align: right;
}

ul ul > li::before {
    content: "›";
    display: block;
    position: relative;
    height: 0;
    width: 2em;
    margin-left: -2.5em;
    font-weight: bolder;
    color: #888;
    text-align: right;
}

ol {
    list-style: none;
    margin-left: -2em;
    padding-left: 2em;
}

ol > li {
    padding-left: 0;
    counter-increment: ol-count;
}

ol > li:first-child {
    counter-reset: ol-count;
}

ol > li::before {
    content: counter(ol-count)".";
    display: block;
    position: relative;
    height: 0;
    width: 2em;
    margin-left: -2.5em;
    font-weight: bolder;
    color: #888;
    text-align: right;
}

ol ol,
ol ul,
ul ol,
ul ul {
    margin: 0.5em 0;
}

img {
    display: block;
    width: calc(100% + 4rem);
    margin: 1rem -2rem;
}

figure {
    display: inline-table;
    margin: 0rem -2rem 1rem -2rem;
    padding: 2rem 2rem;
    background-color: #eee;
}

figure img {
    display: inline-block;
    width: auto;
    max-width: 100%;
    margin: 0 auto;
}

figure img + img {
  margin-left: 1rem;
}

figure figcaption {
    max-width: 100%;
    margin: 1rem auto -1rem auto;
    font-size: 0.9rem;
    font-style: italic;
}

table {
    margin: 0 -1rem 1rem -1rem;
    width: calc(100% + 2rem);
    overflow: hidden;
    border-collapse: collapse;
}

table caption {
  padding-top: 0.5rem;
  border-top: 1px solid #eee;
  caption-side: bottom;
  text-align: center;
  font-style: italic;
  color: #666;
}

tr {
    transition: 0.15s;
}

thead tr {
    border-bottom: 2px solid #888;
}

tfoot tr {
    border-bottom: none;
    border-top: 1px solid #eee;
    font-weight: bolder;
}

tbody tr:hover,
tfoot tr:hover {
    background-color: #eee;
}

td, th {
    position: relative;
    padding: 0.3rem 1rem;
}

th {
    font-weight: bolder;
}

tbody tr:first-of-type td,
tbody tr:first-of-type th {
    padding-top: 0.5rem;
}

hr {
    height: 0;
    width: 10rem;
    border: 0;
    border-bottom: 1px solid rgba(0,0,0,1);
    margin: 2rem auto;
}

/*hr::after {
    content: "* *";
    display: block;
    position: relative;
    bottom: 1.5em;
    margin: 0 auto;
    text-align: center;
    font-size: 2rem;
}*/

/* .toast-warning{
    background-color: yellow;
  } */

.toast{
  transition:all 0.5s ease;
  -webkit-transition:all 0.5s ease;
}
              
            
!

JS

              
                let cnv;
let reso = 200;
let padding = 7;
let h;

let generated = false;
let f = function () {};

var scribble = new Scribble();
scribble.bowing = 0.9; // changes the bowing of lines
scribble.roughness = 0.7; // changes the roughness of lines
scribble.maxOffset = 1.4; // coordinates will get an offset, here you define the max offset

function generate() {
  let inp =$("#formula-inp").val();
  let ev;
  let bup = f;
  try {
    f = eval(constants() + " (x)=>{ return " + inp + "; }");
    runTest();
  } catch (error) {
    console.log(error);
    showToast(error);
    f = bup;
    return;
  }
  generated = true;
}

function runTest() {
  return f(0);
}

function formula(x) {
  // x = map(x, 0, TAU, -1, 1);
  return f(x);
}

function setup() {
  console.log("setup");
  cnv = createCanvas(600, 200);
  // document.getElementById('canvas').appendChild(cnv.canvas);
  $("#canvas").append(cnv.canvas);

  renderTable();
  h = height - padding;
}

let playheadpos = 0;
function grid() {
  stroke(0);
  strokeWeight(1);
  // Zero Crossing
  scribble.maxOffset = 0.154;
  scribble.scribbleLine(0, height / 2, width, height / 2);
  scribble.maxOffset = 1.4;

//   fill(255);
//   if (playheadpos > width - 10) {
//     // playheadpos =  ? 0 : playheadpos + 1;
//     scribble.scribbleLine(playheadpos - width, 0, playheadpos - width, height);
//     scribble.scribbleEllipse(
//       playheadpos - width,
//       formula(map(playheadpos - width, 0, width, 0, TAU)),
//       10,
//       10
//     );

//     if (playheadpos === width + 10) {
//       playheadpos = 10;
//     }
//   }

//   // Playhead
//   scribble.scribbleLine(playheadpos, 0, playheadpos, height);
//   scribble.scribbleEllipse(
//     playheadpos,
//     formula(map(playheadpos, 0, width, 0, TAU)),
//     10,
//     10
//   );
//   playheadpos++;
}

function draw() {
  clear();
  if (!generated) return;

  renderTable();
  grid();
}

function renderTable() {
  let vtx = [];
  for (let i = 0; i < TAU; i += TAU / reso) {
    vtx.push(createVector(i, formula(i)));
  }

  let verts = pointsNormalized(vtx);

  let _min = verts.findMin("x");
  let _max = verts.findMax("x");

  scribble.maxOffset = 1.8;

  strokeWeight(2);
  let lastPt = createVector(0, height / 2);
  // beginShape(LINES);
  for (let pt of verts) {
    // vertex(map(pt.x, 0, TAU, 0, width), pt.y);
    pt.x = map(pt.x, _min, _max, 0, width);
    pt.y = map(pt.y, -1, 1, padding, height-padding);
    scribble.scribbleLine(lastPt.x, lastPt.y, pt.x, pt.y);
    lastPt = pt;
  }
  // endShape();
}

let varnames = "abcdefghijklmnopqrstuvwyz";
let vars = 1;

$(document).ready(function () {
  $(".toast").toast({ autohide: false });

  $("#formula-inp").val("sin(x)").bind('keypress', (e)=>{ if(e.which === 13) { generate(); } });
  
  
  $("#genBtn").click(function () {
    generate();
  });
  $("#addBtn").click(function () {
    if (vars >= varnames.length) {
      showToast("You have reached the limit for number of constants.");
      return;
    }
    let varName = varnames[vars - 1];
    $("#vars").append(`
<div class="input-group mt-1 userdefined">
  <div class="input-group-prepend">
    <label style="background-color:${selectColor(vars)};" class="input-group-text" for="formControlRange">${varName}</label>
  </div>
  <input type="number" step="0.01" lang="en" value="0.00" class="form-control" id="formControlRange">
</div>`).bind('keypress', (e)=>{ if(e.which === 13) { generate(); } });
    vars++; 
  });
  
 
  
});

function constants(){
  let str = "";
  $('.userdefined').each(function(){
      let _vn = $(this).find('label').text();
      let _val = $(this).find('input').val()
      str += `let ${_vn} = ${_val};`
    });
  return str;
}

function showToast(txt) {
  
  let _toast = $(`
  <div class="toast bg-info text-white mt-1">
    <div class="toast-header text-dark">
      <strong class="mr-auto">Wavetable Generator</strong>
      <small id="timeago">just now</small>
      <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>
    <div class="toast-body" id="err">
      ${txt}
    </div>
  </div>`);
  $("#tst").append(_toast);
  _toast.toast({delay:3000})
  _toast.toast('show')
}
let tout;

function selectColor(colorNum) {
  let colors = varnames.length;
  if (colors < 1) colors = 1; // defaults to one color - avoid divide by zero
  return "hsl(" + ((colorNum * -1 * (360 / colors)) % 360) + ",100%,50%)";
}

// Normalize graph in both axes
function pointsNormalized(points) {
  let _max = points.findMax("y");
  let _min = points.findMin("y");

  let pts = points.map((pt) => {
    return createVector(pt.x, map(pt.y, _min, _max, -1, 1));
  });
  let phase = 0;
  // Return after 2 phases
  let ind = 0;
  let last = 0;
  for (let p of pts) {
    phase = Math.sign(p.y) === last ? phase : phase + 1;
    last = Math.sign(p.y);
    if (phase >= 3) {
      return pts.slice(0, ind);
    } else {
      ind++;
    }
  }
  return pts;
}

Array.prototype.findMax = function (prop) {
  return this.reduce((a, b) => (a[prop] > b[prop] ? a : b))[prop];
};

Array.prototype.findMin = function (prop) {
  return this.reduce((a, b) => (a[prop] <= b[prop] ? a : b))[prop];
};

              
            
!
999px

Console