bezierRgba function
Implementation
bool bezierRgba(Pointer<SdlRenderer> renderer, Pointer<Int16> vx,
Pointer<Int16> vy, int n, int s, int r, int g, int b, int a) {
bool result = true;
int i;
double t, stepsize;
List<double> x = [];
List<double> y = [];
int x1, y1, x2, y2;
/*
* Sanity check
*/
if (n < 3) {
return false;
}
if (s < 2) {
return false;
}
/*
* Variable setup
*/
stepsize = 1.0 / s;
/* Transfer vertices into float arrays */
for (i = 0; i < n; i++) {
x.add(vx[i].toDouble());
y.add(vy[i].toDouble());
}
x.add(vx[0].toDouble());
y.add(vy[0].toDouble());
/*
* Set color
*/
result = true;
if (result) {
result = sdlSetRenderDrawBlendMode(
renderer, (a == 255) ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
}
if (result) {
result = sdlSetRenderDrawColor(renderer, r, g, b, a);
}
/*
* Draw
*/
t = 0.0;
x1 = _evaluateBezier(x, n + 1, t).toInt();
y1 = _evaluateBezier(y, n + 1, t).toInt();
for (i = 0; i <= (n * s); i++) {
t += stepsize;
x2 = _evaluateBezier(x, n, t).toInt();
y2 = _evaluateBezier(y, n, t).toInt();
if (result) {
result = line(
renderer, x1.toDouble(), y1.toDouble(), x2.toDouble(), y2.toDouble());
}
x1 = x2;
y1 = y2;
}
/* Clean up temporary array */
//free(x);
//free(y);
return result;
}