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.

Rubiks' Snake Demo;

I had challenged myself to build a randomly rotating Rubik's Snake in 10 minutes. It totally took me 54 minutes to complete, but that's okay. I think it turned out rather decently. Yes, I realize that this shape may rotate into itself at random, and that's okay too.

There is no interactivity to this demo other than moving your mouse, which should change the offset of the root triangle.

Built with NPOS3D:
              var n = NPos3d,
scene = new n.Scene(),
    //This shape was modeled in Blender, exported to OBJ and converted to JSON via OBJ parsing script:
    triangleShape = {"points":[[-0.768579,-0.89,1],[-0.91,-0.99,0.9],[-0.939289,-0.919289,0.9],[0.99,-0.89,0.9],[0.89,-0.99,0.9],[0.89,-0.89,1],[0.919289,0.939289,0.9],[0.99,0.91,0.9],[0.89,0.768579,1],[-0.939289,-0.919289,-0.9],[-0.91,-0.99,-0.9],[-0.768579,-0.89,-1],[0.89,-0.89,-1],[0.89,-0.99,-0.9],[0.99,-0.89,-0.9],[0.89,0.768579,-1],[0.99,0.91,-0.9],[0.919289,0.939289,-0.9],[0.99,-0.5,0],[0.99,0,0.5],[0.99,0.5,0],[0.99,0,-0.5],[1,-0.5,0],[1,0,0.5],[1,0.5,0],[1,0,-0.5]],"lines":[[0,5],[0,8],[0,1],[0,2],[1,4],[1,2],[1,10],[2,9],[2,6],[3,14],[3,4],[3,5],[3,7],[4,5],[4,13],[5,8],[6,17],[6,7],[6,8],[7,8],[7,16],[9,11],[9,10],[9,17],[10,11],[10,13],[11,12],[11,15],[12,13],[12,15],[12,14],[13,14],[14,16],[15,17],[15,16],[16,17],[18,21],[18,22],[18,19],[19,20],[19,23],[20,24],[20,21],[21,25],[22,23],[22,25],[23,24],[24,25]]},
lastColor = 0,
colors = [
myControlOb = new n.Ob3D({
	shape: triangleShape,
	scale: [20, 20, 20],
	color: colors[0]
triangleList = [];
randomInt = function(max){
	return Math.round(Math.random() * max);
addTriangle = function(){
	lastColor = (lastColor + 1) % 2;
	var triangle = new n.Ob3D({
		shape: triangleShape,
		pos: [2, 0, 0],
		rot: [pi, 0, deg * -90],
		color: colors[lastColor]
	lastTriangleIndex = triangleList.length -1;
	console.log('addTriangle:\n\tlastTriangleIndex', lastTriangleIndex, '\n\tcurrentTriangleIndex',triangleList.length);
	if(lastTriangleIndex === -1){
		console.log('\n\tadding to myControlOb', myControlOb);
	} else {
		console.log('\n\tadding to lastTriangle', triangleList[lastTriangleIndex]);
flip = [-1, 1],
//SinusoidalInOut source: https://github.com/sole/tween.js/blob/master/src/Tween.js
SinusoidalInOut = function(k){return 0.5 * ( 1 - Math.cos( Math.PI * k ) );},
rotateTriangle = function(triangleIndex){
	var triangle = triangleList[triangleIndex],
		newRot = triangle.rot.slice();
		newRot[0] += (deg * 90) * flip[randomInt(1)];
	new n.Fx.Tween({
		object: triangle,
		properties: {
			rot: newRot
    method: SinusoidalInOut,
    frames: 20,
		callback: rotateRandomTriangle
rotateRandomTriangle = function(){
	var triangleIndex = randomInt(triangleList.length - 1);
	console.log('rotateRandomTriangle:', triangleIndex);
myControlOb.update = function() {
	var t = this;
	t.pos[0] = scene.mpos.x;
	t.pos[1] = scene.mpos.y;

for(var i = 0; i < 20; i += 1){
🕑 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.