fps counter
This commit is contained in:
parent
5cf764db2d
commit
4bf3b2fc0d
37
chatgpt.go
37
chatgpt.go
@ -1,15 +1,22 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"math"
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.niplace.ru/XoxJlopeZi4BB/dev/fb"
|
"git.niplace.ru/XoxJlopeZi4BB/dev/fb"
|
||||||
|
"github.com/golang/freetype"
|
||||||
|
"github.com/golang/freetype/truetype"
|
||||||
|
"golang.org/x/image/font"
|
||||||
|
"golang.org/x/image/font/gofont/gomono"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Width, Height = fb.Resolution()
|
var Width, Height = fb.Resolution()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cubeSize = 50
|
cubeSize = 50
|
||||||
Zoom = 1000.0
|
Zoom = 1000.0
|
||||||
@ -118,12 +125,31 @@ func main() {
|
|||||||
|
|
||||||
// Palette for the GIF
|
// Palette for the GIF
|
||||||
palette := []color.Color{color.Black, color.White}
|
palette := []color.Color{color.Black, color.White}
|
||||||
|
var (
|
||||||
|
fontSize = 96.0
|
||||||
|
DPI = 72.0
|
||||||
|
spacing = 1.5
|
||||||
|
)
|
||||||
|
f, err := truetype.Parse(gomono.TTF)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
ctx := freetype.NewContext()
|
||||||
|
ctx.SetDPI(DPI)
|
||||||
|
ctx.SetFont(f)
|
||||||
|
ctx.SetFontSize(fontSize)
|
||||||
|
ctx.SetClip(image.Rect(0, 0, Width, Height))
|
||||||
|
ctx.SetSrc(image.NewUniform(palette[1]))
|
||||||
|
ctx.SetHinting(font.HintingNone)
|
||||||
|
|
||||||
|
var text string = "text"
|
||||||
|
var fps int
|
||||||
// Generate frames
|
// Generate frames
|
||||||
for i := 0; i < frameCount; i++ {
|
for i := 0; i < frameCount; i++ {
|
||||||
angle := float64(i) * rotationStep
|
angle := float64(i) * rotationStep
|
||||||
img := image.NewPaletted(image.Rect(0, 0, Width, Height), palette)
|
img := image.NewPaletted(image.Rect(0, 0, Width, Height), palette)
|
||||||
draw.Draw(img, img.Bounds(), &image.Uniform{color.Black}, image.Point{}, draw.Src)
|
draw.Draw(img, img.Bounds(), &image.Uniform{color.Black}, image.Point{}, draw.Src)
|
||||||
|
ctx.SetDst(img)
|
||||||
|
|
||||||
// Rotate and project vertices
|
// Rotate and project vertices
|
||||||
projVertices := make([]Point2D, len(vertices))
|
projVertices := make([]Point2D, len(vertices))
|
||||||
@ -139,9 +165,20 @@ func main() {
|
|||||||
drawLine(img, p1, p2, color.White)
|
drawLine(img, p1, p2, color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
text = fmt.Sprint(fps)
|
||||||
|
pt := freetype.Pt(30, 30+int(ctx.PointToFixed(fontSize)>>6))
|
||||||
|
_, err = ctx.DrawString(text, pt)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
pt.Y += ctx.PointToFixed(fontSize * spacing)
|
||||||
|
|
||||||
|
t := time.Now()
|
||||||
err := fb.Draw(img)
|
err := fb.Draw(img)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
d := time.Since(t)
|
||||||
|
fps = int(time.Second / d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
go.mod
5
go.mod
@ -3,3 +3,8 @@ module git.niplace.ru/XoxJlopeZi4BB/cube
|
|||||||
go 1.23.4
|
go 1.23.4
|
||||||
|
|
||||||
require git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033838-b2021445b668
|
require git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033838-b2021445b668
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
|
golang.org/x/image v0.23.0 // indirect
|
||||||
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -2,3 +2,7 @@ git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033410-5c05476970ae h1:anDr2+Kui
|
|||||||
git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033410-5c05476970ae/go.mod h1:7YjlidjZZr0+dNjfgYgy5hPfdE3pV1bBT5UcNvz5LjY=
|
git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033410-5c05476970ae/go.mod h1:7YjlidjZZr0+dNjfgYgy5hPfdE3pV1bBT5UcNvz5LjY=
|
||||||
git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033838-b2021445b668 h1:Kh9BL+0ia8Lo+lvIsZ3a5pYqzq9ZYwk0+gho7L7BASI=
|
git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033838-b2021445b668 h1:Kh9BL+0ia8Lo+lvIsZ3a5pYqzq9ZYwk0+gho7L7BASI=
|
||||||
git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033838-b2021445b668/go.mod h1:7YjlidjZZr0+dNjfgYgy5hPfdE3pV1bBT5UcNvz5LjY=
|
git.niplace.ru/XoxJlopeZi4BB/dev v0.0.0-20250126033838-b2021445b668/go.mod h1:7YjlidjZZr0+dNjfgYgy5hPfdE3pV1bBT5UcNvz5LjY=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||||
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
|
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
||||||
|
golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY=
|
||||||
|
Loading…
Reference in New Issue
Block a user