JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
<div class="target">Sass calculated matrix3d<span></span></div>
<div class="target2">Native transform<span></span></div>
// Jump to the very bottom to see where _multiply is called~ :D
$pi: 3.14159265359;
@function _exp($base, $exp) {
$value: 1;
@if $exp > 0 {
@for $i from 0 through ($exp - 1) {
$value: $value * $base;
}
}
@return $value;
}
@function _fact($val) {
$value: 1;
@if $val > 0 {
@for $i from 1 through $val {
$value: $value * $i;
}
}
@return $value;
}
/* Taylor cos approximation series */
@function _sin($angle) {
$angle: $angle / 180 * $pi;
$sin: 0;
@for $n from 0 through 10 {
$sin: $sin + _exp(-1, $n) * _exp($angle, (2 * $n) + 1) / _fact(($n * 2) + 1);
}
@return $sin;
}
/* Sin tests */
/*
@debug "sin(0) " + _sin(0);
@debug "sin(90) " + _sin(90);
@debug "sin(180) " + _sin(180);
@debug "sin(270) " + _sin(270);
*/
/* Taylor cos approximation series */
@function _cos($angle) {
$angle: $angle / 180 * $pi;
$cos: 0;
@for $n from 0 through 10 {
$cos: $cos + _exp(-1, $n) * _exp($angle, 2 * $n) / _fact($n * 2);
}
@return $cos;
}
/* Cos tests */
/*
@debug "cos(0) " + _cos(0);
@debug "cos(90) " + _cos(90);
@debug "cos(180) " + _cos(180);
@debug "cos(270) " + _cos(270);
*/
@function _tan($angle) {
$angle: $angle / 180 * $pi;
$tan: _sin($angle) / _cos($angle);
@return $tan;
}
/* Stupid sass matrix multiplication bahahahahahahaa.... XD */
@function _multiply($m1, $m2) {
$m1_j1: nth($m1, 1);
$m1_j2: nth($m1, 2);
$m1_j3: nth($m1, 3);
$m1_j4: nth($m1, 4);
$m2_j1: nth($m2, 1);
$m2_j2: nth($m2, 2);
$m2_j3: nth($m2, 3);
$m2_j4: nth($m2, 4);
$m1_i1_j1: nth($m1_j1, 1);
$m1_i2_j1: nth($m1_j1, 2);
$m1_i3_j1: nth($m1_j1, 3);
$m1_i4_j1: nth($m1_j1, 4);
$m1_i1_j2: nth($m1_j2, 1);
$m1_i2_j2: nth($m1_j2, 2);
$m1_i3_j2: nth($m1_j2, 3);
$m1_i4_j2: nth($m1_j2, 4);
$m1_i1_j3: nth($m1_j3, 1);
$m1_i2_j3: nth($m1_j3, 2);
$m1_i3_j3: nth($m1_j3, 3);
$m1_i4_j3: nth($m1_j3, 4);
$m1_i1_j4: nth($m1_j4, 1);
$m1_i2_j4: nth($m1_j4, 2);
$m1_i3_j4: nth($m1_j4, 3);
$m1_i4_j4: nth($m1_j4, 4);
$m2_i1_j1: nth($m2_j1, 1);
$m2_i2_j1: nth($m2_j1, 2);
$m2_i3_j1: nth($m2_j1, 3);
$m2_i4_j1: nth($m2_j1, 4);
$m2_i1_j2: nth($m2_j2, 1);
$m2_i2_j2: nth($m2_j2, 2);
$m2_i3_j2: nth($m2_j2, 3);
$m2_i4_j2: nth($m2_j2, 4);
$m2_i1_j3: nth($m2_j3, 1);
$m2_i2_j3: nth($m2_j3, 2);
$m2_i3_j3: nth($m2_j3, 3);
$m2_i4_j3: nth($m2_j3, 4);
$m2_i1_j4: nth($m2_j4, 1);
$m2_i2_j4: nth($m2_j4, 2);
$m2_i3_j4: nth($m2_j4, 3);
$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$m1_i2_j3 * $m2_i4_j2 + $m1_i3_j3 * $m2_i4_j3 + $m1_i4_j3 * $m2_i4_j4
),
(
$m1_i1_j4 * $m2_i1_j1 + $m1_i2_j4 * $m2_i1_j2 + $m1_i3_j4 * $m2_i1_j3 + $m1_i4_j4 * $m2_i1_j4,
$m1_i1_j4 * $m2_i2_j1 + $m1_i2_j4 * $m2_i2_j2 + $m1_i3_j4 * $m2_i2_j3 + $m1_i4_j4 * $m2_i2_j4,
$m1_i1_j4 * $m2_i3_j1 + $m1_i2_j4 * $m2_i3_j2 + $m1_i3_j4 * $m2_i3_j3 + $m1_i4_j4 * $m2_i3_j4,
$m1_i1_j4 * $m2_i4_j1 + $m1_i2_j4 * $m2_i4_j2 + $m1_i3_j4 * $m2_i4_j3 + $m1_i4_j4 * $m2_i4_j4
)
);
}
/* Return a unity (no transform) matrix */
@function _unity() {
@return (
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
(0, 0, 0, 1)
);
}
/* Convert a 4x4 matrix into a string */
@function _unify($matrix) {
$rtn: '';
@each $row in $matrix {
@each $item in $row {
@if $rtn == '' {
$rtn: '' + $item;
} @else {
$rtn: $rtn + ', ' + $item;
}
}
}
@return unquote($rtn);
}
/* A scale matrix */
@function _scale($x, $y, $z) {
@return (
($x, 0, 0, 0),
(0, $y, 0, 0),
(0, 0, $z, 0),
(0, 0, 0, 1)
);
}
/* Rotation matrix for x, y, z */
@function _rotateX($angle) {
$angle: -$angle; // Match CSS transform
@return (
(1, 0, 0, 0),
(0, _cos($angle), _sin(-$angle), 0),
(0, _sin($angle), _cos( $angle), 0),
(0, 0, 0, 1)
);
}
@function _rotateY($angle) {
$angle: -$angle; // Match CSS transform
@return (
(_cos($angle), 0, _sin($angle), 0),
(0, 1, 0, 0),
(_sin(-$angle), 0, _cos($angle), 0),
(0, 0, 0, 1)
);
}
@function _rotateZ($angle) {
$angle: -$angle; // Match CSS transform
@return (
(_cos($angle), _sin(-$angle), 0, 0),
(_sin($angle), _cos($angle), 0, 0),
(0, 0, 1, 0),
(0, 0, 0, 1)
);
}
/* A translate matrix */
@function _translate($x, $y, $z) {
@return (
(1, 0, 0, 0),
(0, 1, 0, 0),
(0, 0, 1, 0),
($x, $y, $z, 1)
);
}
$matrix3d: _unity();
$matrix3d: _multiply($matrix3d, _rotateX(20));
$matrix3d: _multiply($matrix3d, _rotateY(15));
$matrix3d: _multiply($matrix3d, _rotateZ(10));
$matrix3d: _multiply($matrix3d, _translate(50, 50, 0));
$matrix3d: _multiply($matrix3d, _scale(2, 2, 2));
$matrix3d: _unify($matrix3d);
body {
div {
position: absolute;
display: inline-block;
width: 100px;
height: 100px;
border: 1px solid #222;
border-radius: 1px;
padding: 10px;
color: #333;
font-family: arial;
font-size: 10px;
box-shadow: 10px 10px 5px #888888;
span:after {
clear:both;
display: block;
width: 100%;
margin-top: 10px;
font-weight: bold;
font-size: 6px;
color: #000;
}
}
}
.target {
background: #7fff7f;
transform: matrix3d($matrix3d);
-webkit-transform: matrix3d($matrix3d);
span:after {
content: "transform: matrix3d(" + $matrix3d + ")";
}
}
.target2 {
background: #7f7fff;
transform: scaleX(2) scaleY(2) scaleZ(2) translate3d(250px, 50px, 0) rotateZ(10deg) rotateY(15deg) rotateX(20deg);
-webkit-transform:scaleX(2) scaleY(2) scaleZ(2) translate3d(250px, 50px, 0) rotateZ(10deg) rotateY(15deg) rotateX(20deg);
span:after {
content: "transform: scaleX(2) scaleY(2) scaleZ(2) translate3d(250px, 50px, 0) rotateZ(10deg) rotateY(15deg) rotateX(20deg)";
}
}
Also see: Tab Triggers