4 {
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19const char* input = "uf100+91dr180|f3+2|+89uf60+90r2$f20-90dr60|f1+6|u-90f20$-90f50-90f30d+180f60uf1000";
20
21struct Turtle {
float x;
float y;
float h;
bool p; } t;
22
26 paint.setAntiAlias(
true);
28 paint.setStrokeWidth(0);
30}
31
32const char* eval(
SkCanvas* canvas,
const char*
s,
char e,
float& dist,
float& l,
bool pt) {
35 case 'u': t.p = false; break;
36 case 'd': t.p = true; break;
37 case '+': t.h += atoi(
s);
break;
38 case '-': t.h -= atoi(
s);
break;
39 case 'f': {
43 float r = t.h * 0.01745329f;
44 Turtle nt = { t.x + sinf(r) *
d, t.y - cosf(r) *
d, t.h, t.p };
45 if (pt && t.p) canvas->
drawLine(t.x, t.y, nt.x, nt.y,
p());
46 t = nt;
47 break;
48 }
49 case 'r': {
51 while (*
s >=
'0' && *
s <=
'9') { ++
s; }
53 for (
int i = 0;
i < c; ++
i) { n = eval(canvas,
s+1, *
s, dist, l, pt); }
55 }
56 }
57 }
59}
60
63
64 t = { 128, 128, 0, true };
65 float totalDist = 0;
66 float l = 1E9f;
67 eval(canvas, input, 0, totalDist, l, false);
68
69 l =
frame * totalDist;
70 t = { 128, 128, 0, true };
71 eval(canvas, input, 0, totalDist, l, true);
72}
73}
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorWHITE
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
void clear(SkColor color)
@ kStroke_Style
set to stroke geometry
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
static float min(float r, float g, float b)