mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
examples: add an animated spirograph.v using gg
This commit is contained in:
parent
a67bfebe95
commit
811ac125fa
64
examples/gg/spirograph.v
Normal file
64
examples/gg/spirograph.v
Normal file
@ -0,0 +1,64 @@
|
||||
import gg
|
||||
import math
|
||||
|
||||
const pixel_count = 15000
|
||||
const p = 3
|
||||
const s = math.pi * 2 / f32(pixel_count)
|
||||
const color = gg.Color{255, 255, 255, 255}
|
||||
const background = gg.Color{20, 20, 64, 255}
|
||||
const colors = [
|
||||
gg.Color{255, 255, 255, 255},
|
||||
gg.Color{255, 0, 255, 255},
|
||||
gg.Color{255, 255, 0, 255},
|
||||
gg.Color{0, 255, 255, 255},
|
||||
gg.Color{0, 0, 255, 255},
|
||||
gg.Color{0, 0, 0, 255},
|
||||
]!
|
||||
|
||||
mut k := 497
|
||||
mut scale := 200
|
||||
gg.start(
|
||||
window_title: 'Spirograph'
|
||||
bg_color: background
|
||||
width: 900
|
||||
height: 950
|
||||
sample_count: 2
|
||||
frame_fn: fn [mut k, mut scale] (ctx &gg.Context) {
|
||||
wsize := gg.window_size()
|
||||
ctx.begin()
|
||||
d := math.sin(f64(ctx.frame) / 300)
|
||||
if math.abs(d) < 0.0015 {
|
||||
k++
|
||||
}
|
||||
if ctx.pressed_keys[int(gg.KeyCode.left)] {
|
||||
k--
|
||||
}
|
||||
if ctx.pressed_keys[int(gg.KeyCode.right)] {
|
||||
k++
|
||||
}
|
||||
if ctx.pressed_keys[int(gg.KeyCode.up)] {
|
||||
scale++
|
||||
}
|
||||
if ctx.pressed_keys[int(gg.KeyCode.down)] {
|
||||
scale--
|
||||
}
|
||||
d600 := math.sin(f64(ctx.frame) / 60)
|
||||
cd600 := math.cos(d600)
|
||||
mut pdj, mut pkj := [p]f64{}, [p]f64{}
|
||||
for j := 0; j < p; j++ {
|
||||
pdj[j], pkj[j] = math.pow(d, j), math.pow(k, j)
|
||||
}
|
||||
for i := 0; i < pixel_count; i++ {
|
||||
mut x, mut y := 0.0, 0.0
|
||||
for j := 0; j < p; j++ {
|
||||
a := pkj[j] * i * s
|
||||
x += pdj[j] * math.sin(a) * cd600
|
||||
y += pdj[j] * math.cos(a) * cd600
|
||||
}
|
||||
ctx.draw_rect_filled(f32(wsize.width / 2 + scale * x), f32(wsize.height / 2 + scale * y),
|
||||
1, 1, colors[i % colors.len])
|
||||
}
|
||||
ctx.draw_text(wsize.width / 2 - 170, wsize.height - 15, 'frame: ${ctx.frame:06}, k: ${k:4}, scale: ${scale:4}, arrows to change')
|
||||
ctx.end()
|
||||
}
|
||||
)
|
2
thirdparty/sokol/util/sokol_gl.h
vendored
2
thirdparty/sokol/util/sokol_gl.h
vendored
@ -2309,7 +2309,7 @@ typedef struct {
|
||||
#define _SGL_DEFAULT_CONTEXT_POOL_SIZE (4)
|
||||
#define _SGL_DEFAULT_PIPELINE_POOL_SIZE (64)
|
||||
// __v_ start
|
||||
#define _SGL_DEFAULT_MAX_VERTICES (1<<17)
|
||||
#define _SGL_DEFAULT_MAX_VERTICES (1<<22)
|
||||
#define _SGL_DEFAULT_MAX_COMMANDS (1<<15)
|
||||
// __v_ end
|
||||
#define _SGL_SLOT_SHIFT (16)
|
||||
|
Loading…
x
Reference in New Issue
Block a user