Coder Social home page Coder Social logo

bayramooov / bubble-sync Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 7 KB

bubble-sync: Simple canvas experiment exploring tab synchronization through LocalStorage. Enjoy the synchronized movement of bubbles across tabs. A playful journey into web development skills.

HTML 100.00%
browsersync canvas canvas2d frontend javascript localstorage web

bubble-sync's Introduction

Bubble-sync

Visit the simple canvas experiment exploring tab synchronization through LocalStorage. Enjoy the synchronized movement of bubbles across tabs. A playful journey into web development skills.

Environment Management

  • The project utilizes LocalStorage to save and load the environment state, ensuring data persistence.
  • Screen boundaries and tab information are dynamically tracked and updated during runtime.
  • The canvas is resized to match the current window dimensions, providing a full-screen interactive experience.

Documentation

Bubble Class

The Bubble class is responsible for creating and managing individual bubbles. It includes methods for generating random pleasant colors, handling collisions with screen edges, updating bubble positions, and rendering them on the canvas.

constructor(bubble: Object)

Initializes a new Bubble instance with specified options.

  • Parameters:
    • bubble.x (optional): Initial X-coordinate of the bubble's center.
    • bubble.y (optional): Initial Y-coordinate of the bubble's center.
    • bubble.radius (optional): Initial radius of the bubble.
    • bubble.speedX (optional): Speed along the X-axis (change in X-coordinate per frame).
    • bubble.speedY (optional): Speed along the Y-axis (change in Y-coordinate per frame).
    • bubble.color (optional): Color of the bubble.

static randomColor(): string

Generates a random pleasant color in hsl format.

handleCollisions(screenBounds: Object): void

Handles collisions with screen edges.

  • Parameters:
    • screenBounds: Object containing screen boundaries.

update(env: Object): void

Updates the bubble's position and handles collisions.

  • Parameters:
    • env: Object containing screen boundaries and canvas context.

render(ctx: CanvasRenderingContext2D): void

Renders the bubble on the canvas.

  • Parameters:
    • ctx: The canvas rendering context.

Functions

bubbleFactory(): Bubble

Generates a new Bubble with random speeds and default x, y coordinates.

uniqueString(): string

Generates a unique string combining timestamp and random characters.

canvasFullScreen(canvas: HTMLCanvasElement): void

Resizes the canvas element to match the current window dimensions.

  • Parameters:
    • canvas: The canvas element to resize.

saveEnv(env: Object): void

Saves the environment state to localStorage after converting Bubble objects to plain data.

  • Parameters:
    • env: The environment object containing Bubble objects and screen dimensions.

loadEnv(tabId: string): Object

Loads the environment state from localStorage, initializing defaults if needed.

  • Parameters:
    • tabId: Unique identifier for the current tab.

clearEnv(): void

Clears the environment state from localStorage.

logInfo(env: Object): void

Updates HTML elements with environment data for logging.

  • Parameters:
    • env: The environment data to display.

stopAnimation(): void

Stops the Animation.

animate(): void

Animates the bubbles on the canvas, updating their positions and rendering.

bubble-sync's People

Contributors

bayramooov avatar

Stargazers

Arismário Neves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.