Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <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-grid">
  <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>
</div>
              
            
!

CSS

              
                $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
 */
html {
  background-image: linear-gradient(60deg, #29323c 0%, #485563 100%);
  min-height: 100%;
}

body {
  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;
}

.box-grid {
  display: grid;
  grid-gap: 10px;
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 1fr;
}

.box {
  text-align: center;
  border-radius: 10px;
  
  &:before {
    display: inline-block;
    background: #fff;
    color: #000;
    padding: 3px 5px;
    margin-top: 55px;
    font-size: 12px;
    border-radius: 3px;
  }
  
  &:after {
    display: block;
    color: #fff;
    background: rgba(0, 0, 0, 0.8);
    padding: 3px 5px;
    margin-top: 41px;
    font-size: 12px;
    margin-bottom: 10px;
  }
}


/**
 * 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 ) }";
    }
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console