Coder Social home page Coder Social logo

spl's Introduction

GitHub license

spl - A Simple Plotting Drawing Library for C++

The library is under heavy development, some parts are broken, others may not work from time to time. If you find yourself having issues with it, feel free to report it.

About

spl aims to be a simple library to draw stuff and edit images in C++. It is developed with the following ideas in mind:

  • Ease of use: the library must be easy to install and easy to use. We're achieving the former using the conan package manager for the dependencies and cmake as build system, and the latter by taking inspiration from matplotlib, since we recognize in it the simplicity wewant our library to transmit while using it
  • Being as up-to-date with the standard as possible: C++ is evolving, and there's no reason for us to avoid all the goodies that C++11, 14, 17 and 20 have brought us. Also, that's a good exercise to learn all the new stuff that comes out from every new standard
  • Being as standard as possible (minimal external dependencies): we want spl to be as standalone as possible. As for now, we have the following dependencies:
    • fmtlib in the absence of the C++20 formatting library
    • stb for saving and loading various image types

Example

#include <ranges>
#include <numbers>
#include <iostream>

#include "spl/graphics/image.hpp"
#include "spl/graphics/primitive.hpp"

namespace color = spl::graphics::color;

int main()
{
    // Creates a new image
    auto image = spl::graphics::image(900, 600);

    // Support for rows, columns, pixels, and for row-by-row, column-by-column, pixel-by-pixel iteration
    std::ranges::fill(image.row(449), spl::graphics::rgba{255, 0, 255, 255});
    std::ranges::fill(image.column(130), color::violet);

    // Supports some drawing primitives, like lines and rectangles
    auto line = spl::graphics::line{{0, 0}, {300, 599}, color::cyan};
    image.draw(line);
    image.draw(spl::graphics::line{{100, 100}, {50, 550}, color::orange});

    auto rect = spl::graphics::rectangle{{150, 150}, 90, 30};
    rect.fill_color(color::green);
        auto rotated_rect = spl::graphics::rectangle{{20, 30}, {100, 40}, std::numbers::pi / 4, /*antialiasing=*/true}
                      .fill_color(color::red);
    image.draw(rect)
         .draw(rotated_rect);

	// Save a new image
    if (not image.save_to_file("image.png")) {
        std::cerr << "Error\n";
        return 1;
    }

    // Load an existing image
    auto status = image.load_from_file("image.png");
    if (status != spl::graphics::load_status::success) {
        std::cerr << "Error while loading a.png";
        return 2;
    }
}

spl's People

Contributors

momokrono avatar rbrugo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spl's Issues

image_range is not a range

The following code does not compile:

auto img = spl::graphics::image{...};
std::ranges::for_each(img.rows(), [](auto){}); // fails
std::for_each(img.rows().begin(), img.rows.end(), [](auto){}); // fails - no operator *
for (auto && row : img.rows()) { } // fails - no operator *

Rename the project

This is no longer a "Simple Plotting Library": it aims to be a simple, (more or less) general-purpose drawing library. Maybe it should be renamed in a more coherent manner (Simple Graphics Library, Simple Painting Library, ...) or in an original way for the 1.0.0 release

Update the readme

The readme must be updated, it currently describes an API which does not exist in the current branch

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.