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="wrapper">
    <div class="controls"><form>
        <select id="generator">
            <option value="mr">Generator: Math.random</option>
            <option value="randu" selected>Generator: RANDU</option>
            <option value="wh">Generator: Wichmann-Hill</option>
        </select>
        <br/>
        <br/>
        <div class="regenerate">
            <label for="mr-button">Math.random:</label>
            <input id="mr-button" type="button" value="Regenerate" disabled/>
        </div>
        <br/>
        <div class="seed randu">
            <label for="seed-randu">RANDU seed:</label>
            <input id="seed-randu" type="number" min="1" max="2147483647" step="1" value="1">
            <output for="seed-randu">(Range: 1 - 2147483647)</output>
        </div>
        <br/>
        <div class="seed A wh">
            <label for="seed-wh-A">WH seed A:</label>
            <input id="seed--wh-A" type="number" min="1" max="30268" step="1" value="1">
            <output for="seed-A">(Range: 1 - 30268)</output>
        </div>
        <div class="seed B wh">
            <label for="seed-wh-B">WH seed B:</label>
            <input id="seed--wh-B" type="number" min="1" max="30306" step="1" value="2">
            <output for="seed-wh-B">(Range: 1 - 30306)</output>
        </div>
        <div class="seed C wh">
            <label for="seed-wh-C">WH seed C:</label>
            <input id="seed--wh-C" type="number" min="1" max="30322" step="1" value="3">
            <output for="seed-C">(Range: 1 - 30322)</output>
        </div>   
    </form></div>
    <div id="random-box" class="scene"></div>
</div>
              
            
!

CSS

              
                body{
	margin-left: auto;
	margin-right: auto;
}

.wrapper{
	width: 600px;
	margin-left: auto;
	margin-right: auto;	
}

input[type="button"]{
	cursor: pointer;	
}

input[type="number"]{
	text-align: right;
	width: 100px;
}

input:disabled{
	visibility: hidden;	
}

label, output{
	display: inline-block;	
}

label{
	width: 100px;	
}

output{
	margin-left: 10px;
	color: #999999	
}

.scene{
	width: 600px;
	height: 600px;
	margin-top: 30px;
}
              
            
!

JS

              
                (function(){

	"use strict";
	
	$(".controls form")[0].reset();
	var $container = $("#random-box");
	

	var randu = function(seed){
		
		if(!isFinite(seed)){
			throw new Error("Seed not a finite number");
		}
		
		var x = Math.round(seed);
		var a = 65539;
		var m = Math.pow(2, 31);
	   
		if(x<1 || x>=m){
			throw new Error("Seed out of bounds");
		}
	
		return function(){
			x = (a*x)%m;
			return x/m;
		};
			
	};
	
	
	var wh = function(seeds){
	  
		if(seeds.length<3){
			throw new Error("Not enough seeds");
		}
	   
		var xA = Math.round(seeds[0]);
		var aA = 171;
		var mA = 30269;
	   
		var xB = Math.round(seeds[1]);
		var aB = 172;
		var mB = 30307;
	   
		var xC = Math.round(seeds[2]);
		var aC = 170;
		var mC = 30323;
		
		if(!isFinite(xA) || !isFinite(xB) || !isFinite(xC)){
			throw new Error("Seed not a finite number");
		}
	   
		if(Math.min(xA,xB,xC)<1 || xA>=mA || xB>=mB || xC>=mC){
			throw new Error("Seed out of bounds");
		}  
	
		return function(){
			xA = (aA*xA)%mA;
			xB = (aB*xB)%mB;
			xC = (aC*xC)%mC;
			return (xA/mA + xB/mB + xC/mC) % 1;
		};
		  
	};
	
	
	var generateData = function(nextRandom, nTriplets){
		var data = [];
		for(var i=0; i<nTriplets; i++){
			data.push({x:nextRandom(), y:nextRandom(), z:nextRandom()}); 	
		}
		return data;
	};
	
		
	
	var redraw = (function(container, sceneWidth, sceneHeight){
	
		var scene = new THREE.Scene();
		
		var renderer = new THREE.WebGLRenderer();
		renderer.setClearColor(0x222222);
		renderer.setSize(sceneWidth, sceneHeight);
	
		container.appendChild(renderer.domElement);
		

		(function createBox(){
			
			var material = new THREE.LineBasicMaterial({
				color: 0x999999,
				linewidth: 2
			});
			
			var geometry = new THREE.Geometry();
			geometry.vertices.push(new THREE.Vector3(0, 0, 0));
			geometry.vertices.push(new THREE.Vector3(0, 0, 1));
			geometry.vertices.push(new THREE.Vector3(0, 1, 1));
			geometry.vertices.push(new THREE.Vector3(1, 1, 1));
			geometry.vertices.push(new THREE.Vector3(1, 1, 0));
			geometry.vertices.push(new THREE.Vector3(1, 0, 0));
			geometry.vertices.push(new THREE.Vector3(0, 0, 0));
			geometry.vertices.push(new THREE.Vector3(0, 1, 0));
			geometry.vertices.push(new THREE.Vector3(0, 1, 1));
			geometry.vertices.push(new THREE.Vector3(0, 1, 0));
			geometry.vertices.push(new THREE.Vector3(1, 1, 0));
			geometry.vertices.push(new THREE.Vector3(1, 0, 0));
			geometry.vertices.push(new THREE.Vector3(1, 0, 1));
			geometry.vertices.push(new THREE.Vector3(0, 0, 1));
			geometry.vertices.push(new THREE.Vector3(1, 0, 1));
			geometry.vertices.push(new THREE.Vector3(1, 1, 1));
			
			scene.add(new THREE.Line(geometry, material));
			
		})();			
			

		var points = (function(){
			
			var name = "points";
			
			var pointMaterial = new THREE.MeshBasicMaterial({
				color: "rgb(73,145,248)",
				transparent: true,
				opacity: 0.5
			});
			
			var clearPoints = function(){
				scene.remove(scene.getObjectByName(name));
			};
			
			var addPoint = function(coords){
				var pointSize = 0.015;
				var pointGeometry = new THREE.BoxGeometry(pointSize, pointSize, pointSize);
				var point = new THREE.Mesh(pointGeometry, pointMaterial);
				point.position.x = coords.x;
				point.position.y = coords.y;
				point.position.z = coords.z;
				return point;
			};
						
			var createPoints = function(data){
				var geometry = new THREE.Geometry();
				var n = data.length;
				for (var i=0; i<n; i++){
					var pointMesh = addPoint(data[i]);
					pointMesh.updateMatrix();
					geometry.merge(pointMesh.geometry, pointMesh.matrix);
				}
				var points = new THREE.Mesh(geometry, pointMaterial);
				points.name = name;
				scene.add(points);
			};
			
			return Object.freeze({
				clear: function(){clearPoints(); return this;},
				create: function(data){createPoints(data); return this;}
			});
			
		})();
		
		
		var render = (function(){
			
			var camera = new THREE.PerspectiveCamera(45, sceneWidth/sceneHeight, 1, 500);
			camera.position.x = 2;
			camera.position.y = 2;
			camera.position.z = 1.75;
			camera.up = new THREE.Vector3(0, 0, 1);
			camera.lookAt(scene.position);
			
			var controls = new THREE.TrackballControls(camera, renderer.domElement);
			controls.target.set(0.5, 0.5, 0.5); //rotate around centre of box
			
			var clock = new THREE.Clock();	
			
			return function(){
				requestAnimationFrame(render);
				controls.update(clock.getDelta());
				renderer.render(scene, camera);
			};
			
		})();
		
		render();
		
		
		return function(data){
			points.clear().create(data);
		};
		
		
	})($container[0], parseInt($container.css("width"),10), parseInt($container.css("height"),10));
	
	
	var info = {
		generator: undefined,
		randuSeed: undefined,
		whSeeds: []
	};

	
	var update = function(info){
		var n = Math.floor(10000/3);
		var data = [];
		var generator = info.generator;
		if(generator==="mr"){
			data = generateData(Math.random, n);
		} else if(generator==="randu"){
			data = generateData(randu(info.randuSeed), n);
		} else if(generator==="wh"){
			data = generateData(wh(info.whSeeds), n);	
		}
		redraw(data);
	};

	(function(){
				
		var getSeed = function($input){
			
			var valString = $input.val();
			var valInt = parseInt(valString, 10);
			
			if(!isFinite(valInt)){ //if we don't have a number at all
				valInt = parseInt($input.attr("value"), 10); //reset
				$input.val(valInt);
			}
			
			var valFloat = parseFloat(valString);
			var valMin = parseInt($input.attr("min"), 10);
			var valMax = parseInt($input.attr("max"), 10);
			
			if(valFloat !== valInt){ //if we don't have an integer...
				$input.val(valInt); //then set input box so that we do...
			}
			
			if(valInt < valMin){ //too small
				valInt = valMin;
				$input.val(valInt);
				
			} else if(valInt > valMax){ //too big
				valInt = valMax;
				$input.val(valInt);	
			}
			
			return valInt;
		};
		
		
		(function(){
		
			var $randuSeed = $(".seed.randu input");
			
			var setSeedInfo = function(){
				info.randuSeed = getSeed($randuSeed);	
			};
			setSeedInfo();
		
			$randuSeed.on("change", function(){
				setSeedInfo();
				update(info);
			});
		
		})();
		
		
		$(".seed.wh input").each(function(index){
		
			var $seed = $(this);
			
			var setSeedInfo = (function(){
				var seedIndex = index;
				return function(){
					info.whSeeds[seedIndex] = getSeed($seed);
				};
			})();
			
			setSeedInfo();
		
			$seed.on("change", function(){
				setSeedInfo();
				update(info);
			});
			
		});
		
	})();
	//.trigger("change");
	
	
	$("div.regenerate input").on("click", function(){update(info);});
	
	
	var changeDisabled = (function(){
		
		var $mrButton = $("div.regenerate input");
		var $randuSlider = $("div.seed.randu input");
		var $whSliders =  $("div.seed.wh input");
		
		return function(generator){
			
			if(generator === "mr"){
				$mrButton.prop("disabled", false);
			} else{
				$mrButton.prop("disabled", true);
			}
			
			if(generator === "randu"){
				$randuSlider.prop("disabled", false);
			} else{
				$randuSlider.prop("disabled", true);
			}
			
			if(generator === "wh"){
				$whSliders.prop("disabled", false);
			} else{
				$whSliders.prop("disabled", true);
			}
				
		};
		
	})();	
	
	
	$("#generator").on("change", function(){
		var generator = $(this).val();
		changeDisabled(generator);
		info.generator = generator;
		update(info);
	})
	.trigger("change"); //ultimately draws the scene
	

})();
              
            
!
999px

Console