Skip to content

Sam-Belliveau/SPGL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 

Repository files navigation

SPGL

To Install, Drag The "SPGL" Folder Into The Root Of Your Project.

Compile Options -lSDL2 and -std=c++17 if you need to

Simple Pixel Graphics Library is a library made for drawing pixel images.

It makes this really simple. Here is an example of a Mandelbrot Renderer made with this library.

#include <iostream>
#include <complex>

#include "SPGL/SPGL.hpp"

int main()
{
    // Define Width and Height
    SPGL::Size width = 640;
    SPGL::Size height = 480;

    // Make Window and Image Buffer
    SPGL::Window<> win(width, height, "Mandelbrot Set");
    SPGL::Image img(width, height);
    
    for(SPGL::Size y = 0; y < height; ++y)
        for(SPGL::Size x = 0; x < width; ++x)
        {
            // Mandelbrot Algorithm
            const std::complex<double> C((x - width*0.75) / (width/4.0),
                                            (y - height*0.5) / (height/3.0));
            std::complex<double> Z(C);
            SPGL::UInt8 iter = 0;

            while(++iter < 255 && Z.real()*Z.real() + Z.imag()*Z.imag() < 4)
              Z = Z*Z + C;

            // Use built in HSV to RGB conversion to get colors
            if(iter != 255) img(x, y) = SPGL::Color::HSV(iter);
        }
    
    // While the window is open, render the image and check for events.
    while(win.isRunning()) 
    {
        win.renderImage(img); 
        win.update(); 
    }
}

About

Simple Pixel Graphics Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages