From 71ff221cff4115780f92e1c233e8e26b427e12c4 Mon Sep 17 00:00:00 2001 From: Emirhan Yener <97049246+emirhanyener@users.noreply.github.com> Date: Thu, 30 Jun 2022 21:21:12 +0300 Subject: [PATCH] gg: update draw polygon test (#14880) --- vlib/gg/testdata/draw_simple_polygons.vv | 45 ++++++++++++++++++------ 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/vlib/gg/testdata/draw_simple_polygons.vv b/vlib/gg/testdata/draw_simple_polygons.vv index ba41701f5b..5a60fed4b7 100644 --- a/vlib/gg/testdata/draw_simple_polygons.vv +++ b/vlib/gg/testdata/draw_simple_polygons.vv @@ -1,14 +1,20 @@ +module main + import gg import gx struct App { mut: - gg &gg.Context = 0 + gg &gg.Context = unsafe { 0 } rotation f32 = f32(0) + edge int = 3 } [console] fn main() { + println('rotation: left arrow key, right arrow key') + println('center polygon edge: up arrow key, down arrow key') + mut app := &App{} app.gg = gg.new_context( @@ -33,14 +39,19 @@ fn render(app &App) { b: 0 a: 200 } - mut shape := 3 - for i := 1; i < 5; i++ { - for j := 1; j < 5; j++ { - app.gg.draw_polygon_filled(100 * j, 100 * i, 30, shape, app.rotation, color) - shape++ + mut edge := 3 + for i := 0; i <= 5; i++ { + for j := 0; j <= 5; j++ { + if i == 0 || j == 0 || i == 5 || j == 5 { + app.gg.draw_polygon_filled(50 + 80 * i, 50 + 80 * j, 30, edge, app.rotation, + color) + edge++ + } } } + app.gg.draw_polygon_filled(250, 250, 150, app.edge, app.rotation, color) + app.gg.end() } @@ -48,13 +59,25 @@ fn event(e &gg.Event, mut app App) { match e.typ { .key_down { match e.key_code { - .right { app.rotation++ } - .left { app.rotation-- } - .escape { app.gg.quit() } + .up { + app.edge++ + } + .down { + if app.edge > 3 { + app.edge-- + } + } + .right { + app.rotation++ + } + .left { + app.rotation-- + } + .escape { + app.gg.quit() + } else {} } - print('rotation: ') - println(app.rotation) } else {} }