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

              
                <div id="wrap">
  <h2>Drag the <span>red square</span> over the left-hand image.</h2>
			<div id="container">
				<div id="draggable" class="ui-widget-content"></div>
				<a href="https://www.flickr.com/photos/potatodie/16112235816" title="hazelaar from unknown source, on Flickr"><img src="https://farm9.staticflickr.com/8629/16112235816_a79704fbc8_o.jpg" width="300" height="488" alt="hazelaar"></a>
			</div>
			<canvas id="canvas" width="300" height="488"></canvas>

		</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,800);
/* Web Fonts @import */
body {
  font: 400 normal 110%/1.3 "Open Sans", sans-serif;
  margin: 0; }
#canvas {
	border:0px solid #ccc;
	float:right;
}
#draggable { 
	width: 30px; height: 30px;
	border:4px solid rgba(255,25,25,.8); 
background:rgba(200,200,200,0.23);
	position:absolute;
	cursor:move;
}
h2 {
  font-weight: 400;
}
span{
  color: rgba(255,25,25,.8);
  font-weight: 800;
}
#container
{
	margin-right:20px;
	position:relative;
	float:left;
}
#orig
{
	border:2px solid #ccc;
	
}
#wrap
{
	width:650px;
	text-align:center;
	margin: 0 auto;
}

              
            
!

JS

              
                <!-- Tinkering fruit potatoDie (potatodie.nl) -->
$(function() {
	// Setup kaleidoscope with dom elements and perhaps start coordinates
	var kaleidoscope = new Kaleidoscope90 ( {
		peephole: document.getElementById('draggable'),
		original: $("#container img")[0],
		outputCanvas: document.getElementById('canvas'),
		x: (typeof start_x === 'undefined') ? 92 : start_x,
		y: (typeof start_y === 'undefined') ? 132 : start_y
	});
});

/**
 * Kaleidoscope90 repeats a reflected and rotated square (tile)
 * Initialize it with the necessary DOM elements
 */
var Kaleidoscope90 = function ( options ) {
	var $peephole,
			peepholeWidth,
			peepholeHeight,
			original,
			outputCtx,
			tileCanvas,
			tileCanvasCtx;

	init( options );
	
	function init ( options ) {
		$peephole = $(options.peephole);
		peepholeWidth = $peephole.width();
		peepholeHeight = $peephole.height();
		original = options.original;
		outputCtx = options.outputCanvas.getContext('2d');

		tileCanvas = document.createElement("canvas");
		tileCanvas.width = peepholeWidth * 2;
		tileCanvas.height = peepholeHeight * 2;
		tileCanvasCtx = tileCanvas.getContext("2d");

		$peephole.css ( {left: options.x, top: options.y});
		draw();

		// Make the peephole draggable. Redraw on drag
/*		$peephole.draggable( {
			containment: original,
			drag: draw
		});*/
////////////////////////////////////////
////////////////////////////////////////
    Draggable.create('#draggable', {
      bounds:'#container',
      edgeResistance:0.65,
      type:"x,y",
      throwProps:true,
      onDrag: draw,
      onThrowUpdate:draw
    })
////////////////////////////////////////
////////////////////////////////////////
	}
	
	/**
	 * Do the actual drawing
	 */
	function draw( ) {
		createTile();
		fill( tileCanvas, outputCtx );
	}

	/**
	 * Create tile (on a canvas dedicated to that purpose) using copies of peephole
	 * @return none: the canvas is a closure var
	 */
	function createTile () {

		var sx = $peephole.position().left,
				sy = $peephole.position().top,
				w = peepholeWidth,
				h = peepholeHeight,
				ctx = tileCanvasCtx; // Reuse of canvas (for performance optimization)

		// Copy peephole unaffected
		ctx.drawImage(original, sx, sy, w, h, 0, 0, w, h);

		// Mirror horizontal and draw on the right spot
		ctx.scale(-1,1); 
		ctx.drawImage(original, sx, sy, w, h, -2*w, 0, w, h );

		// Flip vertically too (quadrant roght bottom)
		ctx.scale(1,-1);
		ctx.drawImage( original, sx, sy, w, h, -2*w, -2*h, w, h)

		// Flip hor again (for quadrant left bottom)
		ctx.scale(-1,1);	
		ctx.drawImage( original, sx, sy, w, h, 0, -2*h, w, h)
	}	

		
	/**
	 * Fill canvas with tile
	 */
	function fill ( tile, ctx ) {

		outputCtx.rect(0, 0, outputCtx.canvas.width, outputCtx.canvas.height);
		outputCtx.fillStyle = outputCtx.createPattern(tile, "repeat");
		outputCtx.fill();

	}

	/**
	 * export data
	 * @return {ImageData} Resulting graphics
	 */
	function getImageData () {
    // For the future
	}

	return {
		getImageData: getImageData
	}
};
              
            
!
999px

Console