mirror of
https://github.com/Fluffy-Bean/ColouringApp.git
synced 2025-05-20 18:34:52 +00:00
Convert pen strokes to texture
This commit is contained in:
parent
9cfdd651b7
commit
f2d2a539ea
4 changed files with 83 additions and 27 deletions
27
penTool.go
27
penTool.go
|
@ -5,22 +5,41 @@ import (
|
|||
)
|
||||
|
||||
type penTool struct {
|
||||
Color raylib.Color
|
||||
Size float32
|
||||
Color raylib.Color
|
||||
Points []raylib.Vector2
|
||||
}
|
||||
|
||||
func (p *penTool) Draw(offset raylib.Vector2) {
|
||||
func (p *penTool) Render() raylib.Texture2D {
|
||||
offset := raylib.Vector2Scale(canvas.Offset, -1)
|
||||
texture := raylib.LoadRenderTexture(int32(canvas.Size.X), int32(canvas.Size.Y))
|
||||
|
||||
raylib.BeginTextureMode(texture)
|
||||
raylib.ClearBackground(raylib.Fade(raylib.Black, 0))
|
||||
for i := 0; i < len(p.Points)-1; i++ {
|
||||
startPoint := raylib.Vector2Add(p.Points[i], offset)
|
||||
endPoint := raylib.Vector2Add(p.Points[i+1], offset)
|
||||
|
||||
raylib.DrawLineEx(startPoint, endPoint, p.Size, p.Color)
|
||||
raylib.DrawCircle(int32(startPoint.X), int32(startPoint.Y), p.Size/2, p.Color)
|
||||
}
|
||||
// Add a circle at the end of the stroke
|
||||
if len(p.Points) > 0 {
|
||||
endPoint := raylib.Vector2Add(p.Points[len(p.Points)-1], offset)
|
||||
raylib.DrawCircle(int32(endPoint.X), int32(endPoint.Y), p.Size/2, p.Color)
|
||||
}
|
||||
raylib.EndTextureMode()
|
||||
|
||||
return texture.Texture
|
||||
}
|
||||
|
||||
func (p *penTool) Draw() {
|
||||
for i := 0; i < len(p.Points)-1; i++ {
|
||||
startPoint := p.Points[i]
|
||||
endPoint := p.Points[i+1]
|
||||
raylib.DrawLineEx(startPoint, endPoint, p.Size, p.Color)
|
||||
raylib.DrawCircle(int32(startPoint.X), int32(startPoint.Y), p.Size/2, p.Color)
|
||||
}
|
||||
if len(p.Points) > 0 {
|
||||
endPoint := p.Points[len(p.Points)-1]
|
||||
raylib.DrawCircle(int32(endPoint.X), int32(endPoint.Y), p.Size/2, p.Color)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue