Skip to content

Commit 93e6003

Browse files
Added C and C++ examples
1 parent da2abf4 commit 93e6003

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

C/example4.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "pbPlots.h"
2+
#include "supportLib.h"
3+
4+
int main(){
5+
RGBABitmapImageReference *imageReference = CreateRGBABitmapImageReference();
6+
7+
double xs [] = {20.1, 7.1, 16.1, 14.9, 16.7, 8.8, 9.7, 10.3, 22, 16.2, 12.1, 10.3, 14.5, 12.4, 9.6, 12.2, 10.8, 14.7, 19.7, 11.2, 10.1, 11, 12.2, 9.2, 23.5, 9.4, 15.3, 9.6, 11.1, 5.3, 7.8, 25.3, 16.5, 12.6, 12, 11.5, 17.1, 11.2, 12.2, 10.6, 19.9, 14.5, 15.5, 17.4, 8.4, 10.3, 10.2, 12.5, 16.7, 8.5, 12.2};
8+
double ys [] = {31.5, 18.9, 35, 31.6, 22.6, 26.2, 14.1, 24.7, 44.8, 23.2, 31.4, 17.7, 18.4, 23.4, 22.6, 16.4, 21.4, 26.5, 31.7, 11.9, 20, 12.5, 18, 14.2, 37.6, 22.2, 17.8, 18.3, 28, 8.1, 14.7, 37.8, 15.7, 28.6, 11.7, 20.1, 30.1, 18.2, 17.2, 19.6, 29.2, 17.3, 28.2, 38.2, 17.8, 10.4, 19, 16.8, 21.5, 15.9, 17.7};
9+
10+
double xs2 [] = {5, 25};
11+
double ys2 [] = {12, 39};
12+
13+
ScatterPlotSeries *series = GetDefaultScatterPlotSeriesSettings();
14+
series->xs = xs;
15+
series->xsLength = sizeof(xs)/sizeof(double);
16+
series->ys = ys;
17+
series->ysLength = sizeof(ys)/sizeof(double);
18+
series->linearInterpolation = false;
19+
series->pointType = L"dots";
20+
series->pointTypeLength = wcslen(series->pointType);
21+
series->color = CreateRGBColor(1, 0, 0);
22+
23+
ScatterPlotSeries *series2 = GetDefaultScatterPlotSeriesSettings();
24+
series2->xs = xs2;
25+
series2->xsLength = sizeof(xs2)/sizeof(double);
26+
series2->ys = ys2;
27+
series2->ysLength = sizeof(ys2)/sizeof(double);
28+
series2->linearInterpolation = true;
29+
series2->lineType = L"solid";
30+
series2->lineTypeLength = wcslen(series->lineType);
31+
series2->lineThickness = 2;
32+
series2->color = CreateRGBColor(0, 0, 1);
33+
34+
ScatterPlotSettings *settings = GetDefaultScatterPlotSettings();
35+
settings->width = 600;
36+
settings->height = 400;
37+
settings->autoBoundaries = true;
38+
settings->autoPadding = true;
39+
settings->title = L"";
40+
settings->titleLength = wcslen(settings->title);
41+
settings->xLabel = L"";
42+
settings->xLabelLength = wcslen(settings->xLabel);
43+
settings->yLabel = L"";
44+
settings->yLabelLength = wcslen(settings->yLabel);
45+
ScatterPlotSeries *s [] = {series, series2};
46+
settings->scatterPlotSeries = s;
47+
settings->scatterPlotSeriesLength = 2;
48+
49+
DrawScatterPlotFromSettings(imageReference, settings);
50+
51+
size_t length;
52+
double *pngdata = ConvertToPNG(&length, imageReference->image);
53+
WriteToFile(pngdata, length, "example4.png");
54+
DeleteImage(imageReference->image);
55+
56+
return 0;
57+
}

C/make.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ gcc -c supportLib.c -std=c99 -O3 -march=native
33
gcc -c example1.c -std=c99 -O3 -march=native
44
gcc -c example2.c -std=c99 -O3 -march=native
55
gcc -c example3.c -std=c99 -O3 -march=native
6+
gcc -c example4.c -std=c99 -O3 -march=native
67
gcc example1.o pbPlots.o supportLib.o -lm -o example1
78
gcc example2.o pbPlots.o supportLib.o -lm -o example2
89
gcc example3.o pbPlots.o supportLib.o -lm -o example3
10+
gcc example4.o pbPlots.o supportLib.o -lm -o example4
911
strip example1
1012
strip example2
1113
strip example3
14+
strip example4
15+
./example1
16+
./example2
17+
./example3
18+
./example4
19+

Cpp/example3.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "pbPlots.hpp"
2+
#include "supportLib.hpp"
3+
4+
int main(){
5+
RGBABitmapImageReference *imageReference = CreateRGBABitmapImageReference();
6+
7+
double xsa[] = {20.1, 7.1, 16.1, 14.9, 16.7, 8.8, 9.7, 10.3, 22, 16.2, 12.1, 10.3, 14.5, 12.4, 9.6, 12.2, 10.8, 14.7, 19.7, 11.2, 10.1, 11, 12.2, 9.2, 23.5, 9.4, 15.3, 9.6, 11.1, 5.3, 7.8, 25.3, 16.5, 12.6, 12, 11.5, 17.1, 11.2, 12.2, 10.6, 19.9, 14.5, 15.5, 17.4, 8.4, 10.3, 10.2, 12.5, 16.7, 8.5, 12.2};
8+
vector<double> xs(xsa, xsa+sizeof(xsa)/sizeof(double));
9+
double ysa[] = {31.5, 18.9, 35, 31.6, 22.6, 26.2, 14.1, 24.7, 44.8, 23.2, 31.4, 17.7, 18.4, 23.4, 22.6, 16.4, 21.4, 26.5, 31.7, 11.9, 20, 12.5, 18, 14.2, 37.6, 22.2, 17.8, 18.3, 28, 8.1, 14.7, 37.8, 15.7, 28.6, 11.7, 20.1, 30.1, 18.2, 17.2, 19.6, 29.2, 17.3, 28.2, 38.2, 17.8, 10.4, 19, 16.8, 21.5, 15.9, 17.7};
10+
vector<double> ys(ysa, ysa+sizeof(ysa)/sizeof(double));
11+
12+
double xsb[] = {5, 25};
13+
vector<double> xs2(xsb, xsb+sizeof(xsb)/sizeof(double));
14+
double ysb[] = {12, 39};
15+
vector<double> ys2(ysb, ysb+sizeof(ysb)/sizeof(double));
16+
17+
ScatterPlotSeries *series = GetDefaultScatterPlotSeriesSettings();
18+
series->xs = &xs;
19+
series->ys = &ys;
20+
series->linearInterpolation = false;
21+
series->pointType = toVector(L"dots");
22+
series->color = CreateRGBColor(1, 0, 0);
23+
24+
ScatterPlotSeries *series2 = GetDefaultScatterPlotSeriesSettings();
25+
series2->xs = &xs2;
26+
series2->ys = &ys2;
27+
series2->linearInterpolation = true;
28+
series2->lineType = toVector(L"solid");
29+
series2->lineThickness = 2;
30+
series2->color = CreateRGBColor(0, 0, 1);
31+
32+
ScatterPlotSettings *settings = GetDefaultScatterPlotSettings();
33+
settings->width = 600;
34+
settings->height = 400;
35+
settings->autoBoundaries = true;
36+
settings->autoPadding = true;
37+
settings->title = toVector(L"");
38+
settings->xLabel = toVector(L"");
39+
settings->yLabel = toVector(L"");
40+
settings->scatterPlotSeries->push_back(series);
41+
settings->scatterPlotSeries->push_back(series2);
42+
43+
DrawScatterPlotFromSettings(imageReference, settings);
44+
45+
vector<double> *pngdata = ConvertToPNG(imageReference->image);
46+
WriteToFile(pngdata, "example3.png");
47+
DeleteImage(imageReference->image);
48+
49+
return 0;
50+
}

0 commit comments

Comments
 (0)