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.






                import zim from "";

// see
// and
// and

const frame = new Frame(FIT, 1024, 768, darker, dark);
frame.on("ready", () => {
    const stage = frame.stage;
	const stageW = frame.width;
	const stageH = frame.height;
    // put your code here	
	// Create board and pieces using Tile 
	// could use loops, etc. but perhaps this is conceptually easier
	const a = pink;
	const b = purple;
	const c = white;
	const d = black;
	const s = 80;
	const colors = series(a,b,a,b,a,b,a,b).flip();	
    const board = new Tile(new Rectangle(s,s,colors),8,8).center();

	const colorsA = series(d,c,d,c,d,c,d,c).flip();
	const piecesA = new Tile(new Circle(s/2,colorsA),8,3).loc(board);
	const colorsB = series(d,c,d,c,d,c,d,c).flip();	
	const piecesB = new Tile(new Circle(s/2,colorsB),8,3).pos(0,0,LEFT,BOTTOM,board);
	// loop through the pieces and adjust them
	// while we are at it, add each piece to a pool to pick the next move from
	// if a piece is picked and it has no move it will be removed from the pool 
	// and another piece is picked
	// once the turn is over all the existing pieces get added to the pool again
	// store the pieces opposite side as other property
	piecesA.pool = [];
		if (piece.color!=c) piece.removeFrom();
		else {;
			piece.other = piecesB;
	}, true); // loop backwards when removing from container
	piecesB.pool = [];
		if (piece.color!=d) piece.removeFrom();
		else {;
			piece.other = piecesA;
	}, true); // loop backwards when removing from container
	// these are the directions that we can try to move each piece
	const directions = [{x:s,y:s},{x:-s,y:s},{x:s,y:-s},{x:-s,y:-s}];
	const emitter = new Emitter({startPaused:true});
	let pieces;
	let count = 0; // use this to figure the side we are moving
	function move() {
		pieces = count++%2==0?piecesB:piecesA;
		// ZIM loops have no continue nor break
		// but rather use return for continue
		// and return a value to break 
		// the return value goes is returned by the loop
		// NOTE: a return value of true is given to the loop 
		// if it finishes looping 
		// so here, we will eventually return a "done" to status
		// if the piece has taken another or moved to a square 
		let status = false;
		while(status!="done" && pieces.pool.length>0) {

			// grab a piece
			let piece = pluck(pieces.pool, true);	// remove from pool
			piece.start = {x:piece.x, y:piece.y}; // record where we start

			shuffle(directions); // just go any which way!
			status = loop(directions, d=>{ // get a movement

				// relocate the piece to start then do the movement
				if (!piece.hitTestBounds(board)) return; // continue the loop

				let attack = piece.other.loop(other=>{
					if (piece.hitTestBounds(other)) {
						return "success";
				if (attack == "success") return "done"; // breaks the loop

				let empty = piece.parent.loop(sibling=>{ // loop our own pieces
					if (sibling == piece) return; 
					if (piece.hitTestBounds(sibling)) return false;
				if (empty) return "done"; // otherwise will try another direction

			if (status != "done") piece.loc(piece.start);	
		// add all pieces back to pool - next time might be different arrangement
		pieces.pool = [];
		if (piecesA.numChildren==0 || piecesB.numChildren==0) {
		timeout(.3, move);
	function endGame() {
		frame.color = green;
			new Pane(stageW+40,200,"💙 CREATIVE CODING LESSONS on CODEPEN",yellow).show(()=>{
				zgo("", "_blank")
	// docs for items used