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.

              const frame = new Frame({color:black});
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
	let stage = frame.stage;
	let stageW = frame.width;
	let stageH = frame.height;

	// see for video and code tutorials
	// see for documentation
	// see for INTRO to ZIM
	// see for INTRO to CODE


	const space = new Container(5000, 4000).center();

	// create visual border
	// width, height, color, borderColor, borderWidth, corner, dashed
	new Rectangle(space.width, space.height, null, dark, 1, 30, true).addTo(space);

	// create planets
	const planets = new Container().addTo(space);
	planets.mouseEnabled = false; // let click go through to stage for MotionController
	loop(60, i=>{
		let planet = new Circle(rand(10,30), [green,blue,pink,red,purple], dark, rand(5,10))
		.loc(rand(0, space.width), rand(0, space.height), planets)
		planet.num = i+1; // could use child index but will be changing layers later

	const lifeStar = new Circle(20, white, "rgba(255,255,255,.4)", 30).center(space);
	// new to ZIM at time of creation - not in docs yet
	// this will make planets move so lifeStar is in middle of screen
		lag:true // optional 

	// make lifeStar move by pressing down on screen 
	// this is a new setting for MotionController to keep motion moving as view follows target
	const mob = mobile();
	const controller = new MotionController({
		speed:mob?40:20, // optional
		damp:mob?.1:.02, // optional
		boundary:new Boundary(0,0,space.width,space.height), // also need to set in resize event
		container:space // important if target is in a container and not directly on stage

	// make labels for info
	const infoBox = new Container(200,100);
	const message = new Label({
	const terrain = new Label({

	// make a highlight ring
	const highlight = new Circle(80, null, white, 30, true).alp(.1);

	// capture movement of the target with the controller
	// test to see if hitting a planet and show matching message using API
	let count = 0;
	let currentPlanet = null;
	let dataShield = null;
	controller.on("moving", ()=>{
		// not necessary but can throttle hitTest 
		if (++count%20) {
			// loop through planets and see if hitting any
			// we will return true from the loop if we are
			let isPlanet = planets.loop(planet=>{						
				if (planet.hitTestCircles(lifeStar)) {
					// do not call api if already calling api (using a " " to know we are waiting)
					// and only call if it is a different planet than our currentPlanet
					if (message.text != " " && planet!=currentPlanet) {
						// here is the API call and we insert the planet num
						var api = `${planet.num}/?format=json`;
						// ZIM async() uses JSONp 
						// the api returns JSON not JSONp so filter it through a PHP script 
						// You can too - or a sample PHP script is at the bottom of the code
						// JSONp needs a callback and async requires a dot between async and the callback 
						// we also must pass the real reference to the function as the second parameter
						async(`${api}&callback=async.planetInfo`, planetInfo);
						message.text = " "; // use a " " to know we are waiting
						terrain.text = ""; // also clear terrain text
						dataShield = timeout(500, ()=>{
							// in case data is down - or sluggish
							terrain.text = "...shields are up...";
						currentPlanet =; // move planet to top
						planet.uncache(); // we will add highlight and infoBox to planet so uncache,-130);;
					return true; // still hitting planet
			// test to see the results of the loop - if no hit then reset message
			if (!isPlanet && currentPlanet) {
				message.text = "";
				terrain.text = "";
				currentIndex = -1;
				currentPlanet = null;
				if (dataShield) dataShield.clear();

	// this gets called by async when data is returned
	function planetInfo(data) {
		// zog(data)
		if (dataShield) dataShield.clear();
		message.text =;
		terrain.text = data.terrain;
		infoBox.animate({alpha:1}, 500);
	// make intro
	new Label({
		backing:new Rectangle(600,140,black,tin,30,0,true).centerReg()

	// call remote script to make ZIM Foundation for Creative Coding icon
	var icon;  

	// in full mode we are responsible for scaling and positioning 
	// as the frame resizes - in "fit" mode we don't need to worry
	frame.on("resize", ()=>{
		stageW = frame.width;
		stageH = frame.height;
		if (icon) icon.pos(30,30,true,true);
		frame.followBoundary = new Boundary(0,0,stageW,stageH);

	stage.update(); // this is needed to show any changes

	// missing follow in Frame docs - pre-release ZIM 10.5.2

	// SAMPLE PHP for converting JSON to JSONp 
	// <?php
	// $api = $_GET["api"];
	// if (!preg_match('/^http/i', $api)) exit;
	// $callback = $_GET["callback"];
	// header('Content-Type: application/javascript');
	// $data = file_get_contents($api);
	// echo $callback."(".$data.")";
	// ?>

}); // end of ready
🕑 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.