Skip to content

TVATDCI/rotatingx

Repository files navigation

Rotating Cube with Dynamic Backgrounds

Project Overview

This project is a visually engaging React application featuring a 3D rotating cube floating in dynamic and immersive environments. By clicking a floating button, users can cycle through various atmospheric and natural backgrounds, creating an interactive and visually stimulating experience.

Key Features

  • 3D Rotating Cube: A cube rendered in 3D using CSS transform-style: preserve-3d.
  • Dynamic Backgrounds: 12 unique backgrounds including space, natural scenes, and abstract environments.
  • Floating Action Button: A button that changes the background with a smooth transition.
  • Responsive Design: Works seamlessly across devices.

React Concepts Used

  1. Functional Components: The app is built using functional components (App, RotatingCube, and FloatingButton).
  2. State Management: Background changes are managed using React's useState.
  3. Event Handling: Button click triggers background change logic.
  4. Effect Hook: Used in RotatingCube to handle the cube’s animation lifecycle.
  5. Modularity: Components are well-separated for clarity and reusability.

Project Structure

click and have a look inside

  • I am going bed now.

How to Run

  1. Clone the repository:
    git clone <your-repo-url>
    cd <your-repo-folder>
    npm install
    npm run dev
    npm run build

Key Benefits

Scalability

  • Easily extendable to include new background or interactive elements (e.g.,sound effects, UI components).

Modularity

  • Each component (Cube, Button) is self-contained and reusable.

Reusability

  • The FloatingButton component can be used across multiple projects without modification.

How it works

Prop Passing: The App.jsx component defines the changeAtmosphere function and passes it as a prop to the RotatingCube component.

User Interaction: When the user clicks on the cube (the main element in RotatingCube), the onClick event is triggered.

Function Call: The onClick event handler calls the changeAtmosphere function passed from App.jsx.

Random Atmosphere Selection:

The changeAtmosphere function defines a list of atmosphere names in an array called atmospheres. A random atmosphere is selected using this formula:

atmospheres[Math.floor(Math.random() * atmospheres.length)];

State Update: The selected atmosphere is set as the new state of background using setBackground(randomAtmosphere).

Dynamic Styling: The background state is used as a class name for the root

in the App component (<div className={app ${background}}>), changing the background dynamically to match the selected atmosphere.

This ensures a seamless interaction where clicking the cube triggers the background to change randomly to one of the predefined options.

PropTypes:

  • to ensure the changAtmosphere prop is passed correctly and is of the expected type.

Key Changes

    1. Importing PropTypes: Added import PropTypes from "prop-types";.
    1. Defining PropTypes:
    • The changAtmosphere prop is defined as a required function using.
    • PropTypes.func.isRequired.

Why Use PropTypes?

  • It helps catch bugs by validating props passed to the component.
  • Ensures your code is easier to maintain and debug in the future.

Future Ideas

work in progress!
  • Sound Effects: Add atmospheric sounds corresponding to each - background.
  • Cube Glow: Introduce glowing effects on the cube for added aesthetics.
  • Themes: Let users customize and save their favorite atmosphere combinations.
  • Performance Optimization: Use React.memo or lazy loading for assets to improve performance.

Conclusion

  • This project is a fun way to explore React concepts and CSS - animations while building an interactive 3D application. It can serve as a foundation for further development into a game, visualization tool, or educational app.

This file should work as a comprehensive README.md for your project. You can modify or expand it as you develop your application further!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published