Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ct_koch_line(
- ct::plot2d& plot,
- unsigned int irecur_n,
- unsigned int irecur_max,
- ct_complex a,
- ct_complex b,
- ct_float ratio
- ) {
- if (irecur_n >= irecur_max) return;
- ct_complex dif = b - a;
- ct_complex mid = a + dif * .5;
- ct_complex k0 = a + dif * ratio;
- ct_complex k1 = {
- mid.real() - dif.imag() * ratio * .3,
- mid.imag() + dif.real() * ratio * .3
- };
- ct_complex k2 = a + dif * ratio * 2.;
- ct_float alpha = 1.0;
- plot.line(a, k0, CT_RGBAF(1, 1, 0, alpha));
- plot.line(k0, k1, CT_RGBAF(1, 0, 1, alpha));
- plot.line(k1, k2, CT_RGBAF(1, 0, 1, alpha));
- plot.line(k2, b, CT_RGBAF(1, 1, 0, alpha));
- ct_koch_line(plot, irecur_n + 1, irecur_max, a, k0, ratio);
- ct_koch_line(plot, irecur_n + 1, irecur_max, k0, k1, ratio);
- ct_koch_line(plot, irecur_n + 1, irecur_max, k1, k2, ratio);
- ct_koch_line(plot, irecur_n + 1, irecur_max, k2, b, ratio);
- }
- void ct_tessy_test(
- ct::plot2d& plot,
- unsigned int irecur_n,
- unsigned int irecur_max,
- ct_complex a,
- ct_complex b,
- ct_complex c,
- ct_float ratio
- ) {
- if (irecur_n >= irecur_max) return;
- ct_complex mid = c + (b - c) * .5;
- ct_complex gcenter = a + (mid - a) * ratio;
- ct_koch_line(plot, 0, 4, a, gcenter, 1. / 3);
- ct_koch_line(plot, 0, 4, c, gcenter, 1. / 3);
- ct_koch_line(plot, 0, 4, b, gcenter, 1. / 3);
- ct_koch_line(plot, 0, 4, gcenter, a, 1. / 3);
- ct_koch_line(plot, 0, 4, gcenter, c, 1. / 3);
- ct_koch_line(plot, 0, 4, gcenter, b, 1. / 3);
- ct_float nratio = abs(ratio * 1.0);
- ct_tessy_test(plot, irecur_n + 1, irecur_max, a, b, gcenter, nratio);
- ct_tessy_test(plot, irecur_n + 1, irecur_max, b, c, gcenter, nratio);
- ct_tessy_test(plot, irecur_n + 1, irecur_max, c, a, gcenter, nratio);
- }
Advertisement
Add Comment
Please, Sign In to add comment