47 lines
1.4 KiB
C++
47 lines
1.4 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
#pragma once
|
|
|
|
#include "tool_base.h"
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
// Return the points of a regular n-gon
|
|
// with the centre at (x, y)
|
|
// that is modified in the sense that it takes rf,
|
|
// which is used to set the radius for each individual point.
|
|
// It is rotated by base_angle,
|
|
// where 0 starts drawing at the top.
|
|
std::vector<std::pair<float, float>>
|
|
regular_polygon_mod(int n, std::function<float(int)> rf, int x = 0, int y = 0,
|
|
float base_angle = 0);
|
|
|
|
// Return the points of a star
|
|
// with n spikes,
|
|
// the inner radius r1,
|
|
// the outer radius r2
|
|
// and the centre (x, y),
|
|
// rotated by base_angle.
|
|
std::vector<std::pair<float, float>> star(int n, float r1, float r2, int x = 0,
|
|
int y = 0, float base_angle = 0);
|
|
|
|
class star_tool : public tool_base {
|
|
public:
|
|
// Initialize a new star tool.
|
|
// It can draw stars with arbitrary number of spikes (however, at least 2).
|
|
// The preview only supports spikes from 3 to 6 and falls back to 5
|
|
// if a spike outside of that range is given.
|
|
star_tool(canvas_buffer &canvas, int spikes = 5);
|
|
|
|
void draw(int x0, int y0, int x1, int y1);
|
|
|
|
void set_text(std::stringstream &stream);
|
|
|
|
void set_spikes(int spikes);
|
|
|
|
void set_radius_factor(int radius_factor);
|
|
|
|
private:
|
|
int spikes;
|
|
float radius_factor = 1.0 / 3.0;
|
|
};
|