Menu

Home

Sav

Canvas++ is a very simple graphics library contained in single header file. It's purpose is to make teaching of C++ more colorful and funny for kids and students. The main idea is to wrap windows API calls into simple interface. You can start drawing next after "Hello world" example - just declare Window variable and call method draw() to start drawing.

Quick start video: http://youtu.be/AeDaRlMsH5Q

Simple example:

#include "canvas.hpp"
using namespace cnv;
int main()
{
    Window w;
    w.draw(Circle(150, 150, 100), Pen(0, 0, 255));
    system("pause");
}

Animated rose with 5 petals:

#include "canvas.hpp"
#include <cmath>

using namespace cnv;

int main()
{
    Window w;
    w.enable_frame_buffer(); // we want smooth animation
    w.pen(Pen(PS_NULL)); // setting default pen to be invisible

    const double pi = 3.141593;
    const double delta = 0.01;
    const int k = 5;
    const int trace = 25;
    const int x0 = w.width()/2;
    const int y0 = w.height()/2;

    for(double theta = 0; theta <= 16*pi; theta += delta)
    {
        for(int i = trace; i; --i)
        {
            const double t = theta - 2*delta*i; 
            const double r = x0 * sin(k*t)/2;
            const int y = y0 + r*sin(t);
            Brush b1(10*i, 10*i, 255); // blue brush
            Brush b2(10*i, 10*i, 0); // yellow brush
            w.draw(Circle(x0 + r*cos(t), y, (trace-i) / 3), b1);
            w.draw(Circle(x0 - r*cos(t), y, (trace-i) / 3), b2);
        }

        w.paint();
        Sleep(10);
        w.clear();
    }

    system("pause");
}

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.