-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathexample2.c
58 lines (49 loc) · 1.64 KB
/
example2.c
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
#include "pbPlots.h"
#include "supportLib.h"
int main(){
_Bool success;
StringReference *errorMessage;
double xs [] = {-2, -1, 0, 1, 2};
double ys [] = {2, -1, -2, -1, 2};
StartArenaAllocator();
ScatterPlotSeries *series = GetDefaultScatterPlotSeriesSettings();
series->xs = xs;
series->xsLength = 5;
series->ys = ys;
series->ysLength = 5;
series->linearInterpolation = true;
series->lineType = L"dashed";
series->lineTypeLength = wcslen(series->lineType);
series->lineThickness = 2;
series->color = GetGray(0.3);
ScatterPlotSettings *settings = GetDefaultScatterPlotSettings();
settings->width = 600;
settings->height = 400;
settings->autoBoundaries = true;
settings->autoPadding = true;
settings->title = L"x^2 - 2";
settings->titleLength = wcslen(settings->title);
settings->xLabel = L"X axis";
settings->xLabelLength = wcslen(settings->xLabel);
settings->yLabel = L"Y axis";
settings->yLabelLength = wcslen(settings->yLabel);
ScatterPlotSeries *s [] = {series};
settings->scatterPlotSeries = s;
settings->scatterPlotSeriesLength = 1;
RGBABitmapImageReference *canvasReference = CreateRGBABitmapImageReference();
errorMessage = (StringReference *)malloc(sizeof(StringReference));
success = DrawScatterPlotFromSettings(canvasReference, settings, errorMessage);
if(success){
ByteArray *pngdata = ConvertToPNG(canvasReference->image);
WriteToFile(pngdata, "example2.png");
DeleteImage(canvasReference->image);
}else{
fprintf(stderr, "Error: ");
for(int i = 0; i < errorMessage->stringLength; i++){
fprintf(stderr, "%c", errorMessage->string[i]);
}
fprintf(stderr, "\n");
}
FreeAllocations();
return success ? 0 : 1;
}