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

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.

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

              
                .pixel_art
	-(1..64).each do |i|
		.pixel
.pixel_art_2
	-(1..16).each do |i|
		.pixel
              
            
!

CSS

              
                //-----------------------------------------//
// Global Frameworks                       //
//-----------------------------------------//
@import 'bourbon';

//-----------------------------------------//
// Global Styles                           //
//-----------------------------------------//
body{ 
	background: black; 
}

//-----------------------------------------//
// Methods and mixins for frame generation //
//-----------------------------------------//

/*
 * Counts the pixels withing a grid
 * @param {list<list<int>>} $grid
 * @return total units within the grid
 */
@function pixel_count($grid){
	@return length($grid) * length(nth($grid, 1));
}

/*
 * Generates the frames and meta for eacg animation
 * @param {list<list<int>>} $frames - frames for animation
 * @param {list<string>} $pixel_colors - colros for pixels for keys
 * @param {string} $anim_name - unique name for animation
 * @param {seconds} $duration - duration of animation
 */
@mixin pixel_animation_frames($frames, $pixel_colors, $anim_name, $duration){
	$on_anim: $anim_name;
	
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	
	// shared pixel styling
	$px_size: 100 / length(nth(nth($frames, 1),1)) * 1%;
	.pixel{
		flex: flex-grow;
		width: $px_size;
	}
	
	// Creates styles for each pixel for each frame
	@for $i from 1 through length($frames) {
		$on_pixel: 1;
		$frame: nth($frames, $i);
		
		// iterates over each row in the frame
		@for $i from 1 through length($frame) {
			$row: nth($frame, $i);

			// iterates over each pixel
			@for $j from 1 through length($row) {
				$pixel: nth($row, $j);
				$prev_color: nth($pixel_colors, nth(nth(nth($frames, length($frames)), $i), $j));
				$end_color: $prev_color;

				// Sets animation on pixel
				.pixel:nth-child(#{$on_pixel}){
					@include animation(#{"pixel_frames-"+$on_anim+"-"+$on_pixel} $duration linear);
					@include animation-iteration-count(infinite);		
				}
				
				// defines pixel animations
				@include keyframes(#{"pixel_frames-"+$on_anim+"-"+$on_pixel}) {
						
					// sets a antimation step for each frame, 
					//  cheats percent to avoid animation
					@for $k from 1 through length($frames) {
						$color: nth($pixel_colors, nth(nth(nth($frames, $k), $i), $j));
						$frame_percent: (100/length($frames)) * ($k - 1);
						
						#{$frame_percent}% {
							background-color: $prev_color;
						}
						
						#{$frame_percent+0.1}% {
							$color: nth($pixel_colors, nth(nth(nth($frames, $k), $i), $j));
							background-color: $color;
						}
						
						$prev_color: $color;
					}
					
					// ensures correct 100% end color
					100% {
						background-color: $end_color;
					}
				}
				
				// increments active pixel
				$on_pixel: $on_pixel + 1; 
			}
		}
	}
}


// Edit Here
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// This is all you really need to customize if you include the above
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
	
//-----------------------------------------//
// Animation 1 Data                        //
//-----------------------------------------//
$colors_1: #173d8c #503000 white black #efa337 #9851d5 #5241d3 #8cdb6a #376bef;

$f01: 1 1 8 8 8 8 1 1, 
      1 8 1 1 1 1 8 1,
			8 1 1 8 8 1 1 8,
			8 1 8 1 1 8 1 8,
			8 1 8 1 1 8 1 8,
      8 1 1 8 8 1 1 8,
      1 8 1 1 1 1 8 1,
			1 1 8 8 8 8 1 1;

$f02: 2 3 2 3 2 3 2 3, 
      3 2 3 2 3 2 3 2,
			2 3 2 3 2 3 2 3,
			3 2 3 2 3 2 3 2,
			2 3 2 3 2 3 2 3,
      3 2 3 2 3 2 3 2,
			2 3 2 3 2 3 2 3,
			3 2 3 2 3 2 3 2;

$f03: 5 1 1 1 1 1 1 5, 
      6 5 1 1 1 1 5 9,
			6 6 5 1 1 5 9 9,
			6 6 6 5 5 9 9 9,
			6 6 6 5 5 9 9 9,
      6 6 5 7 7 5 9 9,
			6 5 7 7 7 7 5 9,
			5 7 7 7 7 7 7 5;

$animation_frames: $f01 $f02 $f03;

//-----------------------------------------//
// Animation 2 Data                        //
//-----------------------------------------//
$colors_2: purple pink yellow;

$a01: 1 1 1 1, 
      2 2 2 2,
			2 2 2 2,
      2 2 2 2;

$a02: 3 3 3 3, 
      1 1 1 1,
			2 2 2 2,
      2 2 2 2;

$a03: 2 2 2 2, 
      3 3 3 3,
			1 1 1 1,
      2 2 2 2;

$a04: 2 2 2 2, 
      2 2 2 2,
			3 3 3 3,
      1 1 1 1;

$a05: 2 2 2 2, 
      2 2 2 2,
			2 2 2 2,
      3 3 3 3;

$animation_frames_2: $a01 $a02 $a03 $a04 $a05;

//-----------------------------------------//
// Application of CSS to items             //
//-----------------------------------------//
.pixel_art{
	float: left;
	width: 50vw;
	height: 50vw;
	position: absolute;
	top: 50%;
	left: 0px;
	@include transform(translateY(-50%));
	
	@include pixel_animation_frames($animation_frames, $colors_1, first_anim, 1.0s);
}

.pixel_art_2{
	float: left;
	width: 50vw;
	height: 50vw;
	position: absolute;
	top: 50%;
	right: 0px;
	@include transform(translateY(-50%));
	
	@include pixel_animation_frames($animation_frames_2, $colors_2, second, 0.9s);
}
	


              
            
!

JS

              
                ###
Thats right, no javascript!

Jump down to the 
// Edit Here
part of the scss, and you can change the animation frames.

All calculation are done purely with sass based on the
design for the frames. The only other thing neede is to
have the right amount of pixels in the html container.

Also, please dont use this in production, js would be WAY more performant.

###
              
            
!
999px

Console