Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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>  
 <head> 
 <title>Function System Iterator in Javascript using Canvas</title>
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/jquery-ui.min.js"></script>
<LINK REL=StyleSheet HREF="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.19/themes/ui-lightness/jquery-ui.css" TYPE="text/css" MEDIA="screen">
<LINK REL=StyleSheet HREF="IFS.css" TYPE="text/css" MEDIA="screen">
 
  <script type="application/javascript" src="IFS.js"></script> 
    <script type="application/javascript" src="IFSApp.js"></script> 
  <script type="application/javascript">
var counter;
  $(document).ready(function(){
	counter = 2.0;
  });
  
  </script>
    
  <link rel="stylesheet" type="text/css" 
media="screen" href="CellAuto.css">
 </head>  
 <body onload="IFSApp.init(1280,720);" >  
  <div class="container">
  <div id="ui">
  
  <input type="text" name="countfield" class="countfield" value="10000" />
  
  <div class="matrix-ui round">
  <div class="header" >Transform A</div> 
  <input type="text" name="a0" class="matrixfield" value="0.5" /><input type="text" name="a1" class="matrixfield" value="0" /><input type="text" name="a2" class="matrixfield" value="0.5" />
  <input type="text" name="b0" class="matrixfield" value="0" /><input type="text" name="b1" class="matrixfield" value="0.5" /><input type="text" name="b2" class="matrixfield" value="0.5" />
  <input type="text" name="c0" class="matrixfield" value="0" /><input type="text" name="c1" class="matrixfield" value="0" /><input type="text" name="c2" class="matrixfield" value="0.5" />
  <div class="clear"></div>
  <div class="inline">%</div><input type="text" name="ta0" class="matrixfield" value="0.33" />
  </div>
  
  <div class="matrix-ui round">
  <div class="header" >Transform B</div> 
  <input type="text" name="a0" class="matrixfield" value="0.5" /><input type="text" name="a1" class="matrixfield" value="0" /><input type="text" name="a2" class="matrixfield" value="0" />
  <input type="text" name="b0" class="matrixfield" value="0" /><input type="text" name="b1" class="matrixfield" value="0.5" /><input type="text" name="b2" class="matrixfield" value="0.5" />
  <input type="text" name="c0" class="matrixfield" value="0" /><input type="text" name="c1" class="matrixfield" value="0" /><input type="text" name="c2" class="matrixfield" value="0.5" />
  <div class="clear"></div>
  <div class="inline">%</div><input type="text" name="ta0" class="matrixfield" value="0.33" />
  </div>
  
  <div class="matrix-ui round">
  <div class="header" >Transform C</div> 
  <input type="text" name="a0" class="matrixfield" value="0.5" /><input type="text" name="a1" class="matrixfield" value="0" /><input type="text" name="a2" class="matrixfield" value="0" />
  <input type="text" name="b0" class="matrixfield" value="0" /><input type="text" name="b1" class="matrixfield" value="0.5" /><input type="text" name="b2" class="matrixfield" value="0" />
  <input type="text" name="c0" class="matrixfield" value="0" /><input type="text" name="c1" class="matrixfield" value="0" /><input type="text" name="c2" class="matrixfield" value="0.5" />
  <div class="clear"></div>
  <div class="inline">%</div><input type="text" name="ta0" class="matrixfield" value="0.33" />
  </div>
  <button id="iterate-btn" class="round">Iterate!</button>
  <button id="reset-btn" class="round">Reset</button>
  
  
  </div>
    <div id="canvasdiv" class="round border shadow">
    <canvas id="canvas" width="1280px" height="720px"></canvas>  
    </div>
   
 </body>  
</html> 
            
          
!
            
              body{
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:70%;
background-color:#EDF5F3;
letter-spacing:0.06em;
}

.matrixfield, .countfield{
   background-color: #AAAAAA;
    border: 1px solid #888888;
    color: white;
  


}

.matrixfield{
    margin: 2px;
    width: 35px;
      float: left;
}
.countfield{
width:132px;
margin-bottom:10px;
}

#ui{
width:132px;
float:left;
padding:30px 10px  10px 10px;
}
.matrix-ui{
background-color:#AAAAAA;
margin: 0 0 10px 0 ;
height:118px;
}

.clear{
clear:both;
}



.inline{
float:left;
margin-left:37px;
}

.header{
clear:both;
background-color:#000000;
color:white;
padding:4px;
}
#canvasdiv{
float:left;
background-color:#FFFFFF;
}

#iterate-btn, #reset-btn{
	color:white;
	background-color:#aaa;
	width:60px;
	margin:0;

}
#iterate-btn{
margin-left:2px;
}

.round {
     -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    -khtml-border-radius: 5px;
    border-radius: 5px;
}
.border{
border: 1px #AAA solid;
}
.shadow {
  -moz-box-shadow:    1px 1px 3px 1px #ccc;
  -webkit-box-shadow: 1px 1px 3px 1px #ccc;
  box-shadow:         1px 1px 3px 1px #ccc;
}
.container{
    margin-left: auto;
    margin-right: auto;
    margin-top: 50px;
    width: 1480px;

}
            
          
!
            
              

(function( global ) {
  var IFSApp = (function() {

    // these are private variables
    //var data = "secret";
    //var numRows = -1;
    //var numCols = -1;
    var cellsX = [];
    var cellsY = [];
    var cellColors = [];

	var Color = function(r_in,g_in,b_in) {  
  this.r = Math.floor(r_in);
  this.g = Math.floor(g_in);
  this.b = Math.floor(b_in); 
}

	var w;
	var h;
	var count;
	var i;
	var j;
	var iterations;
	var initialVals = [0.5,0,0.5,0,0.5,0.5,0,0,0.5,0.33,0.5,0,0,0,0.5,0.5,0,0,0.5,0.33,0.5,0,0,0,0.5,0,0,0,0.5,0.33];

	var matrices = [{
		a : [1,0,0],
		b : [0,1,0],
		c : [0,0,1],
		pct : 0.33
	},
	{
		a : [1,0,0],
		b : [0,1,0],
		c : [0,0,1],
		pct : 0.33
	},
	{
		a : [1,0,0],
		b : [0,1,0],
		c : [0,0,1],
		pct : 0.33
	}];


    return {
      // public properites
      //bool: true,
      //string: "a string",
      //array: [ 1, 2, 3, 4 ],
      //object: {
      //  lang: "en-Us"
      //},
      
      resetMatrices : function(){
      
      	for(i=0;i<$(".matrixfield").length;i++){
      	$(".matrixfield").eq(i).val(initialVals[i]);
      	//console.log("ok");
      	
      	}
      	this.init(w,h);
      
      },
      
      readMatrices : function(){
      
      
      for(i=0;i<$(".matrix-ui").length;i++){
      var f = $(".matrix-ui").eq(i).children().filter(".matrixfield");
      
      matrices[i].a = [ f[0].value, f[1].value, f[2].value ];
      matrices[i].b = [ f[3].value, f[4].value, f[5].value ];
      matrices[i].c = [ f[6].value, f[7].value, f[8].value ];
      matrices[i].pct = f[9].value;
      
      // console.log(parseFloat(matrices[i].pct));
      }
      
      },
      
      
      init : function(w_in,h_in){
       
       $('#iterate-btn').click(function(){
       IFSApp.readMatrices();
       IFSApp.iterate();
       // console.log(this);
       });
         $('#reset-btn').click(function(){
       IFSApp.resetMatrices();
       
       });
       
       count = $('.countfield').val();
       
       
       w = w_in;
        h = h_in;
       // iterations = iterations_in;
       
       // var inefficient = "";
           var canvas = document.getElementById("canvas");  
      		if (canvas.getContext) {  
            	var ctx = canvas.getContext("2d");  
            	ctx.clearRect ( 0,0,w,h );
            	var tx;
            	var ty;
            	for(i=0;i<count;i++){
            		tx = Math.random();
            		ty = Math.random();
            		cellsX[i] = tx;
            		cellsY[i] = ty;
            		cellColors[i] = new 
                // random color?
                 //Color(Math.random()*128,Math.random()*128,Math.random()*128);
                Color(0,0,0);
            	}
            	
            	for(j=0;j<count;j++){
            	//ctx.fillStyle="rgb(255,0,0)";
            	//console.log("rgb("+cellColors[j].r+","+cellColors[j].g+","+cellColors[j].b+")");
            	ctx.fillStyle = "rgb("+cellColors[j].r+","+cellColors[j].g+","+cellColors[j].b+")";
            		ctx.fillRect(cellsX[j]*w,cellsY[j]*h,2,2);
            	}
         
        	}
        	  // alert(inefficient);
        },
        
        iterate : function(counter){
   
        	var canvas = document.getElementById("canvas");  
      		if (canvas.getContext) {  
            	var ctx = canvas.getContext("2d");  
            	ctx.clearRect ( 0,0,w,h );

        		for(j=0;j<count;j++){
            			
            			
            			/*
            			var rand = Math.random();
            			// rand = 0.44;
            			//var prevX = cellsX[j];
            			//var prevY = cellsY[j];
            			if(rand>0.66){
            				cellsX[j] /= 2;
            				cellsY[j] /=2;
            				cellsX[j] += (-1.0/(counter));
            				cellsY[j] += (-1.0/(counter));
            				
            			} else if(rand>0.33){
            				cellsX[j] /= 2;
            				cellsY[j] /=2;
            				cellsY[j] += (1.0/(counter));
            				cellsX[j] += (-1.0/(counter));
            				
            			} else {
            				cellsX[j] /=2;
            				cellsY[j] /=2;
            				cellsX[j] += (1.0/(counter));
            				cellsY[j] += (1.0/(counter));
            				
            			}
            			//cellsX[j]+=prevX;
            			//cellsY[j]+=prevY;
            			
            			*/
            			
            			var x = cellsX[j];
            			var y = cellsY[j];
            			var z = 1;
            			
            			var rand = Math.random();
            			var t;
            			var secondGate = parseFloat(matrices[0].pct)+parseFloat(matrices[1].pct);
            			if(rand<matrices[0].pct){
            				t = matrices[0];
            			//	console.log(0,rand);
            			} else if(rand<(secondGate)){
            				t = matrices[1];
            			//	console.log(1,rand);
            			} else {
            				t = matrices[2];
            			//	console.log(2,rand);
            			}
            			//console.log(secondGate);
            			
            			cellsX[j] = t.a[0]*x+t.a[1]*y+t.a[2]*z;
            			cellsY[j] = t.b[0]*x+t.b[1]*y+t.b[2]*z;
            			
            			ctx.fillStyle = "rgb("+cellColors[j].r+","+cellColors[j].g+","+cellColors[j].b+")";
            		ctx.fillRect(cellsX[j]*w,cellsY[j]*h,2,2);	
            	}
            // console.log(counter);		
            	
            	
        	}
        }
        
        
      
    }
        
     
        
        
        
    
      
        
        
        

      

  })();

  // Other things might happen here

  // expose our module to the global object
  global.IFSApp = IFSApp;

})( this );
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console