Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #include "ct_g2d.hpp"
- // plot a semicircle wave
- struct ct_ap_circle
- {
- // the functions input
- struct input
- {
- ct::plot2d& plot; // the plotter
- ct_complex origin; // origin point
- unsigned int imax; // the number of point per circle
- };
- struct output
- {
- unsigned int ret; // not used
- };
- static output result_for(
- input const& in,
- unsigned int irecur,
- unsigned int irecur_max
- ) {
- output out = { 0 };
- if (irecur >= irecur_max) return out;
- ct_float angle_start = 1 / (in.imax - 1.0) * CT_PI2;
- ct_complex pt = {
- 1, 0
- };
- ct_complex ptx = {
- (std::cos(angle_start) +
- std::floor(std::sin(angle_start)) * 2 + 1) * .5,
- std::sin(angle_start) * .5
- };
- ct_complex dif = ptx - pt;
- ct_float dis = std::abs(dif) * .5;
- for (unsigned int i = 1; i < in.imax; ++i)
- {
- ct_float ir = i / (in.imax - 1.0);
- ct_float angle = CT_PI2 * ir;
- ct_complex np = {
- (std::cos(angle) + std::floor(std::sin(angle)) * 2 + 1) * .5,
- std::sin(angle) * .5
- };
- np = np + in.origin;
- ct_float ddd = std::abs(np - pt) * .5;
- if (ddd <= dis && i > 1)
- {
- in.plot.line(pt, np, CT_RGBF(0, 1, 1));
- }
- ct_ap_circle::input cap_irn = {
- in.plot,
- np,
- in.imax
- };
- result_for(cap_irn, irecur + 1, irecur_max);
- pt = np;
- }
- return out;
- }
- };
- int main()
- {
- {
- ct_complex viewp_center = { 0, 0 };
- ct_float viewp_radius = 1.17;// .965;
- ct_float aratio = 1080.0 / 1920.0;
- ct_float width = 1920 * 1;
- ct::axes2d viewp_axes(viewp_center, viewp_radius);
- ct::plot2d viewp_plot(viewp_axes, width, width * aratio, true);
- viewp_plot.clear(CT_RGBF(0, 0, 0));
- {
- unsigned int circle_count = 2;
- // our input
- ct_ap_circle::input cap_in = {
- viewp_plot,
- { 0, 0 },
- 64
- };
- // execute! Iteration count is number of circles plotted
- ct_ap_circle::output cap_out =
- ct_ap_circle::result_for(cap_in, 0, circle_count);
- }
- viewp_plot.circle({ 0, 0 }, 1, CT_RGBF(1, 1, 0));
- viewp_plot.circle({ 0, 0 }, 2, CT_RGBF(1, 0, 1));
- viewp_plot.save("./output.bmp");
- // auto open on windows
- //std::system("mspaint ./output.bmp");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment