summaryrefslogtreecommitdiff
path: root/Canvas/cpu/CalculateCanvas.cpp
blob: 75a99965ed3aa1a1d1a9a8d2b89bf99123d84a7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Created by saintruler on 05.05.19.
//
#include "CalculateCanvas.h"

void calculate(unsigned char* canvas, int width, Point* points, int nPoints, int canvasX, int canvasY)
{
    int pathX, pathY;
    int length_squared;
    double f = 0;

    for (int i = 0; i < nPoints; i++)
    {
        pathX = points[i].x - canvasX;
        pathY = points[i].y - canvasY;

        length_squared = pathX * pathX + pathY * pathY;
        f += (1e5 * 20) / (float) length_squared;
    }

    int l = (int) f;
    if (l > 255) l = 255;

    canvas[canvasY * width * 3 + canvasX * 3 + 0] = l;
    canvas[canvasY * width * 3 + canvasX * 3 + 1] = 0;
    canvas[canvasY * width * 3 + canvasX * 3 + 2] = 0;
}

//void calculate(unsigned char* canvas, int width, Point* points, int nPoints, int canvasX, int canvasY)
//    point canvas_pt(canvasX, canvasY);
//    double f = 0;
//    for (point pt : points)
//    {
//        point path = pt - canvas_pt;
//
//        f += (1e5 * 20 * 1) / path.length_sqared();
//    }
//
//    int l = (int) f;
//    if (l > 255) l = 255;
//
//
//    canvas[y * SCR_WIDTH * 3 + x * 3 + 0] = l;
//    canvas[y * SCR_WIDTH * 3 + x * 3 + 1] = 0;
//    canvas[y * SCR_WIDTH * 3 + x * 3 + 2] = 0;
//}



void generate_canvas(int width, int height, unsigned char* canvas, Point* points, int nPoints)
{
    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < height; y++)
        {
            calculate(canvas, width, points, nPoints, x, y);
        }
    }
}