gog

package module
v2.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

README

GoDoc

GOG v2

GOG is a Go Object-oriented 2d drawing library for creative coding and generative art

curve_anim

Examples

Path follow animation
ctx := gog.NewContext(250, 100)
rect := shapes.Rect(v.Vec{}, 30, 10)
lemn := shapes.Lemniscate(100, 100).SetPos(ctx.Center)
lemnTotalLength := lemn.Length()
for _, length := range utils.Linspace(0, lemnTotalLength, 120) {
  ctx.Clear(color.Black)
  ctx.Stroke(lemn, gog.DefaultStrokeStyle())
  pos, ang := lemn.PointAngleAtLength(length)
  ctx.Fill(rect.SetPos(pos).Rotated(ang), color.White)
  ctx.AppendAnimationFrame()
}
ctx.SaveAPNG("path_follow.png", 2)

path_follow

See folder examples for all examples

Documentation

Overview

Package gog is a Go Drawing Library

Example

150-frame rotating cubic bezier APNG animation

ctx := gog.NewContext(250, 250)
curve := shapes.CubicBezier(100, 95, 50, 300, 190, 88, 140, 200, 50)
curve.SetPos(ctx.Center)
for range 150 {
	ctx.Clear(color.Gray{30})
	curve.Rotate((math.Pi * 2) / 150)
	ctx.DebugDraw(curve)
	ctx.AppendAnimationFrame()
}
// ctx.SaveAPNG("anim.png", 3)
fmt.Println(len(ctx.AnimationFrames))
Output:
150

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapMode

type CapMode uint8
const (
	ButtCap CapMode = iota
	SquareCap
	RoundCap
	CubicCap
	QuadraticCap
)

CapMode constants determines line cap style

type Context

type Context struct {
	AnimationFrames []image.Image
	// Center point of Canvas
	Center v.Vec
	// contains filtered or unexported fields
}

func NewContext

func NewContext(width, height int) *Context

NewContext returns a new drawing context.

func (*Context) AppendAnimationFrame

func (ctx *Context) AppendAnimationFrame()

AppendAnimationFrame appends current canvas to animation frames.

func (*Context) Clear

func (ctx *Context) Clear(c color.Color) *Context

Clear clears canvas

func (*Context) ClearAnimationFrames

func (ctx *Context) ClearAnimationFrames()

ClearAnimationFrames clears context.AnimationFrames

func (*Context) DebugDraw

func (ctx *Context) DebugDraw(pth *path.Path)

DebugDraw draws Path attributes for debug

func (*Context) Fill

func (ctx *Context) Fill(p *path.Path, fillColor color.Color)

Fill draws path with fillColoræ

func (*Context) SaveAPNG

func (ctx *Context) SaveAPNG(filePath string, delay int)

SaveAPNG Saves APNG animation addes with AppendAnimationFrame().

The successive delay times, one per frame, in 100ths of a second. (2 for 50 FPS, 4 for 25 FPS)

func (*Context) SavePNG

func (ctx *Context) SavePNG(filePath string)

SavePNG saves current canvas as static image

func (*Context) Stroke

func (ctx *Context) Stroke(p *path.Path, strokeStyle *StrokeStyle)

Stroke draw paths with StrokeStyle

func (*Context) Surface

func (ctx *Context) Surface() *image.RGBA

Surface returns canvas surface image

type DrawMode

type DrawMode uint8

type JoinMode

type JoinMode uint8
const (
	MiterJoin JoinMode = iota
	RoundJoin
	BevelJoin
)

JoinMode constants determine how stroke segments bridge the gap at a join

type StrokeStyle

type StrokeStyle struct {
	Color     color.Color
	LineWidth float64
	// Line cap style constant
	//
	// 0=ButtCap 1=SquareCap 2=RoundCap 3=CubicCap 4=QuadraticCap
	Cap CapMode
	// Line join style
	//
	// 0=MiterJoin 1=RoundJoin 2=BevelJoin
	Join JoinMode
}

Style of path

func DefaultStrokeStyle

func DefaultStrokeStyle() *StrokeStyle

DefaultStyle returns default style

func NewStrokeStyle

func NewStrokeStyle(fillColor, strokeColor color.Color, lineWidth float64, cap CapMode, join JoinMode) *StrokeStyle

NewStyle shorthand for create Style{}

func (*StrokeStyle) SetColor

func (s *StrokeStyle) SetColor(c color.Color) *StrokeStyle

func (*StrokeStyle) SetLineWidth

func (s *StrokeStyle) SetLineWidth(w float64) *StrokeStyle

Directories

Path Synopsis
examples
bezier command
cap_join command
path_follow command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL