Pen Settings

HTML

CSS

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

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

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.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // ZIM is a JavaScript Canvas Framework for coding creativity!
// https://zimjs.com - please visit to start a wonderful coding journey.
// The main site has banner sections of TEN excellent uses of ZIM.

// NOTE - we often make colorful things with shapes - that is our style
// ZIM can be used very well with images, etc. if that is your style
// sound is also no problem - but sometimes slows down CodePen's preview...

// ZIM provides many conveniences, components and controls 
// to help designers, developers and artists create interactive media 
// https://zimjs.com/about.html - why ZIM, features, applications
// https://zimjs.com/docs.html - expand open any feature for info and examples

// Here are CodePen examples with comments for learning:
// https://codepen.io/zimjs/pens/public - ZIM CodePen
// https://codepen.io/danzen/pens/public - ZIM Founder's CodePen
// https://codepen.io/zimjs/post/welcome-to-zim-on-codepen

// There are also many tutorials, videos and references here:
// https://zimjs.com/learn.html - ZIM Skool, ZIM Kids, ZIM Badges, etc.
// https://zimjs.com/code.html - ZIM Template, tools and more
// https://zimjs.com/slack/ - join us on *** Slack *** for discussion and support

// -----------------

// ZIM is powered by CreateJS so we import CreateJS and ZIM in CodePen settings
// We make a Frame object which makes a stage on an HTML canvas 
// We then add objects to the stage and update the stage to see them 

const frame = new Frame("fit", 1024, 768, purple, purple);
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;
	let stageW = frame.width;
	let stageH = frame.height;

	// CODE HERE
	
	// ES6 Class that extends a ZIM Container 
	class Bee extends Container {
		constructor() {
			super(80,40); // must call superclass - CreateJS requirement
			let body = new Circle(30).siz(60,40).center(this); // this is the container
			new Tile(new Rectangle(5,60,yellow), 6, 1, 5, 0).center(body).setMask(body);
			body.cache(); // helps performance by turning vectors into bitmap
		}
	}
	
	// We have purple slants that need to match against the HTML outercolor
	// Relying on stage color can leave thin line artifact at edges during browser scaling
	// Try it if you want - comment this out and set color (first purple in Frame call) to pink
	new Rectangle(stageW, stageH, pink).addTo(); 
	
	// bees behind Grim
	const beesBack = new Container(stageW, stageH).rot(-5).sca(.8).alp(.6).centerReg();
	
	// points of Blob came from here https://zimjs.com/nio/paths.html
	const reaper = new Blob({
		color:black,
		points:[[-20,-142.4,0,0,-35.6,9.6,35.6,-9.6,"mirror"],[44.8,-78.3,0,0,-4.8,-28.8,41.6,-32,"free"],[160.9,-102.3,0,0,-28,-20,-31.4,3.1,"free"],[88.3,-68.3,0,0,23,-26.3,-38.6,-32.3,"free"],[69.6,4,0,0,-34.9,-40.6,42,48.7],[67.5,127.3,0,0,0,0,0,0,"none"],[2.4,121.6,0,0,36.7,0,-36.7,0,"mirror"],[-69.6,131.2,0,0,0,0,0,0,"none"],[-25.6,-3.2,0,0,24,47.4,-24,-47.4,"mirror"]],
		interactive:false
	}).sca(2.5).center().mov(0,100)
		// make Grim move around at SLOW speed
		.wiggle("x", stageW/2, 50, 100, 20000, 30000) // prop, start, min, max, minTime, maxTime
		.wiggle("y", stageH/2+100, 20, 50, 20000, 30000);	
	const mouth = new Circle(10, dark).sca(1,.7).rot(-10).loc(-8, -105, reaper);
	reaper.shape.cur(); // interactive false seems to keep cursor away so add to shape
	
	// bees in front of Grim
	const beesFront = new Container(stageW, stageH).rot(-5).centerReg();
	
	// move the bees along with the reaper
	Ticker.add(()=>{
		beesBack.loc(reaper).mov(0,-200);
		beesFront.loc(reaper).mov(0,-200);
	})
	
	// the two purple slants - fun!
	new Rectangle(stageW+500, 400, purple).reg(0,400).loc(0,0).rot(3);
	new Rectangle(stageW+500, 400, purple).loc(0,stageH).rot(-10);
	
	// make bees and wiggle them FAST!	
	// add some to front and some to back depending on ternary operation
	// condition?if true:if false
	// i%2==0?beesBack:beesFront
	loop(30, i=>{
		let x = rand(stageW*.4, stageW*.54); // tweaked until liked
		let y = rand(stageH*.2,stageH*.35);
		let bee = new Bee()
			.sca(.7)
			.centerReg(i%2==0?beesBack:beesFront) // centerReg so goes in mouth properly
			.loc(x,y)
			.wiggle("x", x, 20, 400, 300, 500) // prop, start, min, max, minTime, maxTime
			.wiggle("y", y, 20, 150, 300, 500)
			.wiggle("rotation", 0, 10, 20, 1000, 2000);	
	});
	
	// when clicked, animate bees into mouth
	reaper.on("click", ()=>{
		removeBees(beesBack);
		removeBees(beesFront);
		reaper.shape.cur("default");
	}, null, true); // just once
	
	function removeBees(bees) {
		bees.loop((bee, i)=>{
			// could use a series but need different location as time goes on
			timeout(i*100, ()=>{ 
				let locMouth = mouth.localToLocal(0,0, bees); // gets 0,0 of mouth in bees
				bee.animate({
					props:{x:locMouth.x, y:locMouth.y},
					ease:"linear",
					time:300,
					call:()=>{bee.removeFrom()} // remove bee when animation is done
				});
			});			
		}, true); // loop backwards anytime removing from container 
		
		// fill reaper with bee pattern ;-) 
		// this helps make a little story
		new Tile(new Rectangle(5,500,yellow), 40, 1, 5, 0)
			.centerReg(reaper)
			.ord(-1) // move under mouth in Blob
			.rot(45)
			.setMask(reaper)
			.alp(0)
			.animate({
				props:{alpha:.1},
				time:2000,
				wait:1200
			});
	}
	
	new Label("GIVE GRIM A HEART!", 50, "impact", white).rot(-10).loc(425, 713).alp(.2);
	
	// we are animating so no need to update the stage
	// stage.update(); // this is needed to show any changes

	// DOCS FOR ITEMS USED
	// https://zimjs.com/docs.html?item=Frame
	// https://zimjs.com/docs.html?item=Container
	// https://zimjs.com/docs.html?item=Circle
	// https://zimjs.com/docs.html?item=Rectangle
	// https://zimjs.com/docs.html?item=Blob
	// https://zimjs.com/docs.html?item=Label
	// https://zimjs.com/docs.html?item=Tile
	// https://zimjs.com/docs.html?item=animate
	// https://zimjs.com/docs.html?item=wiggle
	// https://zimjs.com/docs.html?item=loop
	// https://zimjs.com/docs.html?item=cur
	// https://zimjs.com/docs.html?item=loc
	// https://zimjs.com/docs.html?item=mov
	// https://zimjs.com/docs.html?item=ord
	// https://zimjs.com/docs.html?item=alp
	// https://zimjs.com/docs.html?item=rot
	// https://zimjs.com/docs.html?item=siz
	// https://zimjs.com/docs.html?item=reg
	// 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=setMask
	// https://zimjs.com/docs.html?item=rand
	// https://zimjs.com/docs.html?item=timeout
	// https://zimjs.com/docs.html?item=zog
	// https://zimjs.com/docs.html?item=Ticker

	// FOOTER
	// call remote script to make ZIM Foundation for Creative Coding icon
	createIcon(); 
	createGreet(null, 70);
	createCode(null, 130);

}); // end of ready
              
            
!
999px

Console