The screen turns on when you connect the cable. Create a wiring puzzle with JavaScript and SVG
Web demo that connects cables by dragging terminals. We will explain SVG curves, Sets for managing connection status, determining correct connections, and alternative operations using buttons.
It's fun to touch. You can understand by making it. A small laboratory for the web. Run it first, and if you feel like it, open the code and try changing one thing.
First, try touching it.
Drag from the round terminal to the connection destination. You can also connect by selecting two buttons below.
Recipe for how to play
Video output → input Power supply output → input
This is a model that plays with the idea of connection. It does not reproduce the terminals and compatibility of the actual product.
Ready.
The device's "Reduce parallax effect" setting suppresses movement when displaying images.
For a playful CTA. If you transform using transform, the position of the surrounding text will not change. Even if you hit repeatedly, the animation will not overlap.
For feedback on successful operations, such as copy completion. This model only increases the number of marks when you press it, but does not save or send it. There can be up to 6 marks.
status.textContent = 'コピーしました';
None of these demos plays sound. Animations are skipped when your device requests reduced motion.
Try them in this order and you'll see the difference.
Connect the PC's video output and the monitor's video input. The line appears, but the screen does not light up yet.
Also connect the PC's power input to the charger's power output. The connection is complete when “Hello, lab!” appears.
You can also select the same two sets with the terminal buttons below. Also check the instructions when selecting a different type of terminal.
To run it on your own computer.
The entire demo on this page is in a public repository. Below are the steps to copy and run the site. The short code snippet above won't work.
1. Check the execution environment
Open a terminal and run it line by line. Requires Git and Node.js.
git --version
node --version
npm --version
Results to check: Each command should display a version number. This project requires Node.js 22.12.0 or later. If a command is missing, use Git official and Node.js official to set up your environment.
2. Get the code and launch
Move to the folder you want to save it to, then execute the following line by line. If a folder with the same name already exists, choose a different location.
git clone https://github.com/R-Koda/ryu-koda.com.git
cd ryu-koda.com
npm ci
npm run dev -- --host 127.0.0.1 --port 4321
Results to check:Finally, the local server URL will be displayed and the terminal will remain open. If an error occurs, do not proceed and check the output of the previous command.
3. Open the experiment page
Open http://127.0.0.1:4321/playground/cables/ in your browser. If the same demo appears and responds as described above, it is running successfully. If Terminal shows a different port, use that port instead. Press Ctrl+C in Terminal to stop the server.
Which file should I read?
src/components/Experiment.astro:SVG, HTML, CSS for appearance.
src/scripts/experiments.ts contains the experiment interactions. Look for if(kind==='cables').
src/pages/playground/[slug].astro: Common layout for this explanation page.
If the screen is white, check your terminal for errors and your browser's developer tools. If the movement stops, also check the "Reduce parallax effect" setting on your device. This demo will suppress movement according to that setting.
How does it work?
Point 1
Reorder the terminal identifiers into a single key and match it against the Set of allowed combinations. Even if the order of selection is reversed, it can be treated as the same connection.
Point 2
Store connected pairs in a Set as well. This prevents repeated attempts at the same connection from creating endless duplicate lines.
Point 3
Draw a curve using the SVG path, and switch the screen color and text only when there is both video and power. Dragging and button operations update the same connection state.
Try changing one thing and compare.
Open src/scripts/experiments.ts in your editor and find the branch for this experiment.
What to change:Let's temporarily remove power&& from the judgment equivalent to const on in the cables draw (on=power&&connected.has('monitor:pc-video')).
Result changes:The screen will now light up with the video connection alone. Restore the code and it will need both cables again. This experiment changes the outcome through state conditions, not styling.
Once saved, return to your browser and reload if necessary. Make a note of the original values so you can quickly go back and compare.
before incorporating it into your site.
It does not reproduce the terminal types, standards, or power supply conditions of the actual product. A puzzle for learning conditional branching and state management.
Instead of conveying information through movement alone, it can also be used with keyboard operations and settings that reduce movement. First, incorporate it into one part and make sure that it does not interfere with the readability of articles and menus.