跳到正文
DEV Community· Code Lead Grow·· 3 小時前AI 評分42

我的電燈開關吉祥物:用 4 張圖片、mix-blend-mode 和幾行 JS 製作

My light-switch mascot: 4 images, mix-blend-mode and a few lines of JS

AI 導讀

作者拆解了一個電燈開關吉祥物的實作,發現只需 4 張圖片、CSS 的 mix-blend-mode 和少量 JS。吉祥物以一張全燈關閉及三張各自亮起一盞燈的圖片疊加,混合光色;開關聲則由幾行 JS 交由瀏覽器生成,毋須 mp3 檔。

正文

Code Lead Grow

I love front-end work, but life took me elsewhere: years of coding whatever came along, and I never got deep into it. Now, with AI, I can finally learn while I build.

A while ago I saw a mascot with three light switches around it. Click one and its lamp turns on or off, and the light falls on the character. I loved it, so I asked AI to research it and make one like it.

It was done fast, and then I realised I had no idea how it worked. So I sat down and took it apart. I expected three.js or something complicated. It turned out all it takes is:

  • 4 images: one with every lamp off, and three with one lamp on each. Stack them and let CSS blend them; with 2 or 3 lamps on at once, the colours still mix well.
  • The main CSS property doing the blending is mix-blend-mode.
  • The images themselves: ask Gemini or ChatGPT to draw them.
  • For the click when a lamp switches, AI wrote a few lines of JS so the browser makes the sound itself. No mp3 file at all.

I put the whole process into a talk. Here's a short video that pulls out the principles underneath:

If you want to dig deeper, open the slides and turn on autopilot, and they present themselves: https://vibe-coding-a-light-switch-mascot.codeleadgrow.workers.dev/?src=devto

Slide 9 keeps exactly how I prompted, and re-prompted, until it came out right. Honestly, that part was painful. I'm still looking for a better way. Ha ha.

Want more, or the next parts as they come out? Follow me on Facebook: https://www.facebook.com/codeleadgrow

Building in public 2026 · part 1: Vibe-Coding a Light-switch Mascot

I wrote this post in Vietnamese; AI helped me translate it.

來源:DEV Community · dev.to