css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <h1>Sass Color Matrix</h1>
<p>Fundamentals from <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix">feColorMatrix</a> and <a href="http://alistapart.com/article/finessing-fecolormatrix">Finessing feColorMatrix</a></p>
<div class="box"></div>
<div class="box green"></div>
<div class="box blue"></div>
<div class="box box--1"></div>
<div class="box box--1 green"></div>
<div class="box box--1 blue"></div>
<div class="box box--2"></div>
<div class="box box--2 green"></div>
<div class="box box--2 blue"></div>
<div class="box box--3"></div>
<div class="box box--3 green"></div>
<div class="box box--3 blue"></div>
            
          
!
            
              $red:   rgba( 255, 0, 0, 1 );
$green: rgba( 0, 255, 0, 1 );
$blue:  rgba( 0, 0, 255, 1 );

$deuteranopia: ( 0.567, 0.433, 0, 0,
                0, 0.558, 0.442, 0, 0,
                0, 0, 0.242, 0.758, 0, 0,
                0, 0, 0, 1, 0 );

$deuteranomaly: ( 0.8, 0.2, 0, 0, 0,
                 0.258, 0.742, 0, 0, 0, 
                 0, 0.142, 0.858, 0, 0,
                 0, 0, 0, 1, 0 );

$protanopia: ( 0.567, 0.433, 0, 0, 0, 
              0.558, 0.442, 0, 0, 0,
              0, 0.242, 0.758, 0, 0,
              0, 0, 0, 1, 0 );

$greenOut: ( 0, 0, 0, 0, 0,
             1, 1, 1, 1, 0,
             0, 0, 0, 0, 0,
             0, 0, 0, 1, 0 );

/**
 * Chunk - Chunk an array into sizable peices
 *
 * https://hugogiraudel.com/2013/10/09/advanced-sass-list-functions-again/
 * 
 * @param  {array}  $list   - The array to be split into chunks
 * @param  {number} $size   - The size of the array chunks
 *
 * @return {array}          - The array split into chunks
 */
@function Chunk( $list, $size ) {
  $result: ();
  $n: ceil( length( $list ) / $size );
  $temp-index: 0;

  @for $i from 1 through $n {
    $temp-list: ();

    @for $j from 1 + $temp-index through $size + $temp-index {
      @if $j <= length( $list ) {
        $temp-list: append( $temp-list, nth( $list, $j ) );
      }
    }

    $result: append( $result, $temp-list );
    $temp-index: $temp-index + $size;
  }

  @return $result;
}


/**
 * ColorFilter - Run a matrix filter over a color variable and return the color
 *
 * http://alistapart.com/article/finessing-fecolormatrix
 * https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feColorMatrix
 * 
 * @param  {string} $color   - The color to be manipulated by the filter
 * @param  {string} $filter  - The filter in a matrix; red, green, blue, alpha
 *
 * @return {string}          - The manipulated color based on the filter
 */
@function ColorFilter( $color, $filter ) {

  // RGBA values of the color
  $colorRGBA: (
    'red':   red( $color ),  
    'green': green( $color ),
    'blue':  blue( $color ),
    'alpha': alpha( $color ),
  );
  
  // Split the filter into groups of 5
  $filterRGBA: Chunk( $filter, 5 );
  
  // Create an empty map to fill with data
  $filterResult: (
    'red': 0,
    'green': 0,
    'blue': 0,
    'alpha': 0,
  );
  
  $j: 1;
  
  @each $filterGroup in $filterRGBA {
    
    $i: 1;
    
    @each $key in map-keys( $colorRGBA ) {
      $rgbaValue: map-get( $colorRGBA, $key );
      
      @debug $rgbaValue;
      @debug nth( $filterGroup, $i );
      
      $filterResult: map-merge(
        $filterResult, 
        ( 
          nth( map-keys( $filterResult ), $j ) : nth( map-values( $filterResult ), $j ) + nth( $filterGroup, $i ) * $rgbaValue
        )
      );
      
      $i: $i + 1;
    }
    
    $j: $j + 1;
    
  }
  
  @return rgba( 
    map-get( $filterResult, 'red' ), 
    map-get( $filterResult, 'green' ), 
    map-get( $filterResult, 'blue' ), 
    map-get( $filterResult, 'alpha' )
  );
}


/**
 * Random stuff to make it look nice
 */
body {
  background: #24292e;
  color: #fff;
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;
  padding: 50px 20px;
  width: 500px;
  margin: 0 auto;
}

a {
  color: #EBCA79;
}

h1 {
  margin-top: 0;
  margin-left: 5px;
  margin-right: 5px;
}

.box {
  width: 150px;
  height: 150px;
  float: left;
  display: block;
  margin: 5px;
  text-align: center;
  
  &:before {
    display: inline-block;
    background: #fff;
    color: #000;
    padding: 3px 5px;
    margin-top: 55px;
    font-size: 12px;
  }
  
  &:after {
    display: block;
    color: #fff;
    background: #000;
    padding: 3px 5px;
    margin-top: 41px;
    font-size: 12px;
  }
}


/**
 * Proof of concept
 */
.box {
  background: $red;
  
  &:before {
    content: "#{ $red }";
  }
  
  &:after {
    content: "Default";
  }
  
  &.green {
    background: $green;
    
    &:before {
      content: "#{ $green }";
    }
  }
  
  &.blue {
    background: $blue;
    &:before {
      content: "#{ $blue }";
    }
  }
}

.box--1 {
  background: ColorFilter( $red, $deuteranopia );
  
  &:before {
    content: "#{ ColorFilter( $red, $deuteranopia ) }";
  }
  
  &:after {
    content: "Deuteranopia";
  }
  
  &.green {
    background: ColorFilter( $green, $deuteranopia );
    
    &:before {
      content: "#{ ColorFilter( $green, $deuteranopia ) }";
    }
  }
  
  &.blue {
    background: ColorFilter( $blue, $deuteranopia );
    
    &:before {
      content: "#{ ColorFilter( $blue, $deuteranopia ) }";
    }
  }
}


.box--2 {
  background: ColorFilter( $red, $deuteranomaly );
  
  &:before {
    content: "#{ ColorFilter( $red, $deuteranomaly ) }";
  }
  
  &:after {
    content: "Deuteranomaly";
  }
  
  &.green {
    background: ColorFilter( $green, $deuteranomaly );
    
    &:before {
      content: "#{ ColorFilter( $green, $deuteranomaly ) }";
    }
  }
  
  &.blue {
    background: ColorFilter( $blue, $deuteranomaly );
    
    &:before {
      content: "#{ ColorFilter( $blue, $deuteranomaly ) }";
    }
  }
}


.box--3 {
  background: ColorFilter( $red, $deuteranomaly );
  
  &:before {
    content: "#{ ColorFilter( $red, $deuteranomaly ) }";
  }
  
  &:after {
    content: "Protanopia";
  }
  
  &.green {
    background: ColorFilter( $green, $protanopia );
    
    &:before {
      content: "#{ ColorFilter( $green, $protanopia ) }";
    }
  }
  
  &.blue {
    background: ColorFilter( $blue, $protanopia );
    
    &:before {
      content: "#{ ColorFilter( $blue, $protanopia ) }";
    }
  }
}


.box--3 {
  background: ColorFilter( $red, $greenOut );
  
  &:before {
    content: "#{ ColorFilter( $red, $greenOut ) }";
  }
  
  &:after {
    content: "Green Out";
  }
  
  &.green {
    background: ColorFilter( $green, $greenOut );
    
    &:before {
      content: "#{ ColorFilter( $green, $greenOut ) }";
    }
  }
  
  &.blue {
    background: ColorFilter( $blue, $greenOut );
    
    &:before {
      content: "#{ ColorFilter( $blue, $greenOut ) }";
    }
  }
}
            
          
!
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.
Loading ..................

Console