1
0

main.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2022 The Ebitengine Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "bytes"
  17. "image/color"
  18. "log"
  19. "math"
  20. "github.com/hajimehoshi/ebiten/v2"
  21. "github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
  22. "github.com/hajimehoshi/ebiten/v2/text/v2"
  23. "github.com/hajimehoshi/ebiten/v2/vector"
  24. )
  25. const (
  26. screenWidth = 640
  27. screenHeight = 480
  28. )
  29. type Game struct {
  30. path vector.Path
  31. tick int
  32. }
  33. func (g *Game) Update() error {
  34. if g.tick == 0 {
  35. s, err := text.NewGoTextFaceSource(bytes.NewReader(fonts.MPlus1pRegular_ttf))
  36. if err != nil {
  37. return err
  38. }
  39. op := &text.LayoutOptions{}
  40. op.LineSpacing = 110
  41. text.AppendVectorPath(&g.path, "ABCEDFG\nabcdefg\nあいうえお\nかきくけこ", &text.GoTextFace{
  42. Source: s,
  43. Size: 90,
  44. }, op)
  45. }
  46. g.tick++
  47. return nil
  48. }
  49. func (g *Game) Draw(screen *ebiten.Image) {
  50. op := &vector.StrokeOptions{}
  51. op.Width = 2*(float32(math.Sin(float64(g.tick)*2*math.Pi/180))+1) + 1
  52. op.LineJoin = vector.LineJoinRound
  53. op.LineCap = vector.LineCapRound
  54. var geoM ebiten.GeoM
  55. geoM.Translate(50, 0)
  56. vector.StrokePath(screen, g.path.ApplyGeoM(geoM), color.White, true, op)
  57. }
  58. func (*Game) Layout(width, height int) (int, int) {
  59. return screenWidth, screenHeight
  60. }
  61. func main() {
  62. ebiten.SetWindowTitle("Font Vector (Ebitengine Demo)")
  63. if err := ebiten.RunGame(&Game{}); err != nil {
  64. log.Fatal(err)
  65. }
  66. }