Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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="harmonograph-style.css">

</head>


<html>

    <body id='main' onload="init()">

        
        <canvas id='canvas' class='' height="1080" width="1080"></canvas>
        
    
            <div class="controls">
			<button type="button" id="pauseBtn" onmouseup="this.blur();">Pause</button>
            <button type="button" id='resetBtn' onmouseup="this.blur();">Reset</button>
            <button id='spdBtn' onmouseup="this.blur();">speed</button>
              <div id="spf">256x</div>
		</div>
            
    <form class='center' name='anim_input' id='animInput' >
        
<div class='flex_container'>
        <div class='flex_col'>
                        <h3>Pendulum 1 Settings:</h3>
            <div class='flex_row'>
                <div class='flex_col'>
                    <input type="text" name='amp_x1' id='amp_x1' value=100 tabindex="1"></input>  
                    <label for='amp_x1' id='amp_x1_lbl'><p>Amplitude X</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='amp_y1' id='amp_y1' value=100 tabindex="2"></input>  
                    <label for='amp_y1' id='amp_y1_lbl'><p>Amplitude Y</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='phase_x1' id='phase_x1' value=90></input>  
                    <label for='phase_x1' id='phase_x1_lbl'><p>Phase X</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='phase_y1' id='phase_y1' value=0></input>  
                    <label for='phase_y1' id='phase_y1_lbl'><p>Phase Y</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='damp1' id='damp1' value=0></input>  
                    <label for='phase_x1' id='phase_x1_lbl'><p>Dampening</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='freq1' id='freq1' value=3  tabindex="7"></input>  
                    <label for='freq1' id='freq1_lbl'><p>Frequency</p></label>
                </div>
				<div class='flex_col'>
                    <input type="text" name='microtn1' id='microtn1' value=0.01  tabindex="10"></input>  
                    <label for='microtn1' id='microtn1_lbl'><p>Micro Tuning 1</p></label>
                </div>
			</div>
        </div>
</div>
<div class='flex_container'>
        <div class='flex_col'>
                        <h3>Pendulum 2 Settings:</h3>
            <div class='flex_row'>
                <div class='flex_col'>
                    <input type="text" name='amp_x2' id='amp_x2' value=100 tabindex="3"></input>  
                    <label for='amp_x2' id='amp_x2_lbl'><p>Amplitude X</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='amp_y2' id='amp_y2' value=100 tabindex="4"></input>  
                    <label for='amp_y2' id='amp_y2_lbl'><p>Amplitude Y</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='phase_x2' id='phase_x2' value=0></input>  
                    <label for='phase_x2' id='phase_x2_lbl'><p>Phase X</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='phase_y2' id='phase_y2' value=90></input>  
                    <label for='phase_y2' id='phase_y2_lbl'><p>Phase Y</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='damp2' id='damp2' value=0></input>  
                    <label for='damp2' id='damp2_lbl'><p>Dampening</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='freq2' id='freq2' value=2  tabindex="8"></input>  
                    <label for='freq2' id='freq2_lbl'><p>Frequency</p></label>
                </div>
				<div class='flex_col'>
                    <input type="text" name='microtn2' id='microtn2' value=0.02  tabindex="11"></input>  
                    <label for='microtn2' id='microtn2_lbl'><p>Micro Tuning 2</p></label>
                </div>
            </div>
        </div>
</div>
<div class='flex_container'>
        <div class='flex_col'>
                        <h3>Pendulum 3 Settings:</h3>
            <div class='flex_row'>
                <div class='flex_col'>
                    <input type="text" name='amp_x3' id='amp_x3' value=50 tabindex="5"></input>  
                    <label for='amp_x3' id='amp_x3_lbl'><p>Amplitude X</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='amp_y3' id='amp_y3' value=-50 tabindex="6"></input>  
                    <label for='amp_y3' id='amp_y3_lbl'><p>Amplitude Y</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='phase_x3' id='phase_x3' value=-90></input>  
                    <label for='phase_x3' id='phase_x3_lbl'><p>Phase X</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='phase_y3' id='phase_y3' value=0></input>  
                    <label for='phase_y3' id='phase_y3_lbl'><p>Phase Y</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='damp3' id='damp3' value=0></input>  
                    <label for='damp3' id='damp3_lbl'><p>Dampening</p></label>
                </div>
                <div class='flex_col'>
                    <input type="text" name='freq3' id='freq3' value=3  tabindex="9"></input>  
                    <label for='freq3' id='freq3_lbl'><p>Frequency</p></label>
                </div>
				<div class='flex_col'>
                    <input type="text" name='microtn3' id='microtn3' value=-0.01  tabindex="12"></input>  
                    <label for='microtn3' id='microtn3_lbl'><p>Micro Tuning 3</p></label>
                </div>
            </div>
        </div>
</div>
<div class='flex_container'>
	<div class='flex_col'>
            	<fieldset id='pattern_clr'>
					<label id='pattern_color' for='pattern_color'>Color?</label>
    	<div class='flex_row'>
					<div class='flex_col'>
						<input type='radio' name='pattern_color' id='red' value='red'/><p>Red</p>
					</div>
					<div class='flex_col'>
						<input type='radio' name='pattern_color' id='blue' value='blue'/><p>Blue</p>
					</div>
					<div class='flex_col'>
						<input type='radio' name='pattern_color' id='green' value='green'/><p>Green</p>
					</div>
					<div class='flex_col'>
						<input type='radio' name='pattern_color' id='orange' value='orange'/><p>Orange</p>
					</div>
					<div class='flex_col'>
						<input type='radio' name='pattern_color' id='purple' value='purple'/><p>Purple</p>
					</div>
            	</fieldset>      
		</div>

		

	<div class='flex_col'>
            	<fieldset id='pattern'>
					<label id='pattern_amount' for='pattern_amount'>How Much Pattern?</label>
            <div class='flex_row'>
					<div class='flex_col'>
						<input type='radio' name='pattern_amount' id='full' value='full' /><p>Full</p>
					</div>

					<div class='flex_col'>
						<input type='radio' name='pattern_amount' id='half' value='half'/><p>Half</p>
					</div>
					<div class='flex_col'>
						<input type='radio' name='pattern_amount' id='third' value='third'/><p>Third</p>
					</div>
            	</fieldset>
	</div>
			</div>
      	</div>
		<div class='flex_row'>
						<input class='submit_button' type="button" name='sbmtBtn' value="GO!" onclick="btnGetFormClick()">
		</div>       

		</div>
          
</form>
<!--        <script src='harmonograph-script.js'></script>-->
<div id='music_cheatsheet'>
  <h2>
    Some Musical Ratios
  </h2>
<h3>
Fifth is 3:2
<br>
Fourth is 4:3
<br>
Major sixth is 5:3
<br>
Major third is 5:4
<br>
Perfect eleventh is 8:3
<br>
Seventh-limit jazz tuning is 7:3
</h3>
</div>
    
              
            
!

CSS

              
                
html {
  font-family: Helvetica, Arial, sans-serif;
  font-size: 80%;
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    padding: 0;
    overflow: auto;
    background-color: #000;
}

.center{
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
}

canvas {
/* background must be HEX color, otherwise FileSaver.js will render it with
   a white background */
    background: #000;
    position: absolute;
/* top: 75% looks good on a larger screen, when browser is at 100% zoom */
/*    top: 75%;*/
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    z-index: -1;
}

.controls {
    position: absolute;
    top: 3%;
    left: 3%;
    z-index: 1;
}

button,#spf {
    opacity: 0.5;
  display: inline-block;
  border-radius: 3px;
  border: 2px solid;
  font-size: 0.9rem;
  padding: 0.4rem 0.8em;
  background: rgba(0,0,0,0);
/*  border-bottom: 1px solid #498b50;*/
  color: white;
  -webkit-font-smoothing: antialiased;
  font-weight: bold;
  margin: 0 0.25rem;
  text-align: center;
  transition: 0.5s;
}

button:hover {
  opacity: 0.75;
background: rgba(224, 232, 255, 0.78);
    color: #000;
    border-color: white;
  cursor: pointer;
}

button:active {
  opacity: 1;
  box-shadow: 0 -3px 10px rgba(0, 0, 0, 0.1) inset;
}

.fadeaway {
    opacity: 0;
}

#ratio_col {
    opacity: 0.1;
    transition-duration: 1s;
}

input[type='radio'] {
    border: 0px;
    width: auto;
    height: 1.2em;
	margin-top: 7px;
}
input {
    height: 3.0em;
    width: 3.0em;
    font-size: 1.0em;
    padding: 0;
    text-align: center;
/*    display: block;*/
    border: none;
    border-radius: 50%;
    opacity: .65;
    color: #3e3e3e;
}

form {
/*    opacity: 0.65;*/
    color: rgba(255, 255, 255, 0.85);
    min-width: 650px;
    margin: 0 auto;
    border-radius: 4em;
    padding: 0.0em;
  	padding-bottom: 1em;
    background-color: rgba(87, 87, 87, 0.65);
    line-height: 1.1em;
    transition: 1s;
}

legend {
    text-align: center;
}

fieldset input {
    margin: 1em auto 0.2em auto;
}

legend + input {
    margin: 0.1em auto 0.75em auto;
}

input + p {
margin-top: 2px;
}

label {
    padding: 0;
    text-align: center;
    display: block;
    margin: 1em auto 0 auto;
}

fieldset {
display: -webkit-flex;
    display: flex;
    border: none;
/*    text-align: center;*/
/*    width: 100%;*/
}

.flex_container {
display: -webkit-flex;
    display: flex;
    -webkit-justify-content: center;
    justify-content: center;
    flex-direction: row;
	align-items: center;
    margin: 0 .1em;
/*    width: 100%;*/    
}

.flex_row {
display: -webkit-flex;
    display: flex;
    -webkit-justify-content: space-around;
    justify-content: space-around;
    flex-direction:row;
	width: auto;
}

.flex_col {
    flex-direction: column;
     -webkit-justify-content: space-between;
    justify-content: space-between;
    text-align: center;
	align-items: center;
	margin: 0 10px;
}

#pattern_color,#pattern_amount {
	font-weight: bold;
	font-size: 1.2em;
}

#epi,#hypo,#mod_yes,#mod_no,#ellip_Big_ratio,#ellip_sml_ratio {
    margin: 0 0.5em;
}

.flex_box {
display: -webkit-flex;
    display: flex;
    -webkit-justify-content: center;
    justify-content: center;
    flex-direction: row;
/*    width: 30%;*/
/*    background-color: lightgrey;*/
}

#firstrow,#secondrow,#thirdrow,#fourthrow {
display: -webkit-flex;
    display: flex;
    -webkit-justify-content: center;
    justify-content: center;
    width: 100%;
/*    background-color: lightgrey;*/
}

#fourthrow, #fifthrow {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
    justify-content:flex-start;
    padding-left: 2.6em;
}

.row1 {
/*    float: left;*/
    margin: 0 0.6em;
    width: 22.7%;
}
.row2,.row3,.row4 {
    text-align: center;
    margin: 0 0.6em;
    width: 22%;
}

.row4,.row5 {
    display: flex;
    flex-wrap: nowrap;
    text-align: left;
    margin-top: 0.5em;
    width: 100%;
        align-content:flex-end;
}

#row5_first {
    margin-top: 3em;
}

#fourthrow_first_col,#fifthrow_first_col {
    display: flex;
    flex-direction: column;
    margin-right: 2em;
}

fourthrow_second_col,#fifthrow_second_col {
    display: -webkit-flex;
   display: flex;
   -webkit-flex-direction: column /* works with row or column */
   flex-direction: column;
   -webkit-align-items: center;
   align-items: flex-start;
   -webkit-justify-content: center;
   justify-content: center;
}
/*
* [type="color"] {
    border-radius: 0;
        border: none;
    background-color: none;
}
*/
#colorpicker {
/*
    width: 2em;
    height: 2em;
*/
    margin-top: 0.5em;
    border-radius: 0;
        border: none;
    background: none;
}

#formleft {
    width: 40%;
    padding-left: 3em;
    float: left;
}
#formright {
    display: none;
    width: 50%;
    float: right;
}

#formlast {
/*    overflow: auto;*/
    
/*    display: block;*/
/*    width: 60%;*/
    margin: 2em auto;

}

.submit_button {
    float: none;
    height: 5.25em;
    width: 5.25em;
    font-size: 1.5em;
    font-weight: bold;
    color: #313131;
    padding: 0;
    text-align: center;
    border: none;
    border-radius: 50%;
}

[type='range'] {
    height: 1em;
    width: 280px;
    margin: 4px 10px 0 0;
    padding: 0;
        align-content: center;

}

#green_value,#blue_value,#opacity_value {
    margin-top: 16px;
}

#outputRed {
    margin-top: 5px;
}

#outputBlue,#outputGreen,#outputOpacity {
    margin-top: 17px;
}

#outputRed,#outputGreen,#outputBlue,#outputHorzScale,#outputVertScale,#outputOpacity { 
    display: inline-table;
    width: 105px;
  color: white;
    opacity: 0.75;
    padding: 0 1em;
  border-radius: 10px;
  font: bold 15px/20px;
}

/*
output:after { 
  content: "";
  position: absolute; 
  width: 0;
  height: 0;
  border-top: 10px solid #999999;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  margin-top: -1px;
}
*/

#colorSwatch {
    margin-top: 0.8em;
    height: 112px;
    width: 138px;
    border-color: aliceblue;
    background-color: rgb(255,107,0,0.40);
    transition: 0.5s;
}

input.error {background-color: #671008;}

#music_cheatsheet {
display: block;
position: absolute;
top: 10%;
left: 3%;
color: hsl(0, 0%, 25%);
}

.flex-container-col,.flex-container-row {
		  padding: 0;
		  margin: 0;
		  list-style: none;
		  display: -webkit-box;
		  display: -moz-box;
		  display: -ms-flexbox;
		  display: -webkit-flex;
		  display: flex;
		  -webkit-flex-flow: column wrap;
		  justify-content: space-around;
}

.flex-container-row {
		  -webkit-flex-flow: row wrap;
}

.flex-item {
		  background: tomato;
		  padding: 5px;
		  width: 200px;
/*		  height: 150px;*/
		  margin-top: 10px;
		  color: greenyellow;
		  font-weight: bold;
		  font-size: 1em;
		  text-align: center;
}

.color-selector {
		width: 40%;
}

.flex-container-row .flex-item {
		width: 46px;
		background-color: purple;
}
              
            
!

JS

              
                //  Some variables, and the step() function, based on Andy Giger's virtual harmonograph:
//  andygiger.com/science/harmonograph/index.html
//  Although I didn't use Mr. Giger's equations, I learned a lot by studying them,
//  and am eternally grateful to him for posting his work

//  The equations I used are from the Wikipedia entry on Harmongraphs:
//  https://en.wikipedia.org/wiki/Harmonograph#Computer-generated_harmonograph_figure

//  BASIC VARIABLES  //

var theta = 0;
// frequency   HOW FAR APART THE DOTS ARE, SMALLER NUMBERS = CLOSER
var fd;
var f1;
var f2;
var f3;
var f4;
var f5;
var f6;

//  micro tuning
var mt1;
var mt2;
var mt3;

// phase
var p1;
var p2;
var p3;
var p4;
var p5;
var p6;

var ad;
var a1; // Amplitude   //   CONTROLS THE OVERALL SIZE, LARGER NUMBERS = BIGGER
var a2;
var a3;
var a4;
var a5;
var a6;

var d1; // dampening; 0 = pendulum won't naturally stop swinging due to gravity
var d2;
var d3;
var d4;
var d5;
var d6;

// Canvas
var canvas;

// 2d Drawing Context.
var ctx;

var centerX, centerY;
var rot_increment;
var revo_increment_multiplier;
var userInputForm;
var s = 256;
var t = 0.0;
var dt = 0.001;
var intId;
var ns, setns = 100000;
var revolutions;

var userInputForm = document.anim_input;

var full_pattern = 314000;
var half_pattern = 157000; 
var third_pattern = 104666;

var pattern_color;
var requestID;
var animation_is_running;

//  END BASIC VARIABLES  //

//  LETS GET THIS PARTY STARTED

function init() {
  window.clearInterval(intId);
  intId = null;
  canvas = document.getElementById('canvas');
  ctx = canvas.getContext('2d');
  ctx.globalCompositeOperation = 'source-over';
  centerX = canvas.width / 2;
  centerY = canvas.height / 2;
  ctx.setTransform(1, 0, 0, 1, 0, 0);
  ctx.rotate(0);
  ctx.translate(0, 0);

  ctx.moveTo(0, 0);
  ctx.fillStyle = 'rgba(0,0,0,1)';
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  ctx.rotate(theta);

  ctx.fillStyle = pattern_color;
  ctx.translate(centerX, centerY);

  userInputForm = document.anim_input;
  userInputForm.sbmtBtn.addEventListener('click', btnGetFormClick);
  
  fd = 0.001;
  
  mt1 = parseFloat(document.getElementById('microtn1').value);
  mt2 = parseFloat(document.getElementById('microtn2').value);
  mt3 = parseFloat(document.getElementById('microtn3').value);

  f1 = (parseFloat(document.getElementById('freq1').value) + mt1) * fd;
  f2 = f1;
  f3 = (parseFloat(document.getElementById('freq2').value) + mt2) * fd;
  f4 = f3;
  f5 = (parseFloat(document.getElementById('freq3').value) + mt3) * fd;
  f6 = f5;

  p1 = parseInt(document.getElementById('phase_x1').value) / 180 * Math.PI;
  p2 = parseInt(document.getElementById('phase_y1').value) / 180 * Math.PI;
  p3 = parseInt(document.getElementById('phase_x2').value) / 180 * Math.PI;
  p4 = parseInt(document.getElementById('phase_y2').value) / 180 * Math.PI;
  p5 = parseInt(document.getElementById('phase_x3').value) / 180 * Math.PI;
  p6 = parseInt(document.getElementById('phase_y3').value) / 180 * Math.PI;

  ad = 2;
  a1 = document.getElementById('amp_x1').value * ad;
  a2 = document.getElementById('amp_y1').value * ad;
  a3 = document.getElementById('amp_x2').value * ad;
  a4 = document.getElementById('amp_y2').value * ad;
  a5 = document.getElementById('amp_x3').value * ad;
  a6 = document.getElementById('amp_y3').value * ad;

  willbe_d1 = document.getElementById('damp1').value;
  willbe_d3 = document.getElementById('damp2').value;
  willbe_d5 = document.getElementById('damp3').value;

  t = 0.0;
  ns = setns;
  revolutions = 0;
  rot_increment = 6;  //  I DON'T THINK I EVEN USE THIS
  revo_increment_multiplier = 1.0; //  OR THIS EITHER

  intId = window.setInterval(step, 1000 * dt);
}

function step() {
  for (var i = 0; i < s; ++i) {
    t += dt;
    drawFrame();
  }


  function drawFrame() {

    dt = 2;
    d1 = willbe_d1 / 1000000; // dampening
    d2 = d1;
    d3 = willbe_d3 / 1000000;
    d4 = d3;
    d5 = willbe_d5 / 1000000;
    d6 = d5;

    var x = a1 * Math.sin((t * f1) + p1) * Math.exp(-d1 * t) + a3 * Math.sin((t * f3) + p3) * Math.exp(-d3 * t) + a5 * Math.sin((t * f5) + p5) * Math.exp(-d5 * t);

    var y = a2 * Math.sin((t * f2) + p2) * Math.exp(-d2 * t) + a4 * Math.sin((t * f4) + p4) * Math.exp(-d4 * t) + a6 * Math.sin((t * f6) + p6) * Math.exp(-d6 * t);

    ctx.beginPath();
    ctx.rect(x, y, 2, 2);
    ctx.fill();
    revolutions += 1;

    if (revolutions == pattern_amount) {
      window.clearInterval(intId);
      intId = null;
    }
//   END OF DRAWFRAME FUNCTION
  }
};

window.onload = function() {
  document.getElementById('spdBtn').addEventListener('click', function(e) {
    s = s * 2;
    if (s > 1024) {
      s = 256;
    };
    document.getElementById('spf').innerHTML = s + "x";
    console.log('from inside the spdBtn function');

  });
  document.getElementById('resetBtn').addEventListener('click', formReset);
  document.getElementById('resetBtn').addEventListener('click', erase);
  document.getElementById('main').addEventListener('keyup', checkSubmit);

  revolutions = 0;

};

function btnGetFormClick(e) {

  revolutions = 0;

  console.log('from inside btnGetFormClick function = ');

  document.getElementById('animInput').setAttribute('class', 'center fadeaway');
  document.getElementById('main').removeEventListener('keyup', checkSubmit);
  document.getElementById('pauseBtn').addEventListener('click', pause);
  setPatternAmount();
  setColor();
  console.log('from inside btnGetFormClick function, pattern amount = ' + pattern_amount);

  init();
}

function setPatternAmount() {

  x = userInputForm.pattern_amount.value;

  switch (x) {
    case 'full':
      pattern_amount = 314000;
      break;
    case 'half':
      pattern_amount = 157000;
      break;
    case 'third':
      pattern_amount = 104666;
      break;
    default:
      pattern_amount = 314001;
      break;
  };
}

function setColor() {

  x = userInputForm.pattern_color.value;

  switch (x) {
    case 'red':
      pattern_color = 'rgba(255, 0, 0, 0.3)';
      break;
    case 'green':
      pattern_color = 'rgba(0, 255, 29, 0.3)';
      break;
    case 'blue':
      pattern_color = 'rgba(0, 177, 255, 0.3)';
      break;
    case 'orange':
      pattern_color = 'rgba(255, 128, 0, 0.3)';
      break;
    case 'purple':
      pattern_color = 'rgba(108, 0, 255, 0.3)';
      break;
    default:
      pattern_color = 'rgba(255, 157, 0, 0.3)';
      break;
  };

}

var checkSubmit = function(e) {
  e.preventDefault();

  console.log('checkSubmit function fired');

  if (e && e.keyCode == 13) {
    btnGetFormClick();
  }
}

var checkReset = function(e) {
  if (e && e.keyCode == 82) {
    console.log('checkReset triggered formReset function');
    formReset();
  }
}

function formReset() {
  window.clearInterval(intId);
  intId = null;
  document.getElementById('pauseBtn').removeEventListener('click', pause);
  erase();
}

function pause() {
  //intId = window.setInterval(step, 1000 * dt);

  console.log('from within the pause function');

  var stab = document.getElementById('pauseBtn');
  if (intId == null) {
    intId = window.setInterval(step, 1000 * dt);
    stab.innerHTML = 'Pause';
  } else {
    window.clearInterval(intId);
    intId = null;
    stab.innerHTML = 'Resume';
  }
}

document.getElementById('saveBtn').addEventListener('click', function(e) {

  canvas.toBlob(function(blob) {
    saveAs(blob, "pretty image.png");
  });
});

function erase() {

  console.log('from inside the erase function');

  ctx.setTransform(1, 0, 0, 1, 0, 0);
  ctx.rotate(0);
  ctx.translate(0, 0);

  ctx.moveTo(0, 0);

  revolutions = 0;

  centerX = canvas.width / 2;
  centerY = canvas.height / 2;

  theta = 0;
  revolutions = 0;
  s = 256;
  t = 0.0;
  dt = 0.001;
  ns = 100000;
  setns = 100000;

  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = 'rgb(0,0,0)';
  ctx.fillRect(0, 0, canvas.width, canvas.height);

  document.getElementById('spf').innerHTML = s + "x";

  document.getElementById('animInput').setAttribute('class', 'center');
  document.getElementById('main').addEventListener('keyup', checkSubmit);
}
              
            
!
999px

Console