SplitShiftEffect

Developer
Size
6,607 Kb
Views
8,096

How do I make an splitshifteffect?

What is a splitshifteffect? How do you make a splitshifteffect? This script and codes were developed by Takashi on 20 October 2022, Thursday.

SplitShiftEffect Previews

SplitShiftEffect - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Split Shift Effect</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.6.3/dat.gui.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

SplitShiftEffect - Script Codes CSS Codes

html,body{margin: 0; overflow: hidden;}

SplitShiftEffect - Script Codes JS Codes

'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
(function () { var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; window.requestAnimationFrame = requestAnimationFrame;
})();
(function () { var cancelAnimationFrame = window.cancelAnimationFrame || window.mozcancelAnimationFrame || window.webkitcancelAnimationFrame || window.mscancelAnimationFrame; window.cancelAnimationFrame = cancelAnimationFrame;
})();
var windowW = window.innerWidth;
var windowH = window.innerHeight;
var centerW = windowW / 2;
var centerH = windowH / 2;
var shortSide = undefined;
var effector = undefined;
var bgColor = '#002C6A';
var graphicW = 360;
var graphicH = 100;
var word = 'HELLO';
var hasReserve = false;
var guiControls = new function () { this.easing = 'easeInQuad'; this.during = 1000;
}();
var easingMap = new Map();
// easeIn
easingMap.set('easeInQuad', function (t, b, c, d) { return c * (t /= d) * t + b;
});
easingMap.set('easeInCubic', function (t, b, c, d) { return c * (t /= d) * t * t + b;
});
easingMap.set('easeInQuart', function (t, b, c, d) { return c * (t /= d) * t * t * t + b;
});
easingMap.set('easeInQuint', function (t, b, c, d) { return c * (t /= d) * t * t * t * t + b;
});
easingMap.set('easeInSine', function (t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
});
easingMap.set('easeInExpo', function (t, b, c, d) { return t == 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
});
easingMap.set('easeInCirc', function (t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
});
easingMap.set('easeInElastic', function (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; s = p / 4; } else { s = p / (2 * Math.PI) * Math.asin(c / a); } return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
});
easingMap.set('easeInBack', function (t, b, c, d) { var s = undefined; if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b;
});
easingMap.set('easeInBounce', function (t, b, c, d) { return c - easingMap.get('easeOutBounce')(d - t, 0, c, d) + b;
});
// easeOut
easingMap.set('easeOutQuad', function (t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
});
easingMap.set('easeOutCubic', function (t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b;
});
easingMap.set('easeOutQuart', function (t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b;
});
easingMap.set('easeOutQuint', function (t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
});
easingMap.set('easeOutSine', function (t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b;
});
easingMap.set('easeOutExpo', function (t, b, c, d) { return t == d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
});
easingMap.set('easeOutCirc', function (t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
});
easingMap.set('easeOutElastic', function (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; s = p / 4; } else { s = p / (2 * Math.PI) * Math.asin(c / a); } return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
});
easingMap.set('easeOutBack', function (t, b, c, d) { var s = undefined; if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
});
easingMap.set('easeOutBounce', function (t, b, c, d) { if ((t /= d) < 1 / 2.75) { return c * (7.5625 * t * t) + b; } else if (t < 2 / 2.75) { return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b; } else if (t < 2.5 / 2.75) { return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b; } else { return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b; }
});
// easeInOut
easingMap.set('easeInOutQuad', function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * (--t * (t - 2) - 1) + b;
});
easingMap.set('easeInOutCubic', function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b;
});
easingMap.set('easeInOutQuart', function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
});
easingMap.set('easeInOutQuint', function (t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
});
easingMap.set('easeInOutSine', function (t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
});
easingMap.set('easeInOutExpo', function (t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
});
easingMap.set('easeInOutCirc', function (t, b, c, d) { if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
});
easingMap.set('easeInOutElastic', function (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a < Math.abs(c)) { a = c; s = p / 4; } else { s = p / (2 * Math.PI) * Math.asin(c / a); } if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
});
easingMap.set('easeInOutBack', function (t, b, c, d) { var s = undefined; if (s == undefined) s = 1.70158; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= 1.525) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
});
easingMap.set('easeInOutBounce', function (t, b, c, d) { if (t < d / 2) return easingMap.get('easeInBounce')(t * 2, 0, c, d) * .5 + b; return easingMap.get('easeOutBounce')(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
});
function setup() { shortSide = min(windowW, windowH); createCanvas(windowW, windowH); background(bgColor); effector = new SplitShiftEffector(word, graphicW, graphicH, '#F8D99B'); effector.execute(); // setting GUI var gui = new dat.GUI(); guiControls.easing = effector.easingName; guiControls.during = effector.during; var easingKeys = []; for (var _iterator = easingMap, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var _ref2 = _ref; var key = _ref2[0]; easingKeys.push(key); } gui.add(guiControls, 'easing', easingKeys).onChange(function (e) { effector.easing = easingMap.get(e); effector.initEasing(); effector.execute(); }); gui.add(guiControls, 'during', 300, 4000).onChange(function (e) { effector.during = e; effector.initEasing(); effector.execute(); });
}
function draw() { background(bgColor); push(); translate(windowW / 2 - graphicW / 2, windowH / 2 - graphicH / 2); effector.display(); pop(); // restart effect if (!hasReserve && effector.slidePointX_easing.isCompleted) { hasReserve = true; setTimeout(function () { effector.initEasing(); effector.execute(); hasReserve = false; }, 2000); }
}
var EasingFactory = function () { function EasingFactory(prop, b, d, c, engine) { _classCallCheck(this, EasingFactory); this.prop = prop; // target property this.t = 0; // elapsed time this.b = b; // start value this.d = d; // duration this.c = c; // diff value from start value (How to operate the start value) this.startTime; this.engine = engine; this.isCompleted = false; this.isRunning = false; } EasingFactory.prototype.execute = function execute() { this.isRunning = true; this.startTime = Date.now(); this.loop(); }; EasingFactory.prototype.update = function update() { var now = Date.now(); this.t = now - this.startTime; if (this.t < this.d) { this.prop = this.engine(this.t, this.b, this.c, this.d); } else { this.t = this.d; this.prop = this.engine(this.t, this.b, this.c, this.d); this.isCompleted = true; } }; EasingFactory.prototype.loop = function loop() { if (this.isRunning) { var loopId = window.requestAnimationFrame(this.loop.bind(this)); this.update(); if (this.isCompleted) { this.isRunning = false; window.cancelAnimationFrame(loopId); } } }; return EasingFactory;
}();
var SplitShiftEffector = function () { function SplitShiftEffector() { var word = arguments.length <= 0 || arguments[0] === undefined ? 'Oops' : arguments[0]; var w = arguments.length <= 1 || arguments[1] === undefined ? 100 : arguments[1]; var h = arguments.length <= 2 || arguments[2] === undefined ? 50 : arguments[2]; var color = arguments.length <= 3 || arguments[3] === undefined ? '#ffffff' : arguments[3]; var during = arguments.length <= 4 || arguments[4] === undefined ? 2000 : arguments[4]; var easingName = arguments.length <= 5 || arguments[5] === undefined ? 'easeInOutCirc' : arguments[5]; var easing = arguments.length <= 6 || arguments[6] === undefined ? easingMap.get('easeInOutCirc') : arguments[6]; _classCallCheck(this, SplitShiftEffector); this.graphics; this.graphicsW = w; this.graphicsH = h; this.graphics = createGraphics(this.graphicsW, this.graphicsH); this.graphics.background(0, 0, 0, 0); this.graphics.textSize(this.graphicsH); this.graphics.fill(color); this.graphics.noStroke(); this.graphics.text(word, 0, 0, this.graphics.width, this.graphics.height); this.splitNum = this.graphics.height; // max value is this.graphics.height this.rowH = floor(this.graphics.height / this.splitNum); this.slidePointX = this.graphics.width / 2; // easing this.easingName = easingName; this.easing = easing; this.during = during; this.initEasing(); } SplitShiftEffector.prototype.execute = function execute() { if (this.slidePointX_easing) { this.slidePointX_easing.execute(); } }; SplitShiftEffector.prototype.initEasing = function initEasing() { this.slidePointX_easing = new EasingFactory(this.slidePointX, this.slidePointX, this.during, -this.slidePointX, this.easing); }; SplitShiftEffector.prototype.display = function display() { if (this.slidePointX_easing.isRunning && !this.slidePointX_easing.isCompleted) { for (var i = 0; i < this.splitNum; i++) { var randomPoint = undefined; var h = i * this.rowH; randomPoint = floor(random(this.slidePointX_easing.prop * -1, this.slidePointX_easing.prop)); image(this.graphics, // src data randomPoint, h, this.graphics.width, this.rowH, // dx,dy,dw,dh 0, h, this.graphics.width, this.rowH // sx,sy,sw,sh ); } } else { image(this.graphics, 0, 0); } }; return SplitShiftEffector;
}();
SplitShiftEffect - Script Codes
SplitShiftEffect - Script Codes
Home Page Home
Developer Takashi
Username tksiiii
Uploaded October 20, 2022
Rating 3.5
Size 6,607 Kb
Views 8,096
Do you need developer help for SplitShiftEffect?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Takashi (tksiiii) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!