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

              
                <svg>
	<path id="pizza25"/>
	<path id="pizza50"/>
	<path id="pacMan60"/>
	<path id="pacMan"/>
</svg>
              
            
!

CSS

              
                body{
	background-color:#3c3c3c;
}
svg{
	margin:20px;
	overflow:visible;
}
#pacMan, #pizza25{
	stroke:none;
	fill:green;
}

#pizza50, #pacMan60{
	stroke:none;
	fill:#0c581b;
}

              
            
!

JS

              
                console.clear();

var pacManFig = document.getElementById("pacMan"),
    pacMan60Fig = document.getElementById("pacMan60"),
    pizza25Fig  = document.getElementById("pizza25"),
    pizza50Fig  = document.getElementById("pizza50");


var pacMan = {x:100, y:100, radius: 50, start:120, end:420};
var pacManX = pacMan.x,
    pacManY = pacMan.y,
    pacManRadius = pacMan.radius,
    pacManStart = pacMan.start,
    pacManEnd = pacMan.end;

pacManFig.setAttribute("d", describeArc(pacManX, pacManY, pacManRadius, pacManStart, pacManEnd));

var pacMan60 = {x:100, y:100, radius: 50, start:60, end:120};
var pacMan60X = pacMan60.x,
    pacMan60Y = pacMan60.y,
    pacMan60Radius = pacMan60.radius,
    pacMan60Start = pacMan60.start,
    pacMan60End = pacMan60.end;

pacMan60Fig.setAttribute("d", describeArc(pacMan60X, pacMan60Y, pacMan60Radius, pacMan60Start, pacMan60End));

// pizza chart ==================
var pizza25 = {x:400, y:100, radius: 50, start:0, end:0.1};
var pizza25X = pizza25.x,
    pizza25Y = pizza25.y,
    pizza25Radius = pizza25.radius,
    pizza25Start = pizza25.start,
    pizza25End = pizza25.end;

pizza25Fig.setAttribute("d", describeArc(pizza25X, pizza25Y, pizza25Radius, pizza25Start, pizza25End));

var pizza50 = {x:400, y:100, radius: 50, start:90, end:90};
var pizza50X = pizza50.x,
    pizza50Y = pizza50.y,
    pizza50Radius = pizza50.radius,
    pizza50Start = pizza50.start,
    pizza50End = pizza50.end;

pizza50Fig.setAttribute("d", describeArc(pizza50X, pizza50Y, pizza50Radius, pizza50Start, pizza50End));

// action =============================
gsap.timeline({repeat:3,  repeatDelay:0.5, onUpdate:update})
  .from([pacManFig, pacMan60Fig], {scale:0, transformOrigin:'center', stagger:0.5},1)
	.from(pacMan, {start:90, end:449.9, duration:0.5, ease:'power1.inOut'}, '+=0.5')
	.to(pacMan60Fig, {x:25, duration:0.5, ease:'back.inOut(10)'}, '-=0.25')
	.to(pizza25, {start:0, end:90, duration:2, ease:'none'}, '+=1')
	.to(pizza50, {start:90, end:270, duration:2, ease:'none'})
	.to(pacManFig, {scale:2.2, transformOrigin:'center', duration:1, ease:'back.inOut(3)'},'+=0.5')
	.addLabel('eat','+=1')
	.to(pacManFig, {x:500, duration:5, ease:'none'}, 'eat')
	.to(pacMan, {start:90, end:449.9, duration:0.05, ease:'power1.inOut', repeat:3, yoyo:true, repeatDelay:1.1},'eat')
	.set(pacMan60Fig, {autoAlpha:0}, 'eat+=0.1')
	.set([pizza25Fig, pizza50Fig], {autoAlpha:0}, 'eat+=2.7')
  .to(pacManFig, {autoAlpha:0, duration:2}, '-=2')


function update() {
	pacManStart = pacMan.start;
	pacManEnd = pacMan.end;
	pacManFig.setAttribute("d", describeArc(pacManX, pacManY, pacManRadius, pacManStart, pacManEnd));

	pizza25Start = pizza25.start;
	pizza25End = pizza25.end;
	document.getElementById("pizza25").setAttribute("d", describeArc(pizza25X, pizza25Y, pizza25Radius, pizza25Start, pizza25End));

	pizza50Start = pizza50.start;
	pizza50End = pizza50.end;
	document.getElementById("pizza50").setAttribute("d", describeArc(pizza50X, pizza50Y, pizza50Radius, pizza50Start, pizza50End));
}

// helper: How to calculate the SVG Path for an arc / a circle
// http://stackoverflow.com/a/24569190/2834898

function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
	var angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;

	return {
		x: centerX + (radius * Math.cos(angleInRadians)),
		y: centerY + (radius * Math.sin(angleInRadians))
	};
};

function describeArc(x, y, radius, startAngle, endAngle) {
	var start = polarToCartesian(x, y, radius, endAngle);
	var end = polarToCartesian(x, y, radius, startAngle);

	var arcSweep = endAngle - startAngle <= 180 ? "0" : "1";

	return [
		"M", start.x, start.y,
		"A", radius, radius, 0, arcSweep, 0, end.x, end.y,
		"L", x, y,
		"L", start.x, start.y
	].join(" ");
}
              
            
!
999px

Console