123

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("fit", 1024, 768, "#ff6337", darker);
frame.on("ready", function() {
	zog("ready from ZIM Frame"); // logs in console (F12 - choose console)

	let stage = frame.stage;
	let stageW = frame.width;
	let stageH = frame.height;

	// create a container for burger - easier to loop through and manage parts
	const burger = new Container(stageW, stageH).addTo();

	// DATA for burger parts 
	// will use ZIM Blob objects which can be Shape tweened
	// we will start with circles and rectangles and tween to the shapes below:
	// the data was made at https://zimjs.com/nio/paths.html in 2 minutes
	const top = [[-4,-49,0,0,-100,0,100,0],[100,11,0,0,1,-15,-1,15],[-2,13,0,0,100,0,-100,0],[-102,12,0,0,0,14,0,-14]];
	const mid = [[-4,-10,0,0,-100,0,100,0],[100,11,0,0,1,-15,-1,15],[-2,13,0,0,100,0,-100,0],[-102,12,0,0,0,14,0,-14]];
	const bot = [[-4,-10,0,0,-100,0,100,0],[100,11,0,0,1,-15,-1,15],[-4,55,0,0,100,0,-100,0],[-102,12,0,0,0,14,0,-14]];

	const colors = [brown, dark, yellow, dark, yellow, red, brown];
	const starts = ["circle", "circle", "rectangle", "circle", "rectangle", "circle", "circle"];
	const ends = [bot, mid, mid, mid, mid, mid, top];
	const pos1 = [[800,500], [750,270], [550,500], [500,600], [300,400], [250,350], [500,200]];
	const pos2 = [[500,400], [500,380], [500,360], [500,350], [500,330], [500,320], [500,300]];
	
	// create parts as Blobs - which can be shape tweened in ZIM (so can Squiggles)
	loop(colors, (color,i)=>{
		let part = new Blob({color:colors[i], borderColor:grey, points:starts[i], interactive:false})
			.loc(pos1[i][0], pos1[i][1], burger)
			.sha("rgba(0,0,0,.1)",3,3,5);
		// interactive of false turns off shape's cursor so part.cur() does not work
		// neither will burger.cur() - it usually would but not in this case
		// so put cursor with finger back on to shape
		part.shape.cur();
	});

	// handle tomato core
	const tomato = burger.getChildAt(5);
	const core = new Container().addTo(tomato);
	loop(4, i=>{
		// to get a "fanning" effect
		// it is easiest to move registration and rotate
		new Triangle({color:white, borderColor:black})
			.reg(null, -15)
			.rot(90*i)
			.sca(.7)
			.alp(.3)
			.addTo(core)
	});

	// handle seeds
	const bun = burger.getChildAt(burger.numChildren-1);
	const seeds = new Container().addTo(bun);
	loop(60, i=>{
		// again, to locate randomly in a circle,
		// it is easiest to randomize the registration 
		// and the rotation
		new Circle(3, light, tin)
			.reg(rand(10,50))
			.sca(1.5,1)
			.rot(rand(360))
			.loc(seeds, null, seeds)
	});

	const plate = new Circle(250, white, dark, 50)
		.alp(0)
		.sca(1,.3)
		.loc(500,445)
		.bot();
	new Circle(110).alp(.2).center(plate).mov(0,-10);
	
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ANIMATE IN PARTS
	
	// note the series value from the ZIM VEE Pick object 
	// and the sequence parameter
	burger.animate({
		props:{x:series(stageW+200, -200)},
		time:500,
		ease:"backOut",
		sequence:100,
		from:true,
		wait:500
	});

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~
	// INTERACTIVIVITY

	let together = false;
	burger.tap(function () {
		together = !together; // toggle together each time
		if (together) {
			plate.animate({props:{alpha:.2}, time:300, wait:300});
			core.animate({props:{scaleY:0}, time:400, ease:"backIn"});
			seeds.animate({props:{scaleY:.3, y:"-25"}, time:400, ease:"backIn"});
			burger.loop((part,i)=>{
				part.animate({
					props:{
						// shape tween to end Blob shape
						shape:new Blob({points:ends[i]}),
						x:pos2[i][0], y:pos2[i][1]
					},
					time:400,
					ease:"backIn"
				});
			});
		} else {
			// planning on adding a reverseTween() method to avoid this 
			// alternatively, ZIM Tweens can be made dynamic and controlled 
			// see https://zimjs.com/nio/flip.html for example 
			// or any of the ZIM NIO examples: https://zimjs.com/nio/
			plate.animate({alpha:0}, 300);
			core.animate({props:{scaleY:1}, time:400, ease:"backOut"});
			seeds.animate({props:{scaleY:1, y:"25"}, time:400, ease:"backOut"});
			burger.loop((part,i)=>{
				part.animate({
					props:{
						// shape tween to start Blob shape
						shape:new Blob({points:starts[i]}),
						x:pos1[i][0], y:pos1[i][1]
					},
					time:400,
					ease:"backOut"
				});
			});
		}
	});
	
	new Label("Press to Create Burger!")
		.pos(30,30)
		.alp(0)
		.sca(.8)
		.animate({props:{alpha:.7}, time:400, wait:1500});
	
	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=Triangle
	// https://zimjs.com/docs.html?item=Blob
	// https://zimjs.com/docs.html?item=Label
	// https://zimjs.com/docs.html?item=tap
	// https://zimjs.com/docs.html?item=animate
	// https://zimjs.com/docs.html?item=loop
	// https://zimjs.com/docs.html?item=cur
	// https://zimjs.com/docs.html?item=sha
	// https://zimjs.com/docs.html?item=pos
	// https://zimjs.com/docs.html?item=loc
	// https://zimjs.com/docs.html?item=mov
	// https://zimjs.com/docs.html?item=bot
	// https://zimjs.com/docs.html?item=alp
	// https://zimjs.com/docs.html?item=rot
	// 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=center
	// https://zimjs.com/docs.html?item=zog

	// FOOTER
	// make a greeting - come on in and join us on ZIM Slack!
	createGreet(); 

	// call remote script to make ZIM Foundation for Creative Coding icon
	createIcon(); 

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

Console