GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Screenshot of web page (detail, start of Source Code section) at URL https://ar.al/2024/03/26/draw-together/: Source code The code sets up a real-time collaborative drawing tool on a 20×20 pixel grid where people can click to toggle the colour of each pixel. Here’s a breakdown of the entire source code, detailing what each section does: Create 20×20 pixel grid const rows = new Array(20).fill().map(row => new Array(20).fill(0)) const colours = ['white', 'black'] Creates a 20x20 grid initialized with zeros. Each cell will store an index corresponding to the colours array. Validation function const isValid = data => typeof data === 'object' && typeof data.rowIndex === 'number' && typeof data.columnIndex === 'number' && data.rowIndex >= 0 && data.rowIndex <= rows.length-1 && data.columnIndex >= 0 && data.columnIndex <= rows[0].length-1 Checks if the data object has valid rowIndex and columnIndex within grid bounds. Handle connections and pixel updates export function onConnect ({ page }) { page.on('pixel', data => { if (!isValid(data)) return

Download link

https://s3-eu-central-1.amazonaws.com/mastodon-aral/media_attachments/files/113/323/781/892/923/594/original/2c7d94459b34096d.png

Notices where this attachment appears

  1. Embed this notice
    Aral Balkan (aral@mastodon.ar.al)'s status on Friday, 18-Oct-2024 01:54:19 JST Aral Balkan Aral Balkan

    Just added a code breakdown for the Draw Together¹ Kitten² app to my blog post with the tutorial video:

    https://ar.al/2024/03/26/draw-together/

    Draw Together, in ~50 lines of code, is a real-time collaborative drawing tool on a 20×20 pixel grid where people can click to toggle the colour of each pixel.

    (The full source and explanations fit the four screenshots on this post.)

    ¹ https://draw-together.small-web.org
    ² https://kitten.small-web.org

    #Kitten #DrawTogether #web #design #dev #SmallWeb #WebSockets #StreamingHTML

    In conversation about a year ago from mastodon.ar.al permalink
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.