help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
cpp-shape-drawer
RSK World
cpp-shape-drawer
C++ Shape Drawer - Advanced Graphics Application + Raylib + OOP Design + Shape Tools + Transformation + Export + Educational Design
cpp-shape-drawer
  • include
  • src
  • CMakeLists.txt1.2 KB
  • LICENSE1.3 KB
  • README.md2.7 KB
  • RELEASE_NOTES.md3.1 KB
  • demo.html25.8 KB
  • index.html32.1 KB
  • release_note.html4.8 KB
Shape.hppPatternGenerator.hpp
include/Shape.hpp
Raw Download
Find: Go to:
/**
 * @file Shape.hpp
 * @brief Base abstract class for all shapes in the drawer application.
 * 
 * Part of the C++ Shape Drawer Project.
 * 
 * @author Molla Samser (Founder of RSK World)
 * @designer Rima Khatun
 * @website https://rskworld.in
 * @email hello@rskworld.in
 * @phone +91 93305 39277
 * @location Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 * @year 2026
 */

#ifndef SHAPE_HPP
#define SHAPE_HPP

#include <raylib.h>
#include <string>

/**
 * @class Shape
 * @brief Abstract base class representing a geometric shape.
 */
enum AnimationType { NONE = 0, PULSE, BOUNCE, SHAKE };

class Shape {
protected:
    Vector2 position;
    Color color;
    bool isFilled;
    float borderThickness;
    float rotation; // In degrees
    float scale;
    float alpha;    // 0.0 to 1.0

    // Masterpiece Features
    bool useGradient;
    Color secondaryColor;
    AnimationType animType;
    float animTime;

public:
    Shape(Vector2 pos, Color col, bool filled = true, float thickness = 2.0f)
        : position(pos), color(col), isFilled(filled), borderThickness(thickness), 
          rotation(0.0f), scale(1.0f), alpha(col.a / 255.0f),
          useGradient(false), secondaryColor(col), animType(NONE), animTime(0.0f) {}

    virtual ~Shape() {}

    // Pure virtual function to be implemented by derived classes
    virtual void draw() const = 0;

    // Hit testing for selection
    virtual bool contains(Vector2 point) const = 0;

    // Serialization
    virtual std::string serialize() const = 0;

    // Update for animations
    virtual void update(float deltaTime) {
        if (animType != NONE) {
            animTime += deltaTime;
        }
    }

    // Masterpiece Getters/Setters
    void setGradient(bool active, Color second = WHITE) { useGradient = active; secondaryColor = second; }
    bool getGradient() const { return useGradient; }
    Color getSecondaryColor() const { return secondaryColor; }

    void setAnimation(AnimationType type) { animType = type; animTime = 0.0f; }
    AnimationType getAnimation() const { return animType; }

    // Unified color getter including alpha and animations
    Color getEffectiveColor(bool secondary = false) const {
        Color base = secondary ? secondaryColor : color;
        float finalAlpha = alpha;
        
        // Pulse animation affect alpha/scale but draw() needs to handle scale
        if (animType == PULSE) {
            finalAlpha *= (0.5f + 0.5f * sinf(animTime * 5.0f));
        }
        
        base.a = (unsigned char)(finalAlpha * 255);
        return base;
    }

    float getEffectiveScale() const {
        if (animType == PULSE) return scale * (1.0f + 0.1f * sinf(animTime * 5.0f));
        return scale;
    }

    Vector2 getEffectivePosition() const {
        Vector2 pos = position;
        if (animType == BOUNCE) pos.y -= fabsf(sinf(animTime * 10.0f)) * 50.0f * scale;
        if (animType == SHAKE) {
            pos.x += (float)GetRandomValue(-5, 5) * scale;
            pos.y += (float)GetRandomValue(-5, 5) * scale;
        }
        return pos;
    }

    // Movement
    virtual void move(Vector2 delta) {
        position.x += delta.x;
        position.y += delta.y;
    }

    // Common getters and setters
    virtual void setPosition(Vector2 pos) { position = pos; }
    virtual Vector2 getPosition() const { return position; }

    virtual void setColor(Color col) { color = col; alpha = col.a / 255.0f; }
    virtual Color getColor() const { 
        Color c = color;
        c.a = (unsigned char)(alpha * 255);
        return c;
    }

    virtual void setFilled(bool filled) { isFilled = filled; }
    virtual bool getFilled() const { return isFilled; }

    virtual void setRotation(float rot) { rotation = rot; }
    virtual float getRotation() const { return rotation; }
    virtual void rotate(float angle) { rotation += angle; }

    virtual void setScale(float s) { scale = s; }
    virtual float getScale() const { return scale; }

    virtual void setAlpha(float a) { alpha = a; if (alpha < 0) alpha = 0; if (alpha > 1) alpha = 1; }
    virtual float getAlpha() const { return alpha; }

    virtual std::string getType() const = 0;
};

#endif // SHAPE_HPP
139 lines•4.2 KB
cpp
include/PatternGenerator.hpp
Raw Download
Find: Go to:
/**
 * @file PatternGenerator.hpp
 * @brief Utility to generate complex shape patterns.
 * 
 * Part of the C++ Shape Drawer Project.
 * 
 * @author Molla Samser (Founder of RSK World)
 * @designer Rima Khatun
 * @website https://rskworld.in
 * @email hello@rskworld.in
 * @phone +91 93305 39277
 * @location Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 * @year 2026
 */

#ifndef PATTERN_GENERATOR_HPP
#define PATTERN_GENERATOR_HPP

#include "DrawingCanvas.hpp"
#include "Circle.hpp"
#include "RectangleShape.hpp"
#include <cmath>

class PatternGenerator {
public:
    static void generateGrid(DrawingCanvas& canvas, int rows, int cols, float spacing) {
        for (int i = 0; i < rows; ++i) {
            for (int j = 0; j < cols; ++j) {
                Vector2 pos = { 50.0f + j * spacing, 50.0f + i * spacing };
                Color col = { (unsigned char)(j * 20), (unsigned char)(i * 20), 150, 255 };
                canvas.addShape(std::make_unique<Circle>(pos, spacing / 2.5f, col, true));
            }
        }
    }

    static void generateSpiral(DrawingCanvas& canvas, Vector2 center, int count) {
        for (int i = 0; i < count; ++i) {
            float angle = i * 0.2f;
            float radius = i * 2.0f;
            Vector2 pos = { center.x + cos(angle) * radius, center.y + sin(angle) * radius };
            Color col = ColorFromHSV(angle * 57.29f, 0.8f, 0.9f);
            canvas.addShape(std::make_unique<Circle>(pos, 5.0f + i * 0.1f, col, true));
        }
    }
};

#endif // PATTERN_GENERATOR_HPP
48 lines•1.6 KB
cpp
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer