| // Copyright 2020 Google LLC. |
| // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| #include "tools/fiddle/examples.h" |
| REG_FIDDLE_ANIMATED(l_system_plant, 256, 256, false, 0, 3) { |
| // https://en.wikipedia.org/wiki/L-system#Example_7:_Fractal_plant |
| {'X', "F-[[X]+X]+F[+FX]-X"}, |
| std::string E(std::string s) { |
| for (int i=0; i<6; i++) { |
| if (rules[i].c == s[0]) { |
| return rules[i].s + E(s.substr(1)); |
| void draw(SkCanvas* canvas) { |
| canvas->drawColor(SK_ColorLTGRAY); |
| p.setStyle(SkPaint::kStroke_Style); |
| std::vector<struct Pt> ptstack; |
| std::string plant = E(E(E(E(E("X"))))); |
| struct Pt pt = {128, 256, 3.14}; |
| for (std::string::iterator it=plant.begin(); it!=plant.end(); ++it) { |
| pt.a += (0.15 + sin(frame*2.0*3.14159)*0.05); |
| pt.a += (-0.15 + sin(frame*2.0*3.14159)*0.05); |
| canvas->drawPath(path, p); |