#include "graphics.hpp"
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <vector>
using namespace genv;
using namespace std;

const unsigned int X = 500;
const unsigned int Y = 500;

struct pehely {
    private:
        int x,y;
        int r, g, b;
    public:
        pehely()
        {
            x = rand() % X;
            y = rand() % Y;
            r = 100 + rand() % 155;
            g = 100 + rand() % 155;
            b = 100 + rand() % 155;
        }
        pehely(unsigned int kattX, unsigned int kattY)
        {
            x = kattX + rand() % 20;
            y = kattY + rand() % 20;
            r = 100 + rand() % 155;
            g = 100 + rand() % 155;
            b = 100 + rand() % 155;
        }
        void rajzol()
        {
            gout << move_to(x, y) << color(r,g,b) << box(2, 2);
        }
        void mozog(int Wx, int Wy)
        {
            x += (rand() % 5) -  2 + Wx;
            y += rand() % 3 + Wy;
            x = (x+X)%X;
            y %= Y;
            rajzol();
        }
};

int main()
{
    gout.open(X,Y);
    vector <pehely> ho;
    for (int i = 0; i < 1000; i++) {pehely p; ho.push_back(p);}
    gout << refresh;
    event ev;
    gin.timer(40);
    int Wx = 0; int Wy;
    while (gin >> ev)
    {
        if (ev.type == ev_timer)
        {
            gout << move_to(0, 0) << color (0,0,0) << box(X, Y);
            for (unsigned int i = 0; i < ho.size(); i++)
                ho[i].mozog(Wx, Wy);
            gout << refresh;
        }
        else if (ev.type == ev_mouse && ev.button == 0)
        {
            Wx = (ev.pos_x -250)/20;
            Wy = (ev.pos_y )/70;
        }
        else if (ev.type == ev_mouse && ev.button > 0)
            for (int i = 0; i < 50; i++)
            {
            pehely p(ev.pos_x, ev.pos_y);
            ho.push_back(p);
            }
    }
    return 0;
}

