Documentation ¶
Index ¶
- type BlendedPattern
- type Camera
- func (c *Camera) FieldOfView() float64
- func (c *Camera) Height() int
- func (c *Camera) PixelSize() float64
- func (c *Camera) RayForPixel(x, y int) *Ray
- func (c *Camera) Render(w *World) *Canvas
- func (t *Camera) Transform() *Matrix4
- func (c *Camera) Width() int
- func (c *Camera) WithThreads(threads int) *Camera
- func (c *Camera) WithTransform(t *Matrix4) *Camera
- func (c *Camera) WithTransformFromParameters(from *Point, to *Point, up *Vector) *Camera
- type Canvas
- type CheckerPattern
- type Color
- func (c *Color) B() float64
- func (c *Color) Equals(d *Color) bool
- func (c *Color) G() float64
- func (c *Color) MinusColor(d *Color) *Color
- func (c *Color) PlusColor(d *Color) *Color
- func (c *Color) R() float64
- func (c *Color) RGBA() (r, g, b, a uint32)
- func (c *Color) TimesColor(d *Color) *Color
- func (c *Color) TimesScalar(f float64) *Color
- type GradientPattern
- type Intersection
- func (i *Intersection) ComputeMetadata()
- func (i *Intersection) Equals(j *Intersection) bool
- func (i *Intersection) Eye() *Vector
- func (i *Intersection) Inside() bool
- func (i *Intersection) Normal() *Vector
- func (i *Intersection) Point() *Point
- func (i *Intersection) Ray() *Ray
- func (i *Intersection) Shape() Shape
- func (i *Intersection) ShiftedPoint() *Point
- func (i *Intersection) T() float64
- type Intersections
- type Light
- type Lights
- type Material
- type Matrix2
- type Matrix3
- type Matrix4
- func NewIdentity() *Matrix4
- func NewMatrix4(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p float64) *Matrix4
- func NewRotateX(x float64) *Matrix4
- func NewRotateY(x float64) *Matrix4
- func NewRotateZ(x float64) *Matrix4
- func NewScale(x, y, z float64) *Matrix4
- func NewShear(xy, xz, yx, yz, zx, zy float64) *Matrix4
- func NewTranslate(x, y, z float64) *Matrix4
- func (m *Matrix4) At(x, y int) float64
- func (m *Matrix4) Equals(n *Matrix4) bool
- func (m *Matrix4) HasInverse() bool
- func (m *Matrix4) Inverse() *Matrix4
- func (m *Matrix4) RotateX(x float64) *Matrix4
- func (m *Matrix4) RotateY(x float64) *Matrix4
- func (m *Matrix4) RotateZ(x float64) *Matrix4
- func (m *Matrix4) Scale(x, y, z float64) *Matrix4
- func (m *Matrix4) Shear(xy, xz, yx, yz, zx, zy float64) *Matrix4
- func (m *Matrix4) TimesMatrix(n *Matrix4) *Matrix4
- func (m *Matrix4) TimesPoint(p *Point) *Point
- func (m *Matrix4) TimesRay(r *Ray) *Ray
- func (m *Matrix4) TimesVector(v *Vector) *Vector
- func (m *Matrix4) Translate(x, y, z float64) *Matrix4
- func (m *Matrix4) Transpose() *Matrix4
- type Pattern
- type PerturbedPattern
- type Plane
- type Point
- func (p *Point) DividedByScalar(f float64) *Point
- func (p *Point) Equals(q *Point) bool
- func (p *Point) MinusPoint(q *Point) *Vector
- func (p *Point) MinusVector(v *Vector) *Point
- func (p *Point) PlusVector(v *Vector) *Point
- func (p *Point) TimesScalar(f float64) *Point
- func (p *Point) W() float64
- func (p *Point) X() float64
- func (p *Point) Y() float64
- func (p *Point) Z() float64
- type RadialGradientPattern
- type Ray
- type RingPattern
- type Shape
- type Shapes
- type SolidPattern
- type Sphere
- type StripePattern
- type Vector
- func (v *Vector) CrossVector(w *Vector) *Vector
- func (v *Vector) DividedByScalar(f float64) *Vector
- func (v *Vector) DotVector(w *Vector) float64
- func (v *Vector) Equals(w *Vector) bool
- func (v *Vector) Magnitude() float64
- func (v *Vector) MinusVector(w *Vector) *Vector
- func (v *Vector) Negate() *Vector
- func (v *Vector) Normalize() *Vector
- func (v *Vector) PlusVector(w *Vector) *Vector
- func (v *Vector) Reflect(w *Vector) *Vector
- func (v *Vector) TimesScalar(f float64) *Vector
- func (v *Vector) W() float64
- func (v *Vector) X() float64
- func (v *Vector) Y() float64
- func (v *Vector) Z() float64
- type World
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlendedPattern ¶
type BlendedPattern struct {
// contains filtered or unexported fields
}
BlendedPattern represents a blended pattern.
func NewBlendedPattern ¶
func NewBlendedPattern(a Pattern, b Pattern) *BlendedPattern
NewBlendedPattern constructs a new blended pattern.
func (*BlendedPattern) ColorAt ¶
func (l *BlendedPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*BlendedPattern) EqualsPattern ¶
func (l *BlendedPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*BlendedPattern) WithTransform ¶
func (l *BlendedPattern) WithTransform(t *Matrix4) *BlendedPattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Camera ¶
type Camera struct {
// contains filtered or unexported fields
}
Camera represents a camera in a scene.
func (*Camera) FieldOfView ¶
FieldOfView returns this camera's field of view.
func (*Camera) PixelSize ¶
PixelSize returns the size in world space units of a pixel on this canvas.
func (*Camera) RayForPixel ¶
RayForPixel returns a ray starting from this camera and passing through the pixel on the canvas at (x, y).
func (*Camera) WithThreads ¶
WithThreads sets the number of threads this camera uses to render the image.
func (*Camera) WithTransform ¶
WithTransform sets this camera's view transform. May return nil if the transform is invalid.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas represents a canvas.
type CheckerPattern ¶
type CheckerPattern struct {
// contains filtered or unexported fields
}
CheckerPattern represents a checker pattern.
func NewCheckerPattern ¶
func NewCheckerPattern(a Pattern, b Pattern) *CheckerPattern
NewCheckerPattern constructs a new checker pattern.
func (*CheckerPattern) ColorAt ¶
func (c *CheckerPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*CheckerPattern) EqualsPattern ¶
func (c *CheckerPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*CheckerPattern) WithTransform ¶
func (c *CheckerPattern) WithTransform(t *Matrix4) *CheckerPattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Color ¶
type Color [3]float64
Color represents a color.
func (*Color) MinusColor ¶
MinusColor returns a color representing this color minus another color.
func (*Color) TimesColor ¶
TimesColor returns this color multiplied by another color.
func (*Color) TimesScalar ¶
TimesScalar returns this color multiplied by a scalar.
type GradientPattern ¶
type GradientPattern struct {
// contains filtered or unexported fields
}
GradientPattern represents a gradient pattern.
func NewGradientPattern ¶
func NewGradientPattern(a Pattern, b Pattern) *GradientPattern
NewGradientPattern constructs a new gradient pattern.
func (*GradientPattern) ColorAt ¶
func (g *GradientPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*GradientPattern) EqualsPattern ¶
func (g *GradientPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*GradientPattern) WithTransform ¶
func (g *GradientPattern) WithTransform(t *Matrix4) *GradientPattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Intersection ¶
type Intersection struct {
// contains filtered or unexported fields
}
Intersection represents an intersection.
func NewIntersection ¶
func NewIntersection(s Shape, r *Ray, t float64) *Intersection
NewIntersection constructs a new intersection.
func (*Intersection) ComputeMetadata ¶
func (i *Intersection) ComputeMetadata()
ComputeMetadata computes and sets the metadata about this intersection.
func (*Intersection) Equals ¶
func (i *Intersection) Equals(j *Intersection) bool
Equals returns whether an intersection is approximately equal to this intersection.
func (*Intersection) Eye ¶
func (i *Intersection) Eye() *Vector
Eye returns the eye vector at this intersection. Returns nil if ComputeMetadata has not yet been called.
func (*Intersection) Inside ¶
func (i *Intersection) Inside() bool
Inside returns whether the intersection is on the inside of the shape. Returns false if ComputeMetadata has not yet been called.
func (*Intersection) Normal ¶
func (i *Intersection) Normal() *Vector
Normal returns the normal vector at this intersection. Returns nil if ComputeMetadata has not yet been called.
func (*Intersection) Point ¶
func (i *Intersection) Point() *Point
Point returns the point in world space where this intersection is. Returns nil if ComputeMetadata has not yet been called.
func (*Intersection) Ray ¶
func (i *Intersection) Ray() *Ray
Ray returns the ray used to create this intersection.
func (*Intersection) Shape ¶
func (i *Intersection) Shape() Shape
Shape returns the shape intersected with to create this intersection.
func (*Intersection) ShiftedPoint ¶
func (i *Intersection) ShiftedPoint() *Point
ShiftedPoint returns the point in world space just over actual point. Returns nil if ComputeMetadata has not yet been called.
func (*Intersection) T ¶
func (i *Intersection) T() float64
T returns the intersection point on the ray used to create this intersection.
type Intersections ¶
type Intersections []*Intersection
Intersections represents an ordered collection of intersections.
func MergeIntersections ¶
func MergeIntersections(i []Intersections) Intersections
MergeIntersections merges a collection of collections of intersections.
func NewIntersections ¶
func NewIntersections(is ...*Intersection) Intersections
NewIntersections constructs a new ordered collection of intersections.
func (Intersections) Equals ¶
func (i Intersections) Equals(j Intersections) bool
Equals returns whether a collection of intersections is approximately equal to this collection of intersections.
func (Intersections) Hit ¶
func (i Intersections) Hit() *Intersection
Hit returns the hit intersection from a collection of intersections. May return nil.
type Light ¶
type Light struct {
// contains filtered or unexported fields
}
Light represents a point light.
func (*Light) Illuminate ¶
Illuminate returns the color of a point given the shape the point is on, normal vector, eye vector, and whether it's in shadow.
type Material ¶
type Material struct {
// contains filtered or unexported fields
}
Material represents a material.
func NewDefaultMaterial ¶
func NewDefaultMaterial() *Material
NewDefaultMaterial constructs a new default material.
func NewMaterial ¶
func NewMaterial(p Pattern, ambient float64, diffuse float64, specular float64, shininess float64) *Material
NewMaterial constructs a new material.
func (*Material) Equals ¶
Equals returns whether a material is approximately equal to this material.
type Matrix2 ¶
type Matrix2 [2][2]float64
Matrix2 represents a 2x2 matrix.
func NewMatrix2 ¶
NewMatrix2 constructs a new matrix of size 2.
type Matrix3 ¶
type Matrix3 [3][3]float64
Matrix3 represents a 3x3 matrix.
func NewMatrix3 ¶
NewMatrix3 constructs a new matrix of size 3.
type Matrix4 ¶
type Matrix4 [4][4]float64
Matrix4 represents a 4x4 matrix.
func NewMatrix4 ¶
NewMatrix4 constructs a new matrix of size 4.
func NewRotateX ¶
NewRotateX returns a matrix representing a rotation around the X axis.
func NewRotateY ¶
NewRotateY returns a matrix representing a rotation around the Y axis.
func NewRotateZ ¶
NewRotateZ returns a matrix representing a rotation around the Z axis.
func NewTranslate ¶
NewTranslate returns a matrix representing a translation operation.
func (*Matrix4) HasInverse ¶
HasInverse returns whether this matrix is invertible.
func (*Matrix4) RotateX ¶
RotateX returns a matrix representing this matrix followed by a rotation around the X axis.
func (*Matrix4) RotateY ¶
RotateY returns a matrix representing this matrix followed by a rotation around the Y axis.
func (*Matrix4) RotateZ ¶
RotateZ returns a matrix representing this matrix followed by a rotation around the Z axis.
func (*Matrix4) Scale ¶
Scale returns a matrix representing this matrix followed by a scaling operation.
func (*Matrix4) Shear ¶
Shear returns a matrix representing this matrix followed by a shearing operation.
func (*Matrix4) TimesMatrix ¶
TimesMatrix returns a matrix representing this matrix multiplied by a matrix.
func (*Matrix4) TimesPoint ¶
TimesPoint returns a point representing this matrix multiplied by a point.
func (*Matrix4) TimesVector ¶
TimesVector returns a vector representing this matrix multiplied by a vector.
type Pattern ¶
type Pattern interface { // ColorAt returns the color of this pattern at a point. ColorAt(*Point) *Color // EqualsPattern returns whether this pattern is approximately equal to another pattern. EqualsPattern(Pattern) bool }
Pattern is an interface for coloriing patterns.
type PerturbedPattern ¶
type PerturbedPattern struct {
// contains filtered or unexported fields
}
PerturbedPattern represents a perturbed pattern.
func NewPerturbedPattern ¶
func NewPerturbedPattern(p Pattern, randomize bool) *PerturbedPattern
NewPerturbedPattern constructs a new perturbed pattern.
func (*PerturbedPattern) ColorAt ¶
func (e *PerturbedPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*PerturbedPattern) EqualsPattern ¶
func (e *PerturbedPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*PerturbedPattern) WithTransform ¶
func (e *PerturbedPattern) WithTransform(t *Matrix4) *PerturbedPattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Plane ¶
type Plane struct {
// contains filtered or unexported fields
}
Plane represents a plane.
func (*Plane) Intersect ¶
func (p *Plane) Intersect(r *Ray) Intersections
Intersect implements the Shape interface.
func (*Plane) Material ¶
func (s *Plane) Material() *Material
Material implements the Shape interface.
func (*Plane) WithMaterial ¶
WithMaterial sets this plane's material to a material.
func (*Plane) WithTransform ¶
WithTransform sets this plane's transform to a matrix. May return nil without setting the transform if the transform is invalid.
type Point ¶
type Point [3]float64
Point represents a point.
func (*Point) DividedByScalar ¶
DividedByScalar returns this point divided by a scalar.
func (*Point) MinusPoint ¶
MinusPoint returns a vector representing this point minus another point.
func (*Point) MinusVector ¶
MinusVector returns a point representing this point minus a vector.
func (*Point) PlusVector ¶
PlusVector returns a point representing this point plus a vector.
func (*Point) TimesScalar ¶
TimesScalar returns this point multiplied by a scalar.
type RadialGradientPattern ¶
type RadialGradientPattern struct {
// contains filtered or unexported fields
}
RadialGradientPattern represents a radial gradient pattern.
func NewRadialGradientPattern ¶
func NewRadialGradientPattern(a Pattern, b Pattern) *RadialGradientPattern
NewRadialGradientPattern constructs a new gradient pattern.
func (*RadialGradientPattern) ColorAt ¶
func (r *RadialGradientPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*RadialGradientPattern) EqualsPattern ¶
func (r *RadialGradientPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*RadialGradientPattern) WithTransform ¶
func (r *RadialGradientPattern) WithTransform(t *Matrix4) *RadialGradientPattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Ray ¶
type Ray struct {
// contains filtered or unexported fields
}
Ray represents a ray.
type RingPattern ¶
type RingPattern struct {
// contains filtered or unexported fields
}
RingPattern represents a ring pattern.
func NewRingPattern ¶
func NewRingPattern(a Pattern, b Pattern) *RingPattern
NewRingPattern constructs a new ring pattern.
func (*RingPattern) ColorAt ¶
func (r *RingPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*RingPattern) EqualsPattern ¶
func (r *RingPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*RingPattern) WithTransform ¶
func (r *RingPattern) WithTransform(t *Matrix4) *RingPattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Shape ¶
type Shape interface { // Material returns this shape's material. Material() *Material // Intersect returns this shape's intersection points with a ray. Intersect(*Ray) Intersections // ColorAt returns the color at a point on this shape. ColorAt(*Point) *Color // NormalAt returns the normal at a point on this shape. NormalAt(*Point) *Vector }
Shape is an interface for shapes.
type Shapes ¶
type Shapes []Shape
Shapes represents a collection of shapes.
func (Shapes) Intersect ¶
func (s Shapes) Intersect(r *Ray) Intersections
Intersect returns a collection of shapes' intersection points with a ray.
type SolidPattern ¶
type SolidPattern struct {
// contains filtered or unexported fields
}
SolidPattern represents a solid pattern.
func NewSolidPattern ¶
func NewSolidPattern(c *Color) *SolidPattern
NewSolidPattern constructs a new solid pattern.
func (*SolidPattern) ColorAt ¶
func (s *SolidPattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*SolidPattern) EqualsPattern ¶
func (s *SolidPattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
type Sphere ¶
type Sphere struct {
// contains filtered or unexported fields
}
Sphere represents a sphere.
func (*Sphere) Intersect ¶
func (s *Sphere) Intersect(r *Ray) Intersections
Intersect implements the Shape interface.
func (*Sphere) Material ¶
func (s *Sphere) Material() *Material
Material implements the Shape interface.
func (*Sphere) WithMaterial ¶
WithMaterial sets this sphere's material to a material.
func (*Sphere) WithTransform ¶
WithTransform sets this sphere's transform to a matrix. May return nil without setting the transform if the transform is invalid.
type StripePattern ¶
type StripePattern struct {
// contains filtered or unexported fields
}
StripePattern represents a stripe pattern in the X dimension.
func NewStripePattern ¶
func NewStripePattern(a Pattern, b Pattern) *StripePattern
NewStripePattern constructs a new stripe pattern.
func (*StripePattern) ColorAt ¶
func (s *StripePattern) ColorAt(p *Point) *Color
ColorAt implements the Pattern interface.
func (*StripePattern) EqualsPattern ¶
func (s *StripePattern) EqualsPattern(p Pattern) bool
EqualsPattern implements the Pattern interface.
func (*StripePattern) WithTransform ¶
func (s *StripePattern) WithTransform(t *Matrix4) *StripePattern
WithTransform sets this pattern's transform to a transform. May return nil without setting the transform if the transform is invalid.
type Vector ¶
type Vector [3]float64
Vector represents a vector.
func (*Vector) CrossVector ¶
CrossVector returns the cross product of this vector and another vector.
func (*Vector) DividedByScalar ¶
DividedByScalar returns this vector divided by a scalar.
func (*Vector) MinusVector ¶
MinusVector returns a vector representing this vector minus another vector.
func (*Vector) Normalize ¶
Normalize returns a vector with the same direction as this vector but with length 1.
func (*Vector) PlusVector ¶
PlusVector returns a vector representing this vector plus another vector.
func (*Vector) TimesScalar ¶
TimesScalar returns this vector multiplied by a scalar.
type World ¶
type World struct {
// contains filtered or unexported fields
}
World represents a world in a scene.
func NewDefaultWorld ¶
func NewDefaultWorld() *World
NewDefaultWorld constructs a new world with some default objects.
func (*World) Intersect ¶
func (w *World) Intersect(r *Ray) Intersections
Intersect returns this world's intersection points with a ray.
func (*World) IsShadowed ¶
IsShadowed returns whether a point in this world is in shadow relative to a light.