Skip to content

Instantly share code, notes, and snippets.

@dneprDroid
Created October 1, 2025 12:53
Show Gist options
  • Select an option

  • Save dneprDroid/d3ac7e2dcccc38b6e89a01aeeb29fce0 to your computer and use it in GitHub Desktop.

Select an option

Save dneprDroid/d3ac7e2dcccc38b6e89a01aeeb29fce0 to your computer and use it in GitHub Desktop.
SkPath star() {
SkPath starPath;
float cx = 100, cy = 100;
float outerRadius = 80;
float innerRadius = 35;
int numPoints = 5;
for (int i = 0; i <= numPoints * 2; ++i) {
float angle = i * SK_ScalarPI / numPoints - SK_ScalarPI / 2;
float radius = (i % 2 == 0) ? outerRadius : innerRadius;
float x = cx + cosf(angle) * radius;
float y = cy + sinf(angle) * radius;
if (i == 0)
starPath.moveTo(x, y);
else
starPath.lineTo(x, y);
}
starPath.close();
return starPath;
}
void draw(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorRED);
SkPaint borderPaint;
borderPaint.setAntiAlias(true);
borderPaint.setStyle(SkPaint::kStroke_Style);
borderPaint.setStrokeWidth(4.0f);
SkPath circle;
circle.addCircle(20, 30, 150);
circle.setFillType(SkPathFillType::kInverseWinding);
canvas->save();
canvas->clipPath(circle, SkClipOp::kDifference, false);
canvas->drawPath(star(), paint);
circle.setFillType(SkPathFillType::kWinding);
canvas->drawPath(circle, borderPaint);
canvas->restore();
canvas->translate(100, 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment