Created
October 4, 2022 16:53
-
-
Save garyanikin/04929bb7c6853b651b22b2edb5833df4 to your computer and use it in GitHub Desktop.
Код для генерации сторис НФТ аватарка
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvasWidth = 1080; | |
const canvasHeight = 1920; | |
const center = [canvasWidth, canvasHeight].map(divideBy2); | |
// Полотно для создания размытого фона | |
const blurredSize = 1 / 8; | |
const blurredWidth = canvasWidth * blurredSize; | |
const blurredHeight = canvasHeight * blurredSize; | |
// Настройка бейджа с нфт аватаркой | |
const mountSize = 814; | |
const borderWidth = 24; | |
const tokenSize = mountSize - borderWidth * 4; | |
let tokenImage, tokenImageBg, overlay, mount, caption, clip; | |
const captionTop = canvasHeight / 5; | |
let now; | |
let blurred; | |
function preload() { | |
tokenImageBg = loadImage("./image.jpeg"); | |
tokenImage = loadImage("./image.jpeg"); | |
overlay = loadImage("./bg_overlay.svg"); | |
mount = loadImage("./mount.svg"); | |
caption = loadImage("./story_caption.svg"); | |
clip = loadImage("./clip.png"); | |
} | |
function setup() { | |
pixelDensity(1); | |
createCanvas(canvasWidth, canvasHeight); | |
noLoop(); | |
blurred = createGraphics(blurredWidth, blurredHeight); | |
imageMode(CENTER); | |
blurred.imageMode(CENTER); | |
} | |
function draw() { | |
now = millis(); | |
imageMode(CENTER); | |
// blurred background | |
renderBackground(); | |
// overlay with heptagons | |
renderOverlay(); | |
// caption (story_caption.svg) | |
renderCaption(); | |
// mount | |
renderMount(); | |
// masked image | |
renderToken(); | |
} | |
function renderBackground() { | |
if (tokenImageBg.width < tokenImageBg.height) { | |
// vertical image | |
tokenImageBg.resize(blurredWidth, 0); | |
} else { | |
// horizontal and square | |
tokenImageBg.resize(0, blurredHeight); | |
} | |
blurred.image( | |
tokenImageBg, | |
divideBy2(blurredWidth), | |
divideBy2(blurredHeight) | |
); | |
blurred.filter(BLUR, 20); | |
image(blurred, ...center, width, height); | |
} | |
function renderOverlay() { | |
blendMode(OVERLAY); | |
image(overlay, ...center); | |
blendMode(BLEND); | |
} | |
function renderCaption() { | |
image(caption, center[0], captionTop); | |
} | |
function renderMount() { | |
image(mount, ...center); | |
} | |
function renderToken() { | |
tokenImage.resize(tokenSize, 0); | |
tokenImage.mask(clip); | |
image(tokenImage, ...center); | |
} | |
function divideBy2(v) { | |
return v / 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment