gart

package module
v0.0.0-...-e4998ed Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2019 License: MIT Imports: 15 Imported by: 0

README

gart

Gart is a way of creating art through golang and cairo

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Palettes = map[string]Palette{
	"pleasant": {
		{0.500, 0.33, 0.70},
		{0.436, 0.23, 0.61},
		{0.286, 0.28, 0.66},
		{0.119, 0.70, 0.83},
		{0.072, 0.33, 0.70},
	},
	"vangogh_cafeterrace": {
		{0.1361, 0.7200, 0.5700},
		{0.6000, 0.4400, 0.3800},
		{0.3306, 0.1900, 0.2500},
		{0.0889, 0.7600, 0.5700},
		{0.3361, 0.1900, 0.2200},
		{0.6056, 0.3900, 0.4200},
		{0.1806, 0.5700, 0.8100},
	},
	"vangogh_roadwithcypressandstar": {
		{0.0417, 0.6800, 0.4100},
		{0.1611, 0.9600, 0.8200},
		{0.6333, 0.6100, 0.4300},
		{0.7333, 0.7300, 0.0600},
		{0.7528, 0.9900, 0.0500},
		{0.5833, 0.5300, 0.5600},
		{0.6389, 0.6700, 0.0800},
	},
	"port": {
		{0.0389, 0.8700, 0.5200},
		{0.5944, 1.0000, 0.5000},
		{0.5694, 0.9000, 0.2700},
		{0.4889, 0.3200, 0.2500},
		{0.0472, 0.1300, 0.4100},
		{0.0778, 0.4700, 0.6500},
	},
	"vangogh_potatoeaters": {
		{0.2361, 0.3100, 0.1400},
		{0.1222, 0.6900, 0.2900},
		{0.1139, 0.7000, 0.4300},
		{0.2528, 0.3700, 0.0700},
		{0.1500, 0.2800, 0.4700},
		{0.1361, 0.4500, 0.1400},
		{0.2861, 0.2200, 0.0800},
	},
	"grayscale": {
		{0.0, 0.0, 0.0},
		{0.0, 0.0, 0.1},
		{0.0, 0.0, 0.2},
		{0.0, 0.0, 0.3},
		{0.0, 0.0, 0.4},
		{0.0, 0.0, 0.5},
		{0.0, 0.0, 0.6},
		{0.0, 0.0, 0.7},
	},
	"desert1": {
		{0.6111, 0.2700, 0.3000},
		{0.0833, 0.1600, 0.4900},
		{0.0778, 0.5000, 0.7000},
		{0.0806, 0.5300, 0.8700},
		{0.0861, 0.3800, 0.7600},
		{0.5833, 0.5100, 0.9400},
		{0.9750, 0.0400, 0.6100},
	},
}
View Source
var ProgramVersionID string

ProgramVersionID is a string that can be set when building in order to identify the version ID of the program. For instance, to set it to the commit ID of your project you can run go build like this:

go build -ldflags "-X github.com/wetdesertrock/gart.ProgramVersionID=$GIT_COMMIT"

gart will store this ID in the metadata and print it to stdout

Functions

func GetOutputFileName

func GetOutputFileName(outputPath string, outName string) (string, error)

GetOutputFileName will look at a given path with a given name string and looks for the next available file name. Files are assumed to be named like this: "<outName>_<id>.png". The ID is determined by the files in the folder and will automatically be set to the max ID found + 1.

func HSLtoRGB

func HSLtoRGB(h, s, l float64) (float64, float64, float64)

func InitFS

func InitFS(outputPath string)

InitFS is given an output path and does any fs specific initializations (currently just creating the output folder).

func InitSettings

func InitSettings(cliArgs *CLIArgs) flexiconfig.Settings

InitSettings loads the settings files (reading them from the args if needed) You shouldn't need to invoke this directly. It is exposed incase somone needs to initialize the program manually.

func RGBtoHSL

func RGBtoHSL(r, g, b float64) (float64, float64, float64)

Types

type CLIArgs

type CLIArgs struct {
	ConfigPaths  []string `flag:"config-path" short:"c" help:"Loads the specified config file"`
	OutputConfig string   `flag:"config-out" short:"O" help:"Saves the resulting config at the specified path"`
}

func InitCLIArgs

func InitCLIArgs() *CLIArgs

InitCLIArgs parses the CLI arguments and returns them. You shouldn't need to invoke this directly. It is exposed incase somone needs to initialize the program manually.

func InitProgram

func InitProgram(name string) (flexiconfig.Settings, *CLIArgs)

InitProgram does all of the mundane tasks needed to run a program. You shouldn't need to invoke this directly. It is exposed incase somone needs to initialize the program manually.

type HSLColor

type HSLColor struct {
	H float64
	S float64
	L float64
}

HSLColor is a struct used to hold and operate on HSL colors

func NewHSLColor

func NewHSLColor(h, s, l float64) HSLColor

func NewHSLColorFromRGB

func NewHSLColorFromRGB(r, g, b float64) HSLColor

func (HSLColor) ToRGB

func (this HSLColor) ToRGB() (float64, float64, float64)

type Painting

type Painting struct {
	Renderer *Renderer
	Settings flexiconfig.Settings
}

Painting is the core struct that allows you to render and save your image

func InitProgramWithPainting

func InitProgramWithPainting(name string) *Painting

InitProgramWithPainting will setup the program (parse CLI args, retrive settings), and setup a Painting to use.

func NewPainting

func NewPainting(settings flexiconfig.Settings) *Painting

NewPainting creates a new painting struct using the settings object. You shouldn't need to ever use this yourself for normal use. Instead you should use InitProgramWithPainting.

func (*Painting) Save

func (this *Painting) Save() (string, error)

Save saves the painting. It will determine where to save the file based on the gart:output:OutFileName and gart:output:OutPath settings.

type Palette

type Palette []HSLColor

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer is a struct that holds the cairo instance and exposes wrapper methods using cairo. This is the struct you will use to do the actual drawaing.

func NewRenderer

func NewRenderer(config flexiconfig.Settings) *Renderer

NewRenderer creates a new renderer from a settings instance. You shouldn't need to use this for average use. It will be created when you create a new painting or simulator.

func (*Renderer) Circle

func (this *Renderer) Circle(filled bool, x, y, radius float64)

Circle will draw a circle located at the x/y locatinon

func (*Renderer) GetSurface

func (this *Renderer) GetSurface() *cairo.Surface

GetSurface returns the underlying cairo Surface.

func (*Renderer) Line

func (this *Renderer) Line(connected bool, points []Vector2d)

Line draws a line defined by the connected points.

func (*Renderer) LineWidth

func (this *Renderer) LineWidth(lineWidth float64)

LineWidth sets the width of the lines drawn

func (*Renderer) Polygon

func (this *Renderer) Polygon(points []Vector2d)

Polygon draws a filled polygon defined by the points.

func (*Renderer) SavePNG

func (this *Renderer) SavePNG(outPath string)

SavePNG saves the surface to a png.

func (*Renderer) SetBlendMode

func (this *Renderer) SetBlendMode(operator cairo.Operator)

SetBlendMode sets the blend mode for cairo.

func (*Renderer) SetColor

func (this *Renderer) SetColor(color HSLColor, alpha float64)

SetColor sets the color the renderer will use for future operations

type Simulator

type Simulator struct {
	*Painting
	// contains filtered or unexported fields
}

Simulator is a struct that provides an easy way of drawing things in a simulated fashion similar to game engines. It allows you to define a framerate and how long it will run for.

func InitProgramWithSimulator

func InitProgramWithSimulator(name string, world World) *Simulator

InitProgramWithSimulator will setup the program (parse CLI args, retrive settings), and setup a Simulator with the supplied world.

func NewSimulator

func NewSimulator(world World, settings flexiconfig.Settings) *Simulator

NewSimulator creates a new simulator struct using the settings object. You shouldn't need to ever use this yourself for normal use. Instead you should use InitProgramWithSimulator.

func (*Simulator) Run

func (this *Simulator) Run()

Run will start simulating the world.

type Vector2d

type Vector2d struct {
	X float64
	Y float64
}

Vector2d is a immutable struct for doing 2d vector operations.

func NewVector2d

func NewVector2d(x, y float64) Vector2d

NewVector2d creates a new vector from the x and y components

func NewVector2dFromPolar

func NewVector2dFromPolar(angle, magnitude float64) Vector2d

NewVector2dFromPolar creates a new vector from a given angle and maagnitude.

func (Vector2d) Add

func (this Vector2d) Add(other Vector2d) Vector2d

func (Vector2d) AddScalar

func (this Vector2d) AddScalar(scalar float64) Vector2d

func (Vector2d) Direction

func (this Vector2d) Direction() float64

Direction gives the angle that this vector is facing (in radians)

func (Vector2d) Distance

func (this Vector2d) Distance(other Vector2d) float64

Distance returns the distance computed between two vectors.

func (Vector2d) Div

func (this Vector2d) Div(other Vector2d) Vector2d

func (Vector2d) DivScalar

func (this Vector2d) DivScalar(scalar float64) Vector2d

func (Vector2d) Equals

func (this Vector2d) Equals(other Vector2d) bool

func (Vector2d) Length

func (this Vector2d) Length() float64

Length returns the length of the vector.

func (Vector2d) LengthSq

func (this Vector2d) LengthSq() float64

LengthSq returns the length of the vector squared. This should provide performance benefits when in tight loops by not doing math.Sqrt().

func (Vector2d) Mult

func (this Vector2d) Mult(other Vector2d) Vector2d

func (Vector2d) MultScalar

func (this Vector2d) MultScalar(scalar float64) Vector2d

func (Vector2d) Normalize

func (this Vector2d) Normalize() Vector2d

Normalize returns a normalized vector.

func (Vector2d) PolarCoordinates

func (this Vector2d) PolarCoordinates() (float64, float64)

PolarCoordinates returns the angle and magnitude of the vector.

func (Vector2d) Rotate

func (this Vector2d) Rotate(theta float64) Vector2d

func (Vector2d) String

func (this Vector2d) String() string

func (Vector2d) Sub

func (this Vector2d) Sub(other Vector2d) Vector2d

func (Vector2d) SubScalar

func (this Vector2d) SubScalar(scalar float64) Vector2d

type World

type World interface {
	Init(simulator *Simulator)
	Update(simulator *Simulator, dt float64)
	Render(simulator *Simulator)
}

World is an interface defining a world that will be simulated.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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