Скрипт анимированной текстуры для элемента canvas
Популярные запросы: Open Graph, плагин Reading Time, тема Quebec, плагин Telegram, набор иконок Analogue
Скрипт анимированной текстуры для элемента canvas
var livePattern = {
canvas: null,
context: null,
cols: 0,
rows: 0,
colors: [252, 251, 249, 248, 241, 240],
triangleColors: [],
destColors: [],
init: function() {
this.canvas = document.getElementById('canvas');
this.context = this.canvas.getContext('2d');
this.cols = Math.floor(document.body.clientWidth / 24);
this.rows = Math.floor(document.body.clientHeight / 24) + 1;
this.canvas.width = document.body.clientWidth;
this.canvas.height = document.body.clientHeight;
this.drawBackground();
this.animate();
},
drawTriangle: function(x, y, color, inverted) {
inverted = inverted == undefined ? false : inverted;
this.context.beginPath();
this.context.moveTo(x, y);
this.context.lineTo(inverted ? x - 22 : x + 22, y + 11);
this.context.lineTo(x, y + 22);
this.context.fillStyle = "rgb("+color+","+color+","+color+")";
this.context.fill();
this.context.closePath();
},
getColor: function() {
return this.colors[(Math.floor(Math.random() * 6))];
},
drawBackground: function() {
var eq = null;
var x = this.cols;
var destY = 0;
var color, y;
while (x--) {
eq = x % 2;
y = this.rows;
while (y--) {
destY = Math.round((y-0.5) * 24);
this.drawTriangle(x * 24 + 2, eq == 1 ? destY : y * 24, this.getColor());
this.drawTriangle(x * 24, eq == 1 ? destY : y * 24, this.getColor(), true);
}
}
},
animate: function() {
var me = this;
var x = Math.floor(Math.random() * this.cols);
var y = Math.floor(Math.random() * this.rows);
var eq = x % 2;
if (eq == 1) {
me.drawTriangle(x * 24, Math.round((y-0.5) * 24) , this.getColor(), true);
} else {
me.drawTriangle(x * 24 + 2, y * 24, this.getColor());
}
setTimeout(function() {
me.animate.call(me);
}, 10);
},
};
!function() {
livePattern.init();
}();
$(window).resize(function() {
livePattern.init();
});
- Создан: 10.03.26 @ 16:05
- Будет удален: никогда
- Просмотры сниппета: 10
- Тип кода: JavaScript
- Владелец: admin
Новые сниппеты:
-
Шаблон редактирования страницы для Cotonti Siena (grid-модель)
Просмотры: 11
Дата: 05.03.26 @ 12:42 -
Шаблон добавления страницы для Cotonti Siena (grid-модель)
Просмотры: 10
Дата: 05.03.26 @ 11:50 -
Отображаем шапку сайта при скролле вверх в мобильной версии
Просмотры: 9
Дата: 18.02.26 @ 11:30 -
Блокиратор ботов в User-Agent
Просмотры: 11
Дата: 04.02.26 @ 17:55 -
Адаптивный шаблон редактирования страницы
Просмотры: 53
Дата: 22.01.26 @ 10:47 -
IP-диапазоны Biterika Grupp для блокировки
Просмотры: 26
Дата: 20.01.26 @ 13:07 -
Скрипт кастомизации формы поиска в стиле Github
Просмотры: 24
Дата: 18.01.26 @ 20:01 -
LESS mixin для верстки моделью grid с обводкой
Просмотры: 23
Дата: 16.01.26 @ 20:47 -
Блок вывода статистики страницы с помощью плагина Reading Time
Просмотры: 27
Дата: 16.01.26 @ 13:50 -
Функция минификации CSS и JS ресурсов
Просмотры: 42
Дата: 14.01.26 @ 20:08