/
SilovAndrey
/
easel_examples
Обзор
Документация
Войти
/
SilovAndrey
/
easel_examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
shapes.cpp
318 строк
7 KB
Andrey HomePC
Add easel_examples v0.1.0 with shapes, space, paths examples
10 июл 2026, 10:34
10 июл 2026, 10:34
8ecc405
Код
Авторство
О чём код?
module; #include <numbers> module App; using namespace easel; using std::numbers::pi; auto constexpr window_size = point{640.0f, 480.0f}; auto constexpr bkd_color = rgb(44, 42, 45); void background(canvas& cnv) { cnv.fill_style(bkd_color); cnv.fill(path_rect({{0, 0}, window_size })); } void rectangles(canvas& cnv) { constexpr auto x = 40.0f; constexpr auto y = 40.0f; cnv.line_width(2); auto preserve = path_rect({x, y, {150.0f, 100.0f}}); cnv.fill_style(colors::red); cnv.fill(preserve); cnv.stroke_style(colors::navajo_white.opacity(0.5)); cnv.stroke(preserve); preserve = path_round_rect({x + 30, y + 30, {150, 100}}, 10); cnv.fill_style(colors::blue.opacity(0.5)); cnv.fill(preserve); cnv.stroke_style(colors::honeydew.opacity(0.5)); cnv.stroke(preserve); } void circles_and_arcs(canvas& cnv) { constexpr auto x = 300; constexpr auto y = 100; for (int i = 0; i != 7; ++i) { float cx = x+(i*45.0f); float cy = y; float ri = 7-i; float radius = 20+(ri*5); cnv.fill_style(hsl(360/7 * i, 0.8, 0.5).opacity(0.7)); cnv.fill(path_circle({cx, cy, radius})); cnv.line_width((ri+1)/2); cnv.stroke_style(colors::light_sky_blue.opacity(0.8)); Path pa; pa.arc(cx, cy, radius, 0.0f, pi + (pi * ((i+1)/7.0f)), false); cnv.stroke(pa); } } void arc_to(canvas& cnv) { constexpr auto x = 40; constexpr auto y = 200; constexpr auto r = 40; auto make_arc = [=](Path& p) { p.move_to(x, y); p.line_to(x+(80-r), y); p.arc_to(x+80, y, x+80, y+20, r); p.line_to(x+80, y+80); }; cnv.stroke_style(colors::dodger_blue.opacity(0.6)); cnv.line_width(10); Path p; make_arc(p); cnv.stroke(p); cnv.fill_style(colors::dodger_blue.opacity(0.2)); Path p1; make_arc(p1); p1.line_to(x, y+80); p1.close(); cnv.fill(p1); cnv.stroke_style(colors::white); cnv.line_width(1); Path p2; p2.move_to(x, y); p2.line_to(x+80, y); p2.line_to(x+80, y+80); cnv.stroke(p2); } void line_caps(canvas& cnv) { auto where = point{160, 215}; auto spacing = 25; cnv.line_width(10); cnv.stroke_style(colors::gold); Path p; cnv.line_width(10); cnv.line_cap(cnv.butt); p.move_to(where.x, where.y); p.line_to(where.x+100, where.y); cnv.stroke(p); p.begin_path(); cnv.stroke_style(colors::sky_blue); cnv.line_cap(cnv.round); p.move_to(where.x, where.y+spacing); p.line_to(where.x+100, where.y+spacing); cnv.stroke(p); p.begin_path(); cnv.stroke_style(colors::light_sea_green); cnv.line_cap(cnv.square); p.move_to(where.x, where.y+spacing*2); p.line_to(where.x+100, where.y+spacing*2); cnv.stroke(p); cnv.stroke_style(colors::white); cnv.line_width(1); p.begin_path(); p.move_to(where.x, where.y); p.line_to(where.x+100, where.y); cnv.stroke(p); p.begin_path(); p.move_to(where.x, where.y+spacing); p.line_to(where.x+100, where.y+spacing); cnv.stroke(p); p.begin_path(); p.move_to(where.x, where.y+spacing*2); p.line_to(where.x+100, where.y+spacing*2); cnv.stroke(p); } void line_joins(canvas& cnv) { auto where = point{290, 100}; cnv.line_width(10); cnv.line_cap(cnv.butt); cnv.stroke_style(colors::gold); Path p; cnv.line_join(cnv.bevel_join); p.move_to(where.x, where.y+100); p.line_to(where.x+60, where.y+140); p.line_to(where.x, where.y+180); cnv.stroke(p); cnv.stroke_style(colors::sky_blue); p.begin_path(); cnv.line_join(cnv.round_join); p.move_to(where.x+40, where.y+100); p.line_to(where.x+100, where.y+140); p.line_to(where.x+40, where.y+180); cnv.stroke(p); cnv.stroke_style(colors::light_sea_green); p.begin_path(); cnv.line_join(cnv.miter_join); p.move_to(where.x+80, where.y+100); p.line_to(where.x+140, where.y+140); p.line_to(where.x+80, where.y+180); cnv.stroke(p); cnv.stroke_style(colors::white); cnv.line_width(1); p.begin_path(); p.move_to(where.x, where.y+100); p.line_to(where.x+60, where.y+140); p.line_to(where.x, where.y+180); cnv.stroke(p); p.begin_path(); p.move_to(where.x+40, where.y+100); p.line_to(where.x+100, where.y+140); p.line_to(where.x+40, where.y+180); cnv.stroke(p); p.begin_path (); p.move_to(where.x+80, where.y+100); p.line_to(where.x+140, where.y+140); p.line_to(where.x+80, where.y+180); cnv.stroke(p); } void bezier(canvas& cnv) { auto where = point{450, 280}; auto height = 100; auto width = 120; auto xmove = 20; auto start = point{where.x, where.y}; auto cp1 = point{where.x+xmove, where.y-height}; auto cp2 = point{where.x+width-xmove, where.y-height}; auto end = point{where.x+width, where.y}; cnv.line_width(10); cnv.stroke_style(colors::dodger_blue.opacity(0.6)); cnv.line_cap(cnv.round); Path p; p.move_to(start); p.bezier_curve_to(cp1, cp2, end); cnv.stroke(p); p.begin_path(); cnv.fill_style(colors::pink.opacity(0.8)); p.add_circle(cp1.x, cp1.y, 3); p.add_circle(cp2.x, cp2.y, 3); cnv.fill(p); p.begin_path(); cnv.stroke_style(colors::white); cnv.line_width(1); p.move_to(start); p.line_to(cp1); p.move_to(cp2); p.line_to(end); cnv.stroke(p); } void quad(canvas& cnv) { auto where = point{40, 420}; auto height = 100; auto width = 120; auto start = point{where.x, where.y}; auto cp = point{where.x+(width/2), where.y-height}; auto end = point{where.x+width, where.y}; cnv.line_width(10); cnv.stroke_style(colors::dodger_blue.opacity(0.6)); cnv.line_cap(cnv.round); Path p; p.move_to(start); p.quadratic_curve_to(cp, end); cnv.stroke(p); p.begin_path(); cnv.fill_style(colors::pink.opacity(0.8)); p.add_circle(cp.x, cp.y, 3); cnv.fill(p); p.begin_path(); cnv.stroke_style(colors::white); cnv.line_width(1); p.move_to(start); p.line_to(cp); p.line_to(end); cnv.stroke(p); } void rainbow(canvas::gradient& gr) { gr.add_color_stop(0.0/6, colors::red); gr.add_color_stop(1.0/6, colors::orange); gr.add_color_stop(2.0/6, colors::yellow); gr.add_color_stop(3.0/6, colors::green); gr.add_color_stop(4.0/6, colors::blue); gr.add_color_stop(5.0/6, rgb(0x4B, 0x00, 0x82)); gr.add_color_stop(6.0/6, colors::violet); } void linear_gradient(canvas& cnv) { auto x = 300.0f; auto y = 330.0f; auto gr = canvas::linear_gradient{x, y, x+300, y}; rainbow(gr); cnv.fill_style(gr); cnv.fill(path_round_rect({x, y, {300.0f, 80.0f}}, 5.0f)); } void radial_gradient(canvas& cnv) { auto center = point{208, 360}; auto radius = 65.0f; auto gr = canvas::radial_gradient{center, 5, center.move(15, 10), radius}; gr.add_color_stop(0.0, colors::red); gr.add_color_stop(1.0, colors::black); cnv.fill_style(gr); cnv.fill(path_circle({center.move(15, 10), radius - 10})); } void draw(canvas& cnv, int w, int h) { //cnv.fill_style(rgb(240, 248, 255)); //cnv.fill(path_rect({0, 0, w, h})); background(cnv); rectangles(cnv); circles_and_arcs(cnv); arc_to(cnv); line_caps(cnv); line_joins(cnv); bezier(cnv); quad(cnv); linear_gradient(cnv); radial_gradient(cnv); } int start(int argc, char const* argv[]) { return run_app(argc, argv, window_size, colors::white, false); }