Pen Settings

HTML

CSS

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

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

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.

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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                const frame = new Frame("fit", 1024, 768, "#A496A4".lighten(.8), "#A496A4".lighten(.3));
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;

	// REFERENCES for ZIM at https://zimjs.com
	// see https://zimjs.com/intro.html for an intro example
	// see https://zimjs.com/learn.html for video and code tutorials
	// see https://zimjs.com/docs.html for documentation
	// see https://codepen.io/topic/zim/ for ZIM on CodePen
	
	// *** NOTE: ZIM Cat defaults to time in seconds
	// All previous versions, examples, videos, etc. have time in milliseconds
	// This can be set back with TIME = "milliseconds" but we suggest you give it a try!
	// There will be a warning in the conslole if your animation is not moving ;-)

	// CODE HERE
	
	// The AHA Game 
	// Try and find the square that is not changing 
			
	const colors = ["#A5A7BB", "#A496A4", "#554d73"];
	const size = 520; // size of game tile
	let num = 4; // number of tiles per col or row
	
	// Just some design - a backing focus rectangle
	new Rectangle(900,530,"#A5A7BB",yellow).alp(.2).loc(50,70)
	
	// Backing rectangle for game tile
	new Rectangle(size+5,size+5,dark).rot(45).center();
	
	// When we get the right square we emit particles 
	// These will be the same size as the tile 
	// but the tile sizes can be changed 
	// So... we could make a new emitter each time 
	// or there is a better solution below:
	
	// ZIM has dynamic parameters - called ZIM VEE values or Pick Objects
	// This means, we can pass in a ZIM VEE value to the obj parameter 
	// Each time the particle is made inside it will pick from the ZIM VEE value
	
	// Different ZIM VEE values are as follows:
	// [1,3,2] - random
	// {min:10, max:20} - range
	// series(1,2,3) - order, 
	// function(){return result;} - function
	
	// We want to make a particle the size of the current tile
	// so we can use a function to make the particle
	// and then pass the function to the Emitter
	
	// Note that the Rectangle being made also uses a ZIM VEE value 
	// It is using the colors array to pick randomly from the color
	// This would not work without ZIM VEE system
	
	function makeParticle() {
		return new Rectangle(size/num,size/num, colors, dark).rot(45);
	}
	
	const emitter = new Emitter({
		obj:makeParticle,
		startPaused:true,
		gravity:0,
		force:{min:10, max:20}
	});
	
	// One square will always stay the same color
	// This is the function to start each round 
	// and set the correct square and its color
	let correct = null;
	function startRound() {
		correct = rand(num*num-1); // 0-value
		correctColor = shuffle(colors)[0];	
		emitter.clearPool(); // emitter pools particles - which could be the wrong size
	}
	startRound();	
	
	// Create the tile in an interval
	// We can pause and change the speed of a ZIM interval
	// We will get rid of the old tile if there is one 
	// and make a new tile each time 
	// Passing in the colors array will make the tile pick randomly from the colors 
	// each time it makes a time - this is ZIM VEE again
	
	let tile = null;
	timer = interval(.6, ()=>{
		if (tile) tile.removeFrom();
		tile = new Tile(new Rectangle(size/num,size/num,colors,dark).centerReg(), num, num)
			.rot(45)
			.cur()			
			.centerReg(stage, 2) // above backing rectangles		
		tile.on("mousedown", ()=>{
			wrong.score++;
		});
		
		let correctTile = tile.getChildAt(correct);
		// correctTile.borderColor = red;
		correctTile.color = correctColor;
		correctTile.on("mousedown", ()=>{
			emitter.loc(correctTile).spurt(10);
			// go to next level
			num++;
			if (num > dial.max) num = dial.min;
			dial.currentValue = num;
			right.score++;
			wrong.score--; // wrong value will also go up so fix that
			startRound();
		}, null, true); // only click once on correct tile
			
		stage.update();
		
	}, null, true); // start interval right away
	
		
	
	// INTERFACE
	
	STYLE = {
		backgroundColor:"#554d73".lighten(.3),
		toggleBackgroundColor:"#A5A7BB",
		color:"#554d73",
		shadowColor:"none",
		font:"impact",
		size:30,
		shiftVertical:2 // for Impact font adjust on Toggle
	}
	
	// We decided after making the interface to animate it  
	// We spent a couple minutes adding it to a Container 
	// so we can animate them all with one animate call 
	// We make the container the same size as the stage 
	// and that will mean we do not have to reposition the interfaces
	// as we had already made and positioned relative to the stage
	
	// Note, again, because we had already placed the objects,
	// it is easier to animate from some other property to its final property 
	// This also has the advantage of being able to "bypass"
	// all the animations with the ANIMATE constant set to false 
	// Uncomment this line to see - this is good for saving time while developing
	
	// ANIMATE = false;
	
	const interface = new Container(stageW, stageH)
		.addTo()
		.animate({
			from:true,
			wait:1,
			props:{y:300},
			ease:"backOut",
			time:.7
		})
	
	const dial = new Dial({min:4, max:12})
		.pos(70,30,LEFT,BOTTOM,interface)
		.change(e=>{
			num = e.target.currentValue;
			startRound();			
		});
	
	new Toggle({label:"PAUSE"})
		.sca(.7)
		.pos(200,30,LEFT,BOTTOM,interface)
		.change(e=>{
			timer.pause(e.target.toggled);
		});
	
	new Slider({
		barLength:150, 
		min:1, max:.2, 
		button:"aztec",
		useTicks:true,
		step:.1,
		currentValue:.6
	})
		.sca(1.1)
		.pos(150,45,RIGHT,BOTTOM,interface)			
		.change(e=>{
			timer.time = e.target.currentValue;
		});
		
	STYLE = {font:"impact", color:"#554d73"};
			
	new Label("A-HA GAME!", 60)
		.centerReg()
		.loc(194, 210)
		.rot(-45)
			.animate({
				from:true,
				props:{scale:0},
				time:.5,
				ease:"backOut",
				wait:.3		
			})
		// .place();
	new Label("PRESS SQUARE THAT DOES NOT CHANGE", 20)
		.centerReg()
		.alp(.6)
		.loc(233, 232)
		.rot(-45)
		.animate({
			from:true,
			props:{scale:0},
			time:.5,
			wait:.6,
			ease:"backOut"
		})
		// .place();
	
	// make a Container for the top interface as well
	// this was done after the creating the interfaces 
	// it just took a couple minutes to do this 
	// so we can animate these in together 
	// We could animate them individually if desired
	// in which case, they would not have to be in a container
	const scores = new Container(stageW, stageH)
		.addTo()
		.animate({
			from:true,
			props:{y:-300},
			time:.7,
			ease:"backOut",
			wait:1.3			
		})
	
	new Label("RIGHT").sca(.5).loc(880, 30, scores);
	new Label("WRONG").sca(.5).loc(880, 150, scores);
	
	STYLE = {};
	
	const right = new Scorer({backgroundColor:"#A5A7BB"}).pos(50,50,RIGHT,TOP,scores)
	const wrong = new Scorer({backgroundColor:"#A496A4"}).pos(50,170,RIGHT,TOP,scores)
	

	// DOCS FOR ITEMS USED
	// https://zimjs.com/docs.html?item=Frame
	// https://zimjs.com/docs.html?item=Container
	// https://zimjs.com/docs.html?item=Rectangle
	// https://zimjs.com/docs.html?item=Label
	// https://zimjs.com/docs.html?item=Toggle
	// https://zimjs.com/docs.html?item=Slider
	// https://zimjs.com/docs.html?item=Dial
	// https://zimjs.com/docs.html?item=change
	// https://zimjs.com/docs.html?item=animate
	// https://zimjs.com/docs.html?item=cur
	// https://zimjs.com/docs.html?item=pos
	// https://zimjs.com/docs.html?item=loc
	// https://zimjs.com/docs.html?item=alp
	// https://zimjs.com/docs.html?item=rot
	// https://zimjs.com/docs.html?item=sca
	// https://zimjs.com/docs.html?item=addTo
	// https://zimjs.com/docs.html?item=removeFrom
	// https://zimjs.com/docs.html?item=centerReg
	// https://zimjs.com/docs.html?item=center
	// https://zimjs.com/docs.html?item=place
	// https://zimjs.com/docs.html?item=Tile
	// https://zimjs.com/docs.html?item=Emitter
	// https://zimjs.com/docs.html?item=shuffle
	// https://zimjs.com/docs.html?item=rand
	// https://zimjs.com/docs.html?item=timeout
	// https://zimjs.com/docs.html?item=interval
	// https://zimjs.com/docs.html?item=series
	// https://zimjs.com/docs.html?item=lighten
	// https://zimjs.com/docs.html?item=zog
	// https://zimjs.com/docs.html?item=STYLE
	// https://zimjs.com/docs.html?item=ANIMATE

	// FOOTER
	// call remote script to make ZIM icon - you will not need this
	timeout(2, function(){
		createIcon();
	});

}); // end of ready
              
            
!
999px

Console