Pen Settings



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


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


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.


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.






                const frame = new Frame("fit", 1024, 768, blue, dark);
frame.on("ready", ()=>{ // ES6 Arrow Function - similar to function(){}
	zog("ready from ZIM Frame"); // logs in console (F12 - choose console)

	// often need below - so consider it part of the template
	const stage = frame.stage;
	const stageW = frame.width;
	const stageH = frame.height;
	// This ZIM example is at 10% the size of the delightful 
	// pen by Adir. 
	// Even if you remove the SVG, it is at 71%. 
	// And we think you will agree that ZIM is much more readable code. 

	// see for an intro example
	// see for video and code tutorials
	// see for documentation


	// draw a backing rectangle
	// note, alpha on border overlaps alpha on shape to still show border
	new Rectangle(600,550,black,black,4,70).alp(.1).center();

	// make a Nail class that extends a ZIM Container so we can put it on the stage
	class Nail extends Container {
		constructor(radius=20) {
			// this calls the Container and sets its origin and registration in the middle
			// like most circular items
			super(-radius, -radius, radius*2, radius*2);
			new Circle(radius, dark).addTo(this);
			// make the half highlight on the top
			new Circle({radius, color:silver, percent:50}).addTo(this).rot(-45);
			new Circle(radius*.85, tin).centerReg(this);
			new Rectangle(radius*2*.85, 3, dark).centerReg(this);

	// tile nails
	const radius = 16;
	const num = 9;
	const space = 20;
	const tile = new Tile(new Nail(radius), num, num, space, space).center();
	// loop through each nail and give it some adjustments
		nail.mouseChildren = false; // so target in mousedown is on nail not part of nail
		nail.getChildAt(3).rot(rand(-60,60)); // randomize the turn but leave highlight at top left
		if (!mobile()) nail.cache().hov(.7).sha(); // cache will unify the hover alpha

	// create a band each time we mousedown and move
	let band = null;
	let nail = null;
	let bandEvent = null;	
	let f = 1.02; // the scale factor on the band radius compared to nail
	let startPoint = null;
	tile.on("mousedown", e=>{
		nail =;
		startPoint = tile.localToGlobal(nail.x, nail.y); // get global location of nail
		// create a shape to draw band in
		band = new Shape().loc(startPoint).bot().ord(1).ble("difference"); // just above backing rectangle
		// bandEvent = nail.on("pressmove", drawBand);
		bandEvent = stage.on("stagemousemove", drawBand);
	// use mouseX and mouseY as moving but then snapped x and snapped y on pressup
	function drawBand(e, x, y) {
		if (x==null) x = frame.mouseX;
		if (y==null) y = frame.mouseY;
		// get the length of the band to the x and y
		// draw it horizontal and then rotate it to the x and y
		let length = dist(startPoint.x, startPoint.y, x, y);
			.a(0, 0, radius*f, 90*RAD, -90*RAD) // arc is in radians
			.lt(length, -radius*f) // top band line is -radius in y
			.a(length, 0, radius*f, -90*RAD, 90*RAD)
			.lt(0, radius*f) // bottom band line is +radius in y 
			.rot(angle(startPoint.x, startPoint.y, x, y))
	tile.on("pressup", e=>{
		//"pressmove", bandEvent); // remove the pressmove event"stagemousemove", bandEvent); // remove the pressmove event
		// use hitTestGrid to get the index of the tile that the mouse is nearest
		// width, height, cols, rows, x, y, offsetX, offsetY, spacingX, spacingY, local, type
		let index = tile.hitTestGrid(tile.width, tile.height, num,num, frame.mouseX,frame.mouseY);
		if (index!=null) { // do not use if (index) {} because index could be 0
			// the drawBand is expecting a global position 
			// so convert the location of the nearest nail to global
			let point = tile.getChildAt(index).localToGlobal(0,0);
			drawBand(null, point.x, point.y);
		} else {
	stage.update(); // this is needed to show any changes	


	// call remote script to make ZIM icon - you will not need this

}); // end of ready