diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-07-17 23:38:25 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-07-17 23:38:25 +0900 |
| commit | b7cb7d848a4535d89df9f1fbf7f91984f7f11298 (patch) | |
| tree | 612eaa3f7062b35f84fe235c38b74847a2092e12 /static/my-icon.js | |
| parent | fe8551d8d8cefa0130ca0a21c6a5816b45ff13dc (diff) | |
| download | blog.nsfisis.dev-b7cb7d848a4535d89df9f1fbf7f91984f7f11298.tar.gz blog.nsfisis.dev-b7cb7d848a4535d89df9f1fbf7f91984f7f11298.tar.zst blog.nsfisis.dev-b7cb7d848a4535d89df9f1fbf7f91984f7f11298.zip | |
feat(content): apply mosaic effects to my icon in about page
Diffstat (limited to 'static/my-icon.js')
| -rw-r--r-- | static/my-icon.js | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/static/my-icon.js b/static/my-icon.js index ec12d4d..5b52ca3 100644 --- a/static/my-icon.js +++ b/static/my-icon.js @@ -31,10 +31,40 @@ function draw() { clear(); draw蜜柑(); + applyMosaicEffect([10, 5, 2, 0][frameCount % 15]); drawMosaic(); drawEyes(); } +function applyMosaicEffect(k) { + if (k === 0) { + return; + } + + loadPixels(); + noStroke(); + const d = pixelDensity(); + for (let y = 0; y < 100; y += k) { + for (let x = 50; x < 100; x += k) { + var r = 0, g = 0, b = 0; + for (let i = 0; i < k; i++) { + for (let j = 0; j < k; j++) { + const offset = 4 * d * ((y + i) * 100 * d + (x + j)); + const r_ = pixels[offset]; + const g_ = pixels[offset + 1]; + const b_ = pixels[offset + 2]; + const a_ = pixels[offset + 3]; + r += a_ === 0 ? red(colorBackground) : r_; + g += a_ === 0 ? green(colorBackground) : g_; + b += a_ === 0 ? blue(colorBackground) : b_; + } + } + fill(r / k**2, g / k**2, b / k**2); + rect(x, y, k, k); + } + } +} + function draw蜜柑() { // 果実、外果皮 fill(color蜜柑の果実); @@ -55,8 +85,8 @@ function draw蜜柑() { translate(50, 50); rotate(t * PI / 5); line(0, -45, 0, 0); - triangle(0, -40, -04, -45, 04, -45); - triangle(0, -20, -03, 0, 03, 0); + triangle(0, -40, -4, -45, 4, -45); + triangle(0, -20, -3, 0, 3, 0); pop(); } } @@ -86,6 +116,6 @@ function drawMosaic() { function drawEyes() { noStroke(); fill(colorEye); - rect(30, 35, 06, 25, 2); - rect(64, 35, 06, 25, 2); + rect(30, 35, 6, 25, 2); + rect(64, 35, 6, 25, 2); } |
