Skip to content

About

Interactive Suminagashi Fluid Simulation using C++ and Raylib. Create mesmerizing marbled patterns inspired by traditional Japanese ink art. Features real-time drop deformation, adaptive edge noise, and dynamic vertex resolution for smooth, fluid visuals. Runs natively and in the browser via Emscripten.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒŠ Suminagashi - Digital Paper Marbling

License C++ Raylib WebAssembly

A modern, interactive web application that brings the ancient Japanese art of Suminagashi (paper marbling) to your browser. Create beautiful, flowing patterns with dynamic color palettes using cutting-edge web technologies.

Suminagashi Demo

๐ŸŽจ What is Suminagashi?

Suminagashi (ๅขจๆตใ—, "floating ink") is a traditional Japanese paper marbling technique that dates back to the 12th century. Artists drop ink onto water's surface, manipulate the patterns with brushes or breath, then transfer the design onto paper. This digital recreation captures the essence of this meditative art form.

โœจ Features

๐ŸŽฏ Core Features

  • Interactive Canvas: Click anywhere to create marbling drops
  • Vertical Tine Tool: Carve elegant vertical deformations into existing patterns
    • Smooth Falloff: Non-linear quintic smoothing for natural edges
    • Adjustable Strength: Control displacement intensity (0-400 pixels)
    • Variable Sharpness: Adjust influence radius and concentration (1-256)
    • Diminishing Returns: Prevents over-carving with cumulative displacement limits
  • Dual Interaction Modes: Toggle between Drops and Tine modes
    • Keyboard Shortcut: Press T to switch modes instantly
    • Visual Feedback: Clear mode indicators and status text
  • 15 Beautiful Color Palettes: Carefully curated themes including:
    • Traditional Japanese Suminagashi (indigo & gray)
    • Turkish Ebru Classic (vibrant traditional colors)
    • Venetian Marble (warm stone tones)
    • Cherry Blossom (soft pink gradients)
    • Ocean, Forest, Sunset, and more!
  • Dynamic Color Selection: Each drop randomly selects from themed palettes
  • Real-time Marbling Simulation: Drops interact to create organic patterns
  • Screenshot Capture: Save your artwork as PNG images
  • Responsive Design: Works on desktop, tablet, and mobile
  • Quality Modes: Performance, Balanced, and High DPR presets for browser rendering
  • Layout Sync: Canvas CSS size and framebuffer size stay synchronized on resize and orientation changes
  • Autosave: Restores the last used controls, preset, and export options on reload

๐Ÿ› ๏ธ Technical Features

  • WebAssembly Performance: Compiled C++ code for near-native speed
  • WebGL Rendering: Hardware-accelerated graphics
  • Modern Web Interface: Dark theme with developer-friendly design
  • Cross-platform: Runs in any modern web browser

๐Ÿš€ Live Demo

Try it online โ†’

๐Ÿ—๏ธ Architecture

suminasashi_web_final/
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ main.cpp             # Entry point and loop selection
โ”‚   โ”œโ”€โ”€ app.cpp              # App lifecycle, drawing, viewport sync
โ”‚   โ”œโ”€โ”€ app.h                # App interface and runtime state
โ”‚   โ”œโ”€โ”€ web_exports.cpp      # JS-callable C exports
โ”‚   โ”œโ”€โ”€ screenshot.cpp       # Native screenshot helpers
โ”‚   โ”œโ”€โ”€ Drops.cpp            # Drop physics and rendering
โ”‚   โ”œโ”€โ”€ drops.h              # Drop class declaration
โ”‚   โ”œโ”€โ”€ colors.cpp           # Color palette management
โ”‚   โ””โ”€โ”€ colors.h             # ColorPalette class declaration
โ”œโ”€โ”€ ๐Ÿ“ docs/                 # Web deployment
โ”‚   โ”œโ”€โ”€ index.html           # Modern web interface
โ”‚   โ”œโ”€โ”€ app.js               # Browser runtime bridge and layout manager
โ”‚   โ”œโ”€โ”€ suminasashi.js       # Compiled WebAssembly
โ”‚   โ””โ”€โ”€ suminasashi.wasm     # Binary WebAssembly module
โ”œโ”€โ”€ ๐Ÿ“ build/                # Build artifacts
โ”œโ”€โ”€ CMakeLists.txt           # Build configuration
โ””โ”€โ”€ README.md               # This file

๐Ÿ› ๏ธ Building from Source

Prerequisites

  1. Emscripten SDK

    git clone https://github.com/Sandeep-003/Suminagashi.git
    cd emsdk
    ./emsdk install latest
    ./emsdk activate latest
    source ./emsdk_env.sh
  2. CMake (3.10+)

  3. Modern C++ Compiler (C++17 support)

Build Steps

  1. Clone the repository

    git clone https://github.com/Sandeep-003/Suminagashi.git
    cd Suminagashi
  2. Activate Emscripten environment

    source path/to/emsdk/emsdk_env.sh  # Linux/macOS
    # or
    path\to\emsdk\emsdk_env.bat        # Windows
  3. Configure and build

    mkdir build && cd build
    emcmake cmake ..
    emmake cmake --build .
  4. Deploy to web

    cp web/suminasashi.js ../docs/
    cp web/suminasashi.wasm ../docs/

The browser shell reads the wasm bundle with a cache-busting query string, so replace both files together during deployment.

GitHub Pages Deploy

The repository is set up to publish from GitHub Actions using the site in docs/.

  1. Push to main or run the workflow manually from the Actions tab.
  2. The workflow builds the web target with Emscripten, copies the generated suminasashi.js and suminasashi.wasm into a temporary Pages site, and deploys it.
  3. In the repository settings, enable Pages with the source set to GitHub Actions if it is not already enabled.

Development Build (Native)

For faster development cycles, you can build natively:

mkdir build-native && cd build-native
cmake ..
make
./suminasashi

๐ŸŽฎ Usage

Web Interface

  1. Visit the live demo or serve locally
  2. Click on canvas to create drops
  3. Watch patterns emerge as drops interact
  4. Save screenshots using the button
  5. Experiment with different clicking patterns

Controls

  • Left Click (Drops Mode): Create a new drop with random color
  • Left Click (Tine Mode): Apply vertical carving deformation at cursor position
  • T Key: Toggle between Drops and Tine interaction modes
  • Strength Slider: Adjust tine displacement intensity (0-400 pixels)
  • Sharpness Slider: Control tine influence radius and falloff steepness (1-256)
  • Screenshot Button: Save current canvas as PNG
  • Clear Button: Reset the canvas
  • Fullscreen Button: Toggle fullscreen mode
  • Quality Buttons: Switch between Performance, Balanced, and High canvas scaling
  • Preset Menu: Load curated palette and control presets
  • Export Options: Set filename prefix and timestamped export naming
  • Reset View / Fit Canvas: Re-sync the browser layout or restore the current preset

๐ŸŽจ Color Palettes

The application features 15 carefully designed color palettes:

Palette Description Colors
Sunset Warm coral, orange, golden tones ๐ŸŸ ๐ŸŸก๐ŸŸค
Ocean Cool blues and teals ๐Ÿ”ต๐ŸŸฆ๐Ÿ’™
Traditional Japanese Classic indigo and gray โšซ๐Ÿ”ตโšช
Turkish Ebru Vibrant traditional marbling colors ๐Ÿ”ด๐ŸŸก๐ŸŸข๐Ÿ”ต
Venetian Marble Warm stone and earth tones ๐ŸŸค๐ŸŸซโšช
Cherry Blossom Soft pink gradients ๐ŸŒธ๐Ÿ’—๐Ÿฉท
Jade Garden Teal and aquamarine tones ๐ŸŸข๐Ÿ’š๐Ÿ”ท
Royal Purple Luxurious purple and gold ๐ŸŸฃ๐ŸŸก๐Ÿ‘‘
Midnight Blues Deep blue gradients ๐ŸŒŒ๐Ÿ”ต๐Ÿ’™
Earth Tones Natural browns and beiges ๐ŸŸซ๐ŸŸค๐ŸคŽ
Copper Verdigris Metallic copper with oxidized green ๐ŸŸซ๐ŸŸข๐Ÿ’š
Wine & Cream Deep reds with creamy whites ๐Ÿทโšช๐Ÿ”ด

๐Ÿงช Technical Implementation

Core Classes

ColorPalette

class ColorPalette {
    using ColorValue = std::array<int, 4>; // RGBA
    using Palette = std::vector<ColorValue>;
    
public:
    ColorPalette();                    // Random palette selection
    ColorValue getColor();             // Random color from current palette
    static void addPalette(const Palette& palette);
    static const std::vector<Palette>& getAllPalettes();
};

Drop

class Drop {
    Vector2 center;
    double radius;
    color clr;
    std::vector<Vector2> vertices;
    std::vector<Vector2> baseVertices; // Stable reference for cumulative operations
    
public:
    Drop(float x, float y, color clr, double radius, int n);
    void Draw_drops();
    void marble(const Drop& other);           // Interaction with other drops
    void applyVerticalTine(float x, float strength, float sharpness, bool commitBase=true);
    void wavy_transformation();              // Visual effects
    void applyEdgeNoise(float amplitude, float frequency, float time);
    void animateShape(float time, float amplitude, float speed, int harmonics=1);
};

Rendering Pipeline

  1. Initialization: Setup Raylib window and WebGL context
  2. Input Handling: Detect mouse clicks for drop creation
  3. Physics Update: Calculate drop interactions and marbling effects
  4. Rendering: Draw all drops with WebGL acceleration
  5. Screenshot: Capture WebGL framebuffer for image export

WebAssembly Integration

  • Emscripten: Compiles C++ to WebAssembly
  • WebGL: Hardware-accelerated graphics rendering
  • Memory Management: Efficient handling of drop collections
  • JavaScript Bridge: Seamless integration with web interface

๐Ÿ”ฎ Future Enhancements

Phase 1: Enhanced Visuals

  • Particle Systems: Add floating particles for atmosphere
  • Advanced Shaders: Custom GLSL shaders for more realistic effects
  • Animation Curves: Smooth transitions and easing
  • Multiple Brush Types: Different drop styles and sizes

Phase 2: Fluid Simulation Integration ๐ŸŒŠ

The next major evolution will incorporate realistic fluid dynamics:

Computational Fluid Dynamics (CFD)

class FluidSimulator {
    // Navier-Stokes equations for fluid motion
    void updateVelocityField(float dt);
    void advectColor(float dt);
    void applyViscosity(float dt);
    void projectDivergenceFree();
    
    // Surface tension effects
    void calculateSurfaceTension();
    void applyCapillaryWaves();
};

Planned Fluid Features

  • ๐ŸŒŠ Realistic Flow: Implement Navier-Stokes equations for authentic fluid motion
  • ๐Ÿ’ง Surface Tension: Accurate droplet behavior and coalescence
  • ๐ŸŒ€ Vorticity: Swirling patterns and turbulence
  • โš—๏ธ Viscosity: Different ink viscosity properties
  • ๐ŸŽฏ Advection: Color transport through fluid medium
  • ๐Ÿ“ Grid-based Solver: High-performance fluid grid simulation
  • ๐Ÿ”ฌ Multi-phase Flow: Oil-water interactions
  • ๐Ÿ“Š Real-time Visualization: Velocity field visualization

Technical Implementation

  • Eulerian Grid: Uniform grid for velocity and pressure fields
  • FLIP/PIC Hybrid: Particle-in-Cell method for detail preservation
  • GPU Acceleration: Compute shaders for parallel processing
  • Adaptive Time Steps: Stable simulation with variable timesteps

Phase 3: Advanced Features

  • 3D Marbling: Three-dimensional fluid simulation
  • VR/AR Support: Immersive marbling experiences
  • AI Pattern Generation: Machine learning for pattern suggestions
  • Collaborative Mode: Multi-user real-time marbling
  • Physical Simulation: Paper absorption and texture effects

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow C++17 standards
  • Maintain consistent code style
  • Add comments for complex algorithms
  • Test on multiple browsers
  • Update documentation

๐Ÿ› Known Issues

  • Screenshot may not work on some older browsers
  • Mobile touch performance could be optimized
  • Clear canvas function needs C++ implementation
  • Memory usage grows with many drops (need cleanup)

๐Ÿ“š References

Academic Papers

  • "Fluid Simulation for Computer Graphics" - Robert Bridson
  • "Real-time Fluid Dynamics for Games" - Jos Stam (GDC 2003)
  • "Particle-based Viscoelastic Fluid Simulation" - Clavet et al.

Traditional Art

  • Suminagashi History: Wikipedia
  • Turkish Ebru Techniques: Traditional marbling methods
  • Modern Paper Marbling: Contemporary artistic approaches

Technical Resources

๐Ÿ‘จโ€๐Ÿ’ป Author

Sandeep Saurav

  • GitHub: @Sandeep-003
  • Portfolio: [Your Portfolio Link]
  • Email: [Your Email]

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Raylib Community for the amazing graphics library
  • Emscripten Team for WebAssembly compilation
  • Traditional Suminagashi Artists for the inspiration
  • Open Source Community for tools and libraries

โญ Star this repository if you found it interesting! โญ

Made with โค๏ธ and lots of โ˜• by Sandeep

About

Interactive Suminagashi Fluid Simulation using C++ and Raylib. Create mesmerizing marbled patterns inspired by traditional Japanese ink art. Features real-time drop deformation, adaptive edge noise, and dynamic vertex resolution for smooth, fluid visuals. Runs natively and in the browser via Emscripten.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages