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.

              <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>
			<canvas id="canvas" width="300" height="488"></canvas>

              @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;
#draggable { 
	width: 30px; height: 30px;
	border:4px solid rgba(255,25,25,.8); 
h2 {
  font-weight: 400;
  color: rgba(255,25,25,.8);
  font-weight: 800;
	border:2px solid #ccc;
	margin: 0 auto;

              // 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,

	init( options );
  $(original).on( 'load', draw ); // Draw as soon as the image is loaded
	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});

		// Make the peephole draggable. Redraw on drag
		$peephole.draggable( {
			containment: original,
			drag: draw
	 * Do the actual drawing
	function draw( ) {
		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.drawImage(original, sx, sy, w, h, -2*w, 0, w, h );

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

		// Flip hor again (for quadrant left bottom)
		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");


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

	return {
		getImageData: getImageData
🕑 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.