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

              
                const frame = new Frame("fit", 1024, 768, dark, darker);
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;

	// REFERENCES for ZIM at http://zimjs.com
	// see http://zimjs.com/learn.html for video and code tutorials
	// see http://zimjs.com/docs.html for documentation
	// see https://www.youtube.com/watch?v=pUjHFptXspM for INTRO to ZIM
	// see https://www.youtube.com/watch?v=v7OT0YrDWiY for INTRO to CODE

	// CODE HERE

	// Create a ZIM Tag() object to hold Zdog
	const dogTag = new Tag(500,500)
		.center()
		.mov(0,-20)
		.add("<canvas id=dog width=500 height=500></canvas>")
		// .outline()

	// Here is how we can get a grab cursor if we want
	// dogTag.tag.style.cursor = "grab";
	// in ZIM we normally would use .cur("grab")
	// but Zdog is overlayed on ZIM so takes away cursor
	// unless we do not use Zdog dragRotate
	// and set dogTag.tag.style.pointerEvents = "none";


	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ZDOG - https://zzz.dog/

	const dog = new Zdog.Illustration({
		element: "#dog",
		dragRotate: true
	});

	// will be dynamically creating color parts between two grey parts
	// distance of top and bottom grey part from the center
	const offset = 120;

	// build in the z access as shapes face that way
	// and then rotate the whole dog Illustration
	// later around the x axis to see sides
	const bunTop = new Zdog.Hemisphere({
		addTo: dog,
		diameter: 120,
		stroke: false,
		color: brown, // zim color
		backface: "sienna", // html color in quotes
	});
	bunTop.translate.z = offset+30;

	const top = new Zdog.RoundedRect({
		addTo:dog,
		width:200,
		height:200,
		fill:true,
		cornerRadius:60,
		stroke:30,
		color:tin,
	});
	top.translate.z = offset;

	const bot = new Zdog.RoundedRect({
		addTo: dog,
		width:150, // bottom of logo is smaller than top
		height:150,
		fill:true,
		cornerRadius:60,
		stroke:30,
		color:tin,
	});
	bot.translate.z = -offset;
	bot.translate.x = -20;

	const bunBot = new Zdog.Hemisphere({
		addTo: dog,
		diameter: 120,
		stroke: false,
		color: brown,
		backface: "sienna",
	});
	bunBot.translate.z = -offset-30;
	bunBot.rotate.x = 180*Math.PI/180;
	bunBot.translate.x = -20;

	const colors = [pink, blue, orange, yellow, green];
	const parts = []; // so can animate these later with a sequence
	const separation = offset*2/(colors.length+1);
	loop(colors, (color,i)=>{
		let size = 40+i*20;
		let part = new Zdog.RoundedRect({
			addTo:dog,
			width:size,
			height:size,
			fill:true,
			cornerRadius:60,
			stroke:30,
			color:color,
		});
		// manipulating z and x to make slanted slats
		part.translate.z = -offset+separation*(i+1);
		part.translate.x = part.startX = size-100;
		parts.push(part);
	});

	// render dog
	Ticker.add(()=>{
		dog.updateRenderGraph();
	});

	// end of Zdog
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~

	// rotate Zdog Illustration
	// tip back 90 and then a full rotation
	const startRotation = (90+360)*Math.PI/180;
	animate({
		target:dog, 
		// put dot animation in quotes
		props:{"rotate.x":startRotation}, 
		time:2000, 
		ease:"backOut",
		wait:400
	});

	// will be animating multiple times
	// otherwise would put this right in the animate() function
	const animObj = {
		target:parts,
		// put dot animation in quotes
		// put relative animation in quotes too ;-)
		// usally this might be  {x:100} to animate x to absolute 100
		props:{"translate.x":"100"},
		time:500,
		loop:true,
		rewind:true,
		sequence:100,
		id:"parts",
		startPaused:true
	}
	animate(animObj);

	// if we reset we will want a new animate()
	// when we press the Animate CheckBox
	// if we have not reset then we will
	// want to pauseAnimate(false) the existing animation
	let resetCheck = false;
	const reset = new Button({
		label:"RESET",
		backgroundColor:blue,
		rollBackgroundColor:green,
		corner:0
	})
		.sca(.5)
		.centerReg()
		.pos(null, 60, null, true)
		.mov(-20)
		.tap(() => {
			resetCheck = true;
			// animate dog Illustration back to start
			animate(dog, {
				"rotate.x":startRotation,
				"rotate.y":0,
				"rotate.z":0
			}, 600, "backOut");
			// stop the parts animation and animate parts back to start
			stopAnimate("parts");
			loop(parts, part=>{
				// part.resetTween(); // would jump to start position
				animate(part, {"translate.x":part.startX}, 400);
			});
			checkBox.checked = false;
		});

	var checkBox = new CheckBox({label:"Animate", color:light})
		.sca(.5)
		.centerReg()
		.loc(reset)
		.mov(150)
		.change(e=>{
			// if we have reset then make a new animate()
			if (resetCheck) {
				resetCheck = false;
				// initial animate starts paused - but do not want that now
				animObj.startPaused = false;
				animate(animObj);
			} else {
				// otherwise we pause or unpause the existing animation
				pauseAnimate(!checkBox.checked, "parts");
			}
		});

	new Label({
		text:"ZIM Burger - drag rotate the Zdog Illustration",
		color:silver
	}).center().pos(null,30);

	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=Label
	// https://zimjs.com/docs.html?item=Button
	// https://zimjs.com/docs.html?item=CheckBox
	// https://zimjs.com/docs.html?item=Tag
	// https://zimjs.com/docs.html?item=tap
	// https://zimjs.com/docs.html?item=change
	// https://zimjs.com/docs.html?item=animate
	// https://zimjs.com/docs.html?item=stopAnimate
	// https://zimjs.com/docs.html?item=pauseAnimate
	// https://zimjs.com/docs.html?item=loop
	// 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=mov
	// https://zimjs.com/docs.html?item=sca
	// https://zimjs.com/docs.html?item=outline
	// https://zimjs.com/docs.html?item=centerReg
	// https://zimjs.com/docs.html?item=center
	// https://zimjs.com/docs.html?item=zog
	// https://zimjs.com/docs.html?item=Ticker
  
	// FOOTER
	// Please see a greeting message - then come visit us at ZIM https://zimjs.com
	createGreet(100);

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

}); // end of ready
              
            
!
999px

Console