-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathexample3.c
39 lines (30 loc) · 864 Bytes
/
example3.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
#include "pbPlots.h"
#include "supportLib.h"
#define points 50
int main(){
_Bool success;
StringReference *errorMessage;
double x [points];
double y [points];
StartArenaAllocator();
for(int i = 0; i < points; i++){
x[i] = i/10.0 - 2.5;
y[i] = sin(x[i]);
}
RGBABitmapImageReference *imageRef = CreateRGBABitmapImageReference();
errorMessage = (StringReference *)malloc(sizeof(StringReference));
success = DrawScatterPlot(imageRef, 800, 600, x, points, y, points, errorMessage);
if(success){
ByteArray *pngdata = ConvertToPNG(imageRef->image);
DeleteImage(imageRef->image);
WriteToFile(pngdata, "example3.png");
}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;
}