# asobi

> Object to Art. Art to Object. Turn Ruby numbers, strings, arrays, and your own classes into pictures with to_art. Every picture returns as an immutable Ruby object you can hold, arrange, and animate.

- Gem: `asobi` (v0.2.2, Ruby >= 3.2, zero runtime dependencies, MIT License)
- Module: `Asobi` (`require "asobi"` or `require "asobi/pure"` for no core extensions)
- Website: https://asobi.myura.me/
- Japanese Website: https://asobi.myura.me/ja/
- Full LLM Context: https://asobi.myura.me/llms-full.txt
- Markdown on request: every page URL answers in Markdown with `Accept: text/markdown` (`curl -H "Accept: text/markdown" https://asobi.myura.me/reference`)
- Agent Skill: https://asobi.myura.me/.well-known/agent-skills/asobi/SKILL.md
- AI Catalog (ARD): https://asobi.myura.me/.well-known/ai-catalog.json
- Source Code: https://github.com/Hayato1031/asobi
- RubyGems: https://rubygems.org/gems/asobi

## Core Concept: Object to Art. Art to Object.

1. **Object to Art**: Ask any Ruby object for `to_art` (like `to_s` or `to_a`).
   - `Numeric`: circle of that radius (negative = outlined, `0` = nothing, or pass `as: star`).
   - `String` / `Symbol`: text picture (`"asobi".chars.to_art` for per-letter styling).
   - `Array` / `Range`: row of pictures; nested arrays stack into a grid.
   - `Hash`: key picture beside value picture, stacked by entry.
   - Custom classes: define `def to_art` (optionally `include Asobi::Art` to chain words like `spin`, `colored`, `move`).
2. **Art to Object**: Every picture is an immutable Ruby value (`Data` / `Asobi::Art`). Calling `.colored(:crimson)` or `.rotate(45)` returns a new picture without mutating the original—never mutating a global canvas.
3. **Pure-Function Motion**: Animations (`Asobi::Motion`) are pure functions of `seconds -> art`, allowing live browser reload without resetting motion phase and clean `.trail` afterimages.
4. **Reactions and Sound**: A word after a motion says who turns its frames instead of the clock: `when_clicked`, `while_hovered`, `when_pressed("a")`, `on_beat`, or `by(:mouse_x)` / `by(:mic, :low)` / `by(:music)`. `play "song.mp3"` loops a song, and `sounding(:kick)` or `sounding(:c4)` after a reaction plays a synthesized drum sound or note. Editing the code does not restart the song, for live coding and VJ sets.

## Quick Example

```ruby
require "asobi"

class Planet
  include Asobi::Art
  def initialize(size, distance, color, year) = (@size, @distance, @color, @year = size, distance, color, year)
  def to_art = ring(@distance, 0.4).colored(:dimgray) + circle(@size).colored(@color).orbit(@distance, every: @year)
end

stars = [3, 1, 4, 1, 5, 9].to_art(as: star).in_ring(38).colored(:hotpink, :gold, :cyan)
show stars.spin(every: 6).glowing, on: :black, grain: true
```

## Documentation Pages (HTML & Markdown)

- [Home (English)](https://asobi.myura.me/) · [Markdown](https://asobi.myura.me/index.md): Overview, Object ⇄ Art loop, live stage, FAQ
- [Getting Started (12 chapters)](https://asobi.myura.me/guide) · [Markdown](https://asobi.myura.me/guide.md): Step-by-step tutorial
- [Reference (79 words)](https://asobi.myura.me/reference) · [Markdown](https://asobi.myura.me/reference.md): Complete API vocabulary with live SVG examples
- [Examples (16 pieces)](https://asobi.myura.me/examples) · [Markdown](https://asobi.myura.me/examples.md): Finished sketches
- [Browser Playground (ruby.wasm)](https://asobi.myura.me/playground) · [Markdown](https://asobi.myura.me/playground.md): Zero-install live Ruby editor
- 日本語: [トップ](https://asobi.myura.me/ja/) · [はじめかた](https://asobi.myura.me/ja/guide.md) · [リファレンス](https://asobi.myura.me/ja/reference.md) · [見本集](https://asobi.myura.me/ja/examples.md) · [遊び場](https://asobi.myura.me/ja/playground.md)

## Vocabulary Index (79 words in 10 groups)

- **shapes** (22): `circle`, `ellipse`, `rect`, `square`, `triangle`, `polygon`, `star`, `line`, `text`, `path`, `arc`, `wave`, `ring`, `heart`, `petal`, `moon`, `drop`, `cloud`, `space`, `nothing`, `hsl`, `gray`
- **combine** (7): `on`, `under`, `+`, `repeat`, `*`, `beside`, `above`
- **change** (7): `move`, `rotate`, `scale`, `grow`, `shrink`, `mirror`, `flip`
- **color** (4): `colored`, `outlined`, `stroke`, `opacity`
- **effect** (5): `glowing`, `blurred`, `blended`, `shadowed`, `clipped_by`
- **arrange** (8): `in_row`, `in_column`, `in_grid`, `in_ring`, `in_fan`, `in_spiral`, `scattered`, `change_each`
- **to_art** (1): `to_art`
- **motion** (13): `spin`, `pulse`, `sway`, `orbit`, `fade`, `flash`, `bounce`, `drift`, `shift_color`, `one_by_one`, `trail`, `animate`, `at`
- **react** (7): `when_clicked`, `while_hovered`, `when_pressed`, `on_beat`, `by`, `sounding`, `play`
- **show** (5): `show`, `save`, `to_svg`, `bounds`, `turn`
