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

              
                <h1>Complicated to Organized</h1>
<p>(scroll to animate)</p>

<svg class="svg" version="1.1" xmlns="http://www.w3.org/2000/svg" id="svg" viewbox="0 0 340 340">
	<defs>
		<style type="text/css"><![CDATA[
			.point {
				fill: #2187dc;
			}

			.line {
				fill: none;
				stroke: #a6a6a6;
				stroke-width: 0.5;
				stroke-linejoin: round;
				stroke-miterlimit: 10;
			}
		]]></style>
	</defs>
	<g id="container" transform="translate(20,20)">
		<g id="lines"></g>
		<g id="points"></g>
	</g>
</svg>
              
            
!

CSS

              
                body {
	font-family: Arial, sans-serif;
	margin: 0px;
	padding: 0px;
	text-align: center;
}

.svg {
	box-sizing: border-box;
	display: block;
	height: 300px;
	margin: 200px auto 800px auto;
	overflow: hidden;
	width: 300px;
}

@media screen and (max-height: 600px) {
	.svg {
		margin: 50px auto 300px auto;
	}
}
              
            
!

JS

              
                var r = 5;
var first = true;
// plotting points completely randomly can look bad, so instead use a limited list of random shapes that have been curated and tweaked to look random but still visually pleasing
var randomShapes = [
	[
		{x: 185, y: 60},
		{x: 165, y: 100},
		{x: 250, y: 250},
		{x: 70, y: 35},
		{x: 160, y: 260},
		{x: 55, y: 160},
		{x: 60, y: 70},
		{x: 260, y: 195},
		{x: 230, y: 90},
	],
	[
		{x: 200, y: 80},
		{x: 120, y: 260},
		{x: 235, y: 155},
		{x: 80, y: 45},
		{x: 140, y: 240},
		{x: 135, y: 90},
		{x: 225, y: 185},
		{x: 250, y: 260},
		{x: 55, y: 195},
	],
	[
		{x: 40, y: 230},
		{x: 270, y: 175},
		{x: 95, y: 265},
		{x: 260, y: 60},
		{x: 175, y: 240},
		{x: 195, y: 270},
		{x: 245, y: 125},
		{x: 205, y: 70},
		{x: 55, y: 65},
	],
	[
		{x: 130, y: 220},
		{x: 80, y: 190},
		{x: 65, y: 65},
		{x: 245, y: 60},
		{x: 190, y: 85},
		{x: 60, y: 95},
		{x: 200, y: 265},
		{x: 220, y: 225},
		{x: 230, y: 120},
	],
	[
		{x: 250, y: 75},
		{x: 40, y: 225},
		{x: 150, y: 130},
		{x: 230, y: 155},
		{x: 210, y: 180},
		{x: 105, y: 40},
		{x: 245, y: 235},
		{x: 55, y: 90},
		{x: 125, y: 220},
	],
];
var randomPoints = randomShapes[Math.floor(Math.random() * randomShapes.length)];
var pointIndex = 0;

/**
 * jQuery scroll event handler - start animations when scrolling down from top
 */
function scrollDown() {
	if ($(window).scrollTop() >= 100) {
		// var reverse = $('#svg').is('.reverse');
		// animateAll(reverse);
		animateAll(!first);
		first = false;
		$('#svg').toggleClass('reverse');
		$(window).unbind('scroll', scrollDown);
		$(window).bind('scroll', scrollUp);
	}
}

/**
 * jQuery scroll event handler - start animations in reverse when scrolling up from bottom
 */
function scrollUp() {
	if ($(window).scrollTop() < 100) {
		animateAll(true);
		$(window).unbind('scroll', scrollUp);
		$(window).bind('scroll', scrollDown);
	}
}

$(function(){

	// draw a 3x3 grid of points with points at 30, 150, and 270
	for (var yIndex = 30; yIndex <= 280; yIndex += 120) {
		for (var xIndex = 30; xIndex <= 280; pointIndex++, xIndex += 120) {

			var y = yIndex;
			var x = xIndex;

			// move corner points in towards the center point to make more of a star shape instead of a square grid
			// if (y != 150 && x != 150) {
			// 	y += 25 * (150 - y) / 100;
			// 	x += 25 * (150 - x) / 100;
			// }

			// get points from curated random shape
			var randomY = randomPoints[pointIndex].y;
			var randomX = randomPoints[pointIndex].x;

			// generate random points
			// var randomY = 25 + Math.random() * 250;
			// var randomX = 25 + Math.random() * 250;

			// create point
			var point = createPoint(randomX, randomY, r);

			// add x and y animations and classes so we can easily identify them later
			addAnimate(point, 'cx', randomX, x).setAttribute('class', 'animate-x');
			addAnimate(point, 'cy', randomY, y).setAttribute('class', 'animate-y');
		}
	}

	// draw lines between all the points
	var points = document.querySelectorAll('.point');

	//figure out better way to do this programmatically instead of just listing them all out?
	connectPoints(points[0], points[1]);
	connectPoints(points[0], points[3]);
	connectPoints(points[0], points[4]);

	connectPoints(points[1], points[2]);
	connectPoints(points[1], points[3]);
	connectPoints(points[1], points[4]);
	connectPoints(points[1], points[5]);

	connectPoints(points[2], points[5]);
	connectPoints(points[2], points[6]);

	connectPoints(points[3], points[4]);
	connectPoints(points[3], points[6]);
	connectPoints(points[3], points[7]);

	connectPoints(points[4], points[5]);
	connectPoints(points[4], points[7]);
	connectPoints(points[4], points[8]);

	connectPoints(points[5], points[7]);
	connectPoints(points[5], points[8]);

	connectPoints(points[6], points[7]);

	connectPoints(points[7], points[8]);
	
	// scroll event listener
	$(window).bind('scroll', scrollDown);
});
              
            
!
999px

Console