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, light, dark);
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;
	
	const backing = new Rectangle(600,400, lighter)
		.center()
		.mov(0,-80) // move up from center
		.sha("rgba(0,0,0,.1)",3,3,5); // color, x, y, blur

	// Create a ZIM Tag() object to hold Zdog 	
	const dogTag = new Tag(300,300)
		.center()
		.mov(0,-80)
		.add("<canvas id=dog width=300 height=300></canvas>")		
		// .drag({boundary:new Boundary(backing.x, backing.y, backing.width-300, backing.height-300)});
		// could have dragged dogTag but would interfere with swiping
	
	// A ZIM Tag object is an HTML div overlay
	// Below, we set to no mouse control 
	// so we can use ZIM Swiper to swipe 
	// Zdog controls are great and we could use those 
	// in which case, do not set the pointerEvents to none! 
	// But... we are domonstrating ZIM components and controls...
	dogTag.tag.style.pointerEvents = "none";

	dogTag.startX = dogTag.x; // for reset button

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ZDOG - https://zzz.dog/
	
	const dog = new Zdog.Illustration({
		element: "#dog",
		// dragRotate: true   
		// comment out pointerEvents above to use dragRotate
		// note - this would rotate dog, not hemi 
		// so reset Button would need function adjusted 
		// to reset rotation of dog, not hemi
	});
	const hemi = new Zdog.Hemisphere({
		addTo: dog,
		diameter: 300,
		stroke: false,
		color: blue,
		backface: green,
	});	
	const startRotationX = -120*Math.PI/180; // spin backwards about x axis
	hemi.rotate.x = startRotationX; 
	
	// update Zdog world
	// note, some Zdog shape properties like width and diameter
	// may still need an updatePath() called on the object
	Ticker.add(()=>{dog.updateRenderGraph();});
	
	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// ZIM Components and Controls

	const slider = new Slider({
		barLength:200,
		min:0, 
		max:2*360*Math.PI/180, // or use 2*Zdog.TAU
		button:new Button({
			width:44, 
			height:44, 
			label:"", 
			corner:22, 
			backgroundColor:white,
			rollBackgroundColor:lighter
		})
	})
		.center()
		.mov(0,200) // move down from center
		.change(()=>{
			hemi.rotate.y = slider.currentValue;    
		});

	const reset = new Button({
		label:"RESET", 
		backgroundColor:blue, 
		rollBackgroundColor:pink, 
		corner:0
	})
		.sca(.65)
		.centerReg() // to align with vertical center of slider
		.loc(slider)
		.mov(slider.width+90) // move over to right
		.tap(()=>{
			swiper.enabled = false; // turn off swiper
			animate({
				target:hemi.rotate, 
				// might be a bug - seems to need these set to current values
				set:{y:hemi.rotate.y, x:hemi.rotate.x},
				props:{y:0, x:startRotationX}, 
				time:1000, 
				ease:"backOut",        
				call:()=>{swiper.enabled = true;} // turn on swiper
			}); 
			slider.animate({currentValue:0}, 1000);
			stepper.currentValue = 0;
			dogTag.animate({
				props:{x:dogTag.startX}, 
				time:500,
				events:true // dogTag needs resizing if manually adjusted
			});
		});
	dogTag.on("animation", ()=>{dogTag.resize();});
	
	// animate hemi and slider to start
	slider.currentValue = slider.max;
	animate({
		target:hemi.rotate, 
		set:{y:slider.max, x:hemi.rotate.x},
		props:{y:0}, 
		time:2000, 
		ease:"backOut"
	});
	slider.animate({currentValue:0}, 2000);
	
	const stepper = new Stepper({
		color:grey,
		width:130,
		corner:0,
		stepperType :"number",
		step:10,
		min:-90,
		max:90		
	})
		.centerReg() // to align with vertical slider center
		.sca(.4)
		.alp(.9)
		.loc(slider)
		.mov(-130) // move to left
		.change(()=>{
			dogTag.x = dogTag.startX + stepper.currentValue;	
			dogTag.resize(); // for manual Tag movement
		});


	const picker = new ColorPicker({
		colors:[red,pink,purple,green,yellow,orange,blue],
		cols:7,
		circles:true,
		backgroundColor:clear,
		spacing:5
	})
		.sca(.65)
		.rot(90)
		.pos(90,backing.y+20,true) // from left 90
		.change(e=>{
			if (toggle.text == "B") {
				hemi.color = e.target.selectedColor;
			} else {
				hemi.backface = e.target.selectedColor;			
			}
		});
	
	var toggle = new Toggle({
		color:grey,
		label:"F",
		labelLeft:"B",
		backgroundColor:silver,
		toggleBackgroundColor:silver,
	})
		.sca(.6)
		.loc(860, 474); // used .place()

	const swiper = new Swiper(backing, hemi.rotate, "x", -.01, false);
	
	const swipeInstructions = new Tile(
		series(
			new Triangle().rot(-90).sca(.35), 
			new Label("SWIPE"), 
			new Triangle().rot(90).sca(.35)
		), 3, 1, 20) // cols, rows, spacingH
		.alp(.5)
		.rot(-90)
		.loc(124, 428); // used .place();

	new Label("Example of Zdog with ZIM")
		.sca(.7)
		.alp(.6)
		.pos(30,30);
	
	var pattern = pizzazz.makePattern({
		type:"slants", 
		colors:"#d4d4d4", 
		size:35, 
		rows:50, 
		cols:60
	}).addTo().bot();
	
	// DOCS FOR ITEMS USED 
	// https://zimjs.com/docs.html?item=Frame
	// https://zimjs.com/docs.html?item=Rectangle
	// https://zimjs.com/docs.html?item=Triangle
	// https://zimjs.com/docs.html?item=Label
	// https://zimjs.com/docs.html?item=Button
	// https://zimjs.com/docs.html?item=Toggle
	// https://zimjs.com/docs.html?item=Stepper
	// https://zimjs.com/docs.html?item=Slider
	// https://zimjs.com/docs.html?item=Tile
	// https://zimjs.com/docs.html?item=ColorPicker
	// 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=drag
	// https://zimjs.com/docs.html?item=animate
	// 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=sca
	// https://zimjs.com/docs.html?item=addTo
	// 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=Swiper
	// https://zimjs.com/docs.html?item=Boundary
	// https://zimjs.com/docs.html?item=series
	// 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); 

	stage.update(); // this is needed to show any changes

}); // 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