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
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
cpp-shape-drawer
/
include
RSK World
cpp-shape-drawer
C++ Shape Drawer - Advanced Graphics Application + Raylib + OOP Design + Shape Tools + Transformation + Export + Educational Design
include
  • Circle.hpp2 KB
  • DrawingCanvas.hpp7.3 KB
  • PatternGenerator.hpp1.6 KB
  • Polygon.hpp2.3 KB
  • RectangleShape.hpp2.7 KB
  • Shape.hpp4.2 KB
  • Star.hpp2.8 KB
  • TextShape.hpp2 KB
  • Triangle.hpp2.5 KB
Star.hpp
include/Star.hpp
Raw Download
Find: Go to:
/**
 * @file Star.hpp
 * @brief Star shape implementation.
 * 
 * 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 STAR_HPP
#define STAR_HPP

#include "Shape.hpp"
#include <cmath>
#include <vector>

class Star : public Shape {
private:
    float outerRadius;
    float innerRadius;
    int points;

public:
    Star(Vector2 pos, float outer, float inner, int pts, Color col, bool filled = true)
        : Shape(pos, col, filled), outerRadius(outer), innerRadius(inner), points(pts) {}

    void draw() const override {
        float rotRad = rotation * (PI / 180.0f);
        float step = PI / points;
        Color c1 = getEffectiveColor();
        Color c2 = getEffectiveColor(true);
        Vector2 pos = getEffectivePosition();
        float s = getEffectiveScale();
        
        std::vector<Vector2> vertices;
        for (int i = 0; i < 2 * points; i++) {
            float r = (i % 2 == 0) ? outerRadius : innerRadius;
            r *= s;
            float angle = i * step + rotRad;
            vertices.push_back({
                pos.x + cos(angle) * r,
                pos.y + sin(angle) * r
            });
        }

        if (isFilled) {
            for (int i = 0; i < (int)vertices.size(); i++) {
                DrawTriangle(pos, vertices[i], vertices[(i + 1) % vertices.size()], useGradient ? c2 : c1);
            }
        } else {
            for (int i = 0; i < (int)vertices.size(); i++) {
                DrawLineV(vertices[i], vertices[(i + 1) % vertices.size()], c1);
            }
        }
    }

    bool contains(Vector2 point) const override {
        return CheckCollisionPointCircle(point, position, outerRadius * scale);
    }

    std::string serialize() const override {
        return "STAR," + std::to_string(position.x) + "," + std::to_string(position.y) + "," +
               std::to_string(outerRadius) + "," + std::to_string(innerRadius) + "," + 
               std::to_string(points) + "," + std::to_string(color.r) + "," + std::to_string(color.g) + "," +
               std::to_string(color.b) + "," + std::to_string(alpha) + "," + (isFilled ? "1" : "0") + "," +
               std::to_string(rotation) + "," + std::to_string(scale) + "," + (useGradient ? "1" : "0") + "," +
               std::to_string(secondaryColor.r) + "," + std::to_string(secondaryColor.g) + "," +
               std::to_string(secondaryColor.b) + "," + std::to_string((int)animType);
    }

    std::string getType() const override { return "Star"; }
};

#endif // STAR_HPP
81 lines•2.8 KB
cpp

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