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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <div class= "title">
		<div> </div>
		<div>
			<h1 > DNA + chaos game </h1>

			<div class="exampleDNA">
				<mark> &#x2731; Don't know where to find some awesome DNA sequences to copy / paste?  
					<a href="https://github.com/alojzije/visualize-dna/tree/master/exampleDNA" target="_blank"> &nbsp; Follow me!</a> 
				</mark>
			</div>
		</div>
	</div>

	
	<div class="container" >
		<div id="inputContainer">
			<div id="uploadContainer">
				<input id="chosenFile" size="33" placeholder="load txt file containing DNA sequence" disabled="disabled" />
				<div class="fileUpload btn">
					<span>upload</span>
					<input id="dnaFileInput" type="file" class="upload" />
				</div>
			</div>
			<br><br>	
			
			<textarea id="dnaTextArea" rows="12" cols="40" placeholder=" . . . or enter / paste a DNA sequence here"></textarea><br>
			
			<input id="dnaTxtButton" type="button" class="btn" value="  visualize  ">
      <span style="font-size:0.9em"> * Built with the amazing <a href="https://p5js.org/" target="_blank">p5.js</a></span>

		</div> 
 
		<div id="canvasOuterContainer">
			<div id="canvasContainer">
				<div id="canvas_1"></div>
				<div id="canvas_3"></div>
				<div id="canvas_2"></div>
				<div id="canvas_4"></div>
			</div>
		</div>
	</div>

              
            
!

CSS

              
                body, html{
	padding:0;
	margin:0;
	margin-left: 3%;
	font-size: 16px;
	font-family: 'Open Sans', 'Bitter', serif;

}
.title h1{
	color: #111;
	font-size: 3.5em;
	font-family: 'Open Sans', 'Bitter', serif;
}
.title > div {
	display: inline-block;	
	vertical-align: middle;

}
 .title img{
	margin: 2.2em 0.5em 0.2em 0;
}

#canvasOuterContainer{
	width: 50%;
	min-width: 360px;
	display: inline-block;
	float: right;
}
#canvasContainer{
	width: 350px;
	min-width: 350px;
	height: 350px;	
	display: inline-block;
	margin: 0 auto;
}


#canvasContainer >div{
	width: 171px;
	height: 171px;
	background-color: #ddd;
	display: inline-block;
}

#inputContainer{
	min-width: 20em;
	margin-right: 2em;
	display: inline-block;
}

#uploadContainer{
	min-width: 20em;
	display: inline-block;
	float: left;
}

.container {
	width: 100%;
	margin-top: 4.5em;
}

#canvas_4{
	    background: url(http://i57.tinypic.com/vg25a9.png);
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

.exampleDNA{
	letter-spacing: 0.04em;
	background-color: rgba( 255,170,0, 0.7);
	padding: 0.5em;
	font-size: 0.9em;

}
mark{
	border-top: 1px solid #222;
	border-bottom: 1px solid #222;
	background-color: rgba( 255,170,0, 0.0);
}
.fileUpload {
	position: relative;
	overflow: hidden;
	background-color: #fff;
	border: 1px solid #333;
	margin: 0 0 0.5em 0.6em;
}

.fileUpload input.upload {
	position: absolute;
	width:  100%;
	height: 100%;
	top:  0;
	right: 0;
	margin: 0;
	padding: 0;
	cursor: pointer;
	opacity: 0;
	filter: alpha(opacity=0);
}


#chosenFile{
	color: #666;
	border: none;
	border-bottom: 1px solid #333;
	background-color: #fff;
}


#dnaTextArea{
	border: 1px solid #333;
	resize: vertical;
	padding: 0.5em 0.2em 0em 0.2em;
	min-width: 20em;
}

#dnaTxtButton{
	margin-top: 0.9em;
	padding: 0.6em 1em;
	outline: none;
	background-color: rgba(255,255,255,0);
	border: 1px solid #333;

}

@media screen and (max-width: 1000px){
	#canvasOuterContainer{
	margin-top: 5em;
	float: left;

}
              
            
!

JS

              
                var lines = '';
var p5_1, p5_2, p5_3;
var visualizeCounter = -1;

window.onload = function(){
  var visualizeBtn = document.getElementById('dnaTxtButton');
  var dnaFileInput = document.getElementById('dnaFileInput');
  var dnaTextArea  = document.getElementById('dnaTextArea');
  var chosenFile   = document.getElementById("chosenFile");
  chosenFile.value  = '';
  dnaTextArea.value  = '';
  dnaFileInput.value = '';


  dnaFileInput.addEventListener('change', function(e){
    chosenFile.value = dnaFileInput.value;
    dnaTextArea.value = '';
    var file = dnaFileInput.files[0];
    if(file.type.match(/text.*/)){
      var reader = new FileReader();
      reader.onload = function(e){
        lines = reader.result;
      };
      reader.readAsText(file);
    }

  });

  visualizeBtn.addEventListener('click',function(e) {
    e.preventDefault();
    visualizeCounter = (++visualizeCounter)%3;
    if(dnaTextArea.value !== ''){
      lines = dnaTextArea.value;
      dnaFileInput.value = '';
      chosenFile.value  = '';
    }
    switch(visualizeCounter){
      case 0:
      if(!p5_1) 
        p5_1 = new p5(s, 'canvas_1');
      else
        redraw1(p5_1);
      break;
      case 2:
      if(!p5_2) {
        p5_2 = new p5(s, 'canvas_2');
        p5_2.stroke(255, 128, 128, 80);
      }
      else
        redraw1(p5_2);
      break;
      default:
      if(!p5_3) {
        p5_3 = new p5(s, 'canvas_3');
        p5_3.stroke(244, 115, 61, 80);
      }
      else
        redraw1(p5_3);
    }
  });
};

function redraw1(myp5){
  myp5.clear();
  myp5.background(200);
  myp5.loop();
  myp5.redraw();
}

var s = function(sketch){

  var xbound = 170;
  var ybound = 170;
  var px = xbound/2;
  var py = ybound/2;  
  var aminoacid = '';
  var i = 0;

  sketch.setup = function() {
      // put setup code here
      sketch.createCanvas(170,170);
      sketch.strokeWeight(2);
      sketch.stroke(0, 128, 128, 80);
      sketch.background(200);
     // noLoop();


   };

   sketch.draw = function (){
    var cnt = 50;
    while(--cnt){
      aminoacid = lines.charAt(i).toUpperCase();   
      switch(aminoacid){
        case 'A':
        px = px/2;
        py = (py+ybound)/2;
        break;
        case 'T':
        case 'U':
        px = (px+xbound)/2;
        py = (py+ybound)/2;
        break;
        case 'G':
        px = (px+xbound)/2;
        py = py/2;
        break;   
        case 'C':
        px = px/2;
        py = py/2;
        break; 
        default:
        break;    
      }

      if(++i >= lines.length){
        sketch.noLoop(); 
        i = 0;
        break;
      }
      sketch.point(parseInt(px),parseInt(py));
    }
  };
};




              
            
!
999px

Console