mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00

Some checks failed
Graphics CI / gg-regressions (push) Waiting to run
vlib modules CI / build-module-docs (push) Waiting to run
native backend CI / native-backend-ubuntu (push) Waiting to run
vab CI / v-compiles-os-android (push) Waiting to run
native backend CI / native-backend-windows (push) Waiting to run
Shy and PV CI / v-compiles-puzzle-vibes (push) Waiting to run
Sanitized CI / sanitize-undefined-clang (push) Waiting to run
Sanitized CI / sanitize-undefined-gcc (push) Waiting to run
Sanitized CI / tests-sanitize-address-clang (push) Waiting to run
Sanitized CI / sanitize-address-msvc (push) Waiting to run
Sanitized CI / sanitize-address-gcc (push) Waiting to run
Sanitized CI / sanitize-memory-clang (push) Waiting to run
sdl CI / v-compiles-sdl-examples (push) Waiting to run
Time CI / time-linux (push) Waiting to run
Time CI / time-macos (push) Waiting to run
Time CI / time-windows (push) Waiting to run
toml CI / toml-module-pass-external-test-suites (push) Waiting to run
Tools CI / tools-linux (clang) (push) Waiting to run
Tools CI / tools-linux (gcc) (push) Waiting to run
Tools CI / tools-linux (tcc) (push) Waiting to run
Tools CI / tools-macos (clang) (push) Waiting to run
Tools CI / tools-windows (gcc) (push) Waiting to run
Tools CI / tools-windows (msvc) (push) Waiting to run
Tools CI / tools-windows (tcc) (push) Waiting to run
Tools CI / tools-docker-ubuntu-musl (push) Waiting to run
vab CI / vab-compiles-v-examples (push) Waiting to run
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Waiting to run
wasm backend CI / wasm-backend (windows-2022) (push) Waiting to run
Workflow Lint / lint-yml-workflows (push) Has been cancelled
82 lines
1.2 KiB
V
82 lines
1.2 KiB
V
module main
|
|
|
|
import gg
|
|
|
|
struct App {
|
|
mut:
|
|
gg &gg.Context = unsafe { nil }
|
|
rotation f32 = f32(0)
|
|
edge int = 3
|
|
}
|
|
|
|
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(
|
|
window_title: 'Simple Polygons'
|
|
width: 500
|
|
height: 500
|
|
bg_color: gg.black
|
|
event_fn: event
|
|
frame_fn: render
|
|
user_data: app
|
|
)
|
|
|
|
app.gg.run()
|
|
}
|
|
|
|
fn render(app &App) {
|
|
app.gg.begin()
|
|
|
|
color := gg.Color{
|
|
r: 175
|
|
g: 0
|
|
b: 0
|
|
a: 200
|
|
}
|
|
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()
|
|
}
|
|
|
|
fn event(e &gg.Event, mut app App) {
|
|
match e.typ {
|
|
.key_down {
|
|
match e.key_code {
|
|
.up {
|
|
app.edge++
|
|
}
|
|
.down {
|
|
if app.edge > 3 {
|
|
app.edge--
|
|
}
|
|
}
|
|
.right {
|
|
app.rotation++
|
|
}
|
|
.left {
|
|
app.rotation--
|
|
}
|
|
.escape {
|
|
app.gg.quit()
|
|
}
|
|
else {}
|
|
}
|
|
}
|
|
else {}
|
|
}
|
|
}
|