close

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

              
                import zim from "https://zimjs.org/cdn/016/zim_physics";

const assets = ["gf_Englebert", "https://assets.codepen.io/2104200/tv.glsl"];
// See Docs under Frame for FIT, FILL, FULL, and TAG
new Frame(FIT, 1024, 768, yellow, purple, ready, assets);
function ready() {

	// given F (Frame), S (Stage), W (width), H (height)
	// put code here

	new Label("ZIM - a leap in simplicity!", 50, "Englebert", purple).pos(0,80,CENTER);

	const tv = new Container(W-150,H-150).reg(CENTER).pos(0,3,CENTER,BOTTOM);	
	// see https://zimjs.com/016/shaders.html for more examples
	const pattern = new Shader({
		width:tv.width,  
		height:tv.height, 
		// https://www.shadertoy.com/view/3d33RN by avin
		fragment:asset("https://assets.codepen.io/2104200/tv.glsl"), 
		rate:.2 // used iChange instead of iTime in glsl to slow down animation with rate
	}).center(tv);

	// https://zimjs.com/paths
	const points = [[0,-150,0,0,-200,0,200,0,"mirror"],[200,0,0,0,0,-150,0,150,"mirror"],[0,150,0,0,200,0,-200,0,"mirror"],[-200,0,0,0,0,150,0,-150,"mirror"]];
	const blob = new Blob({color:black, points:points, interactive:false}).scaleTo(tv,95,95).center(tv).bot();
	pattern.setMask(blob);
	const clone = blob.clone().dye(lighter).scaleTo(tv,100,100).center(tv).bot();
	clone.borderColor = grey;
	clone.borderWidth = 1;

	F.makeIcon({box:faint}).sca(4).center(tv).ble("screen").tap(()=>{
		zgo("https://zimjs.com", "_blank");
	});

	tv.animate({
		wait:.5,
		time:2.8,
		ease:"backIn",
		rewind:true,
		props:{y:"-1500"}, // quotes for relative
		loop:true,
		loopWait:2
	});

	class Person extends Container {
		constructor(head,body,arms,appendages) {
			const w = 100;
			const h = 300;
			super(w,h);
			this.head = new Circle(w/2, head, dark)
				.pos(0,0,CENTER,TOP,this);
			this.body = new Rectangle(w*.5, h/4, body, dark)
				.reg(CENTER)
				.pos(0,this.head.height+10,CENTER,TOP,this);
			this.arms = new Tile(new Rectangle({
				width:20,
				height:h*.5,
				color:arms,
				borderColor:dark
			}).reg(CENTER,TOP), 2, 1, this.body.width, 0)
				.center(this)
				.loc(null,this.body.y-this.body.height/2);
			const hand = new Rectangle({
				width:20,
				height:30,
				corner:8,
				color:pink.lighten(.4).toColor(grey, .2),
				borderColor:dark,
			}).rot(20).pos(0,-20,CENTER,BOTTOM,this.arms.items[0]);
			hand.clone().rot(-20).pos(0,-20,CENTER,BOTTOM,this.arms.items[1]);
			let arm1 = this.arms.items[0].addTo(this.head);
			let arm2 = this.arms.items[1].addTo(this.head);
			arm1.corner = [0,20,0,10];
			arm1.rot(150).mov(10,20)
			arm2.corner = [20,0,10,0];
			arm2.rot(-150).mov(-10,20)
			this.legs = new Tile(new Rectangle({
				width:20,
				height:h*.3,
				color:arms,
				borderColor:dark
			}).reg(CENTER), 2, 1, 4, 0)
				.pos(0,20,CENTER,BOTTOM,this);
			this.feet = new Tile(new Circle({
				radius:13,
				color:appendages,
				borderColor:dark,
				percent:70
			}), 2, 1, 5, 0).pos(0,0,CENTER,BOTTOM,this);

			this.hair = new Tile(new Tile(new Rectangle(5,20,[red,green,blue,grey,darker]).reg(CENTER),1,6,0,0), 10,1,5.0)
				.pos(0,0,CENTER,TOP,this);

			this.mouseChildren = false;
		}
	}
	const me = new Person(brown.darken(.2), orange.darken(.2), orange, dark).reg(CENTER,TOP).loc(W/2,H);
	
	const physics = new Physics(10,"none");
	
	// Physics only works with objects in a Container at 0,0
	// so add objects to the stage then addPhysics()
	me.head.addTo(S).addPhysics();
	let foot1 = me.feet.items[0].addTo(S).addPhysics({contract:5});
	let foot2 = me.feet.items[1].addTo(S).addPhysics({contract:5});
	let leg1 = me.legs.items[0].addTo(S).addPhysics();
	let leg2 = me.legs.items[1].addTo(S).addPhysics();
	me.body.addTo(S).addPhysics();
	loop(me.hair.items, (item,i)=>{
		if (i==0 || i==9) item.y+=30;
		if (i==1 || i==8) item.y+=15;
		if (i==2 || i==7) item.y+=5;
		loop(item.items, (strand,i)=>{
			// maskBits of 2 will only interact with categoryBits of 2 - so... nothing
			// this allows the hair to swing without hitting the head or each other 
			// set categoryBits:2 to hit each other but not the head - pretty good too...
			strand.addTo(S).addPhysics({maskBits:2}); 
		}, true); // loop backwards when removing
	});

	// do the joins
	// obj1, obj2, point1, point2, minAngle, maxAngle, type      
	// a revolute join needs an absolute point about which the second object will revolve
	physics.join(me.head, me.body, new Point(me.body.x,me.body.y-me.body.height/2), null, -20, 20, "revolute");
	physics.join(leg1, foot1, new Point(leg1.x,leg1.y+leg1.height/2), null, -20, 20, "revolute");
	physics.join(leg2, foot2, new Point(leg2.x,leg2.y+leg2.height/2), null, -20, 20, "revolute");
	physics.join(me.body, leg1, new Point(me.body.x-me.body.width/3,me.body.y+me.body.height/2), null, -10, 80, "revolute");
	physics.join(me.body, leg2, new Point(me.body.x+me.body.width/3,me.body.y+me.body.height/2), null, -80, 10, "revolute");		
	loop(me.hair.items, (item,i)=>{
		let last;
		loop(item.items, (strand,i)=>{
			if (i==0) physics.join(me.head, strand, new Point(strand.x,strand.y-strand.height/2), null, -20, 20, "revolute");	
			else physics.join(last, strand, new Point(strand.x,strand.y-strand.height/2), null, -20, 20, "revolute");
			last = strand;
		});
	});
	
	physics.attach(tv, me.head);	// this attaches an object with phyics to an object without physics

}

// Docs for items used:
// https://zimjs.com/docs.html?item=Frame
// https://zimjs.com/docs.html?item=Container
// https://zimjs.com/docs.html?item=Shader
// 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=tap
// https://zimjs.com/docs.html?item=addPhysics
// https://zimjs.com/docs.html?item=animate
// https://zimjs.com/docs.html?item=loop
// 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=ble
// https://zimjs.com/docs.html?item=dye
// 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=scaleTo
// https://zimjs.com/docs.html?item=addTo
// https://zimjs.com/docs.html?item=center
// https://zimjs.com/docs.html?item=setMask
// https://zimjs.com/docs.html?item=Tile
// https://zimjs.com/docs.html?item=Physics
// https://zimjs.com/docs.html?item=Point
// https://zimjs.com/docs.html?item=lighten
// https://zimjs.com/docs.html?item=darken
// https://zimjs.com/docs.html?item=toColor
// https://zimjs.com/docs.html?item=zgo
              
            
!
999px

Console