image

package
v0.0.0-...-d74af64 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Black = &Color{
	red:   0,
	green: 0,
	blue:  0,
}
View Source
var White = &Color{
	red:   1,
	green: 1,
	blue:  1,
}

Functions

This section is empty.

Types

type Canvas

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

Canvas represents a grid of pixels for displaying an image.

func NewCanvas

func NewCanvas(width, height int) *Canvas

NewCanvas returns a new Canvas object.

func (*Canvas) PixelAt

func (c *Canvas) PixelAt(x, y int) *Color

PixelAt returns the Color of a Canvas's pixel.

func (*Canvas) WritePixel

func (c *Canvas) WritePixel(x, y int, color *Color)

WritePixel sets a Canvas's pixel to a color.

func (*Canvas) WriteToFile

func (c *Canvas) WriteToFile(name string) error

WriteToFile writes the canvas ppm to a file.

type CheckerPattern

type CheckerPattern struct {
	*PatternObject
}

CheckerPattern represents a 3D checker pattern.

func NewCheckerPattern

func NewCheckerPattern(color1, color2 *Color) *CheckerPattern

NewCheckerPattern returns a new CheckerPattern object.

type Color

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

Color is a tuple representing an rgb value.

func NewColor

func NewColor(r, g, b float64) *Color

NewColor returns a new Color object.

func (*Color) Add

func (c *Color) Add(c2 *Color) *Color

Add adds two colors together and returns the result.

func (*Color) Equals

func (c *Color) Equals(c2 *Color) bool

Equals returns whether or not two colors are equal to each other.

func (*Color) Multiply

func (c *Color) Multiply(val float64) *Color

Multiply returns a color multiplied by a value.

func (*Color) MultiplyColor

func (c *Color) MultiplyColor(c2 *Color) *Color

MultiplyColor multiplies two colors by each other and returns the result.

func (*Color) Subtract

func (c *Color) Subtract(c2 *Color) *Color

Subtract returns the difference between two colors.

type GradientPattern

type GradientPattern struct {
	*PatternObject
}

GradientPattern represents a gradient color pattern.

func NewGradientPattern

func NewGradientPattern(color1, color2 *Color) *GradientPattern

NewGradientPattern returns a new GradientPattern object.

type MockPattern

type MockPattern struct {
	*PatternObject
}

MockPattern is a mock pattern object for unit testing.

func NewMockPattern

func NewMockPattern() *MockPattern

NewMockPattern returns a new MockPattern object.

type Pattern

type Pattern interface {
	GetColors() []*Color
	GetTransform() *base.Matrix
	SetTransform(...*base.Matrix)
	PatternAt(*base.Tuple) *Color
}

Pattern represents a color pattern.

type PatternObject

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

PatternObject is the base implementation of the pattern interface.

func NewPattern

func NewPattern(
	color1, color2 *Color,
	patternFunc func(*base.Tuple, *PatternObject) *Color,
) *PatternObject

NewPattern returns a new pattern object.

func (*PatternObject) GetColors

func (p *PatternObject) GetColors() []*Color

GetColors returns a list of colors for the pattern.

func (*PatternObject) GetTransform

func (p *PatternObject) GetTransform() *base.Matrix

GetTransform returns the pattern's transform matrix.

func (*PatternObject) PatternAt

func (p *PatternObject) PatternAt(point *base.Tuple) *Color

PatternAt returns the color at a specific point, based on the pattern.

func (*PatternObject) SetTransform

func (p *PatternObject) SetTransform(matrix ...*base.Matrix)

SetTransform sets the pattern's transform matrix.

type RingPattern

type RingPattern struct {
	*PatternObject
}

RingPattern represents a ring color pattern.

func NewRingPattern

func NewRingPattern(color1, color2 *Color) *RingPattern

NewRingPattern returns a new RingPattern object.

type StripePattern

type StripePattern struct {
	*PatternObject
}

StripePattern represents a striped color pattern.

func NewStripePattern

func NewStripePattern(color1, color2 *Color) *StripePattern

NewStripePattern returns a new StripePattern object.

Jump to

Keyboard shortcuts

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