frame

package
v0.0.0-...-ce73456 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASCIISF

func ASCIISF(L float64) (rune, bool)

ASCIISF is the original SetFunc as described in the original implementation. Assumes L ranges from -sqrt(2) to +sqrt(2).

func Gray16Palette

func Gray16Palette() color.Palette

Gray16Palette returns 15 Gray16 colors plus a transparent color.

func Gray16SF

func Gray16SF(L float64) (color.Color, bool)

Gray16SF assumes L ranges from -sqrt(2) to +sqrt(2).

func Render

func Render(frame Frame, t Torus, s Scene)

Render renders the scene onto the frame. Assumes that the frame is sized correctly.

Types

type ASCII

type ASCII struct {
	SF SetFunc[rune]
	// contains filtered or unexported fields
}

ASCII implements the Frame interface.

func NewASCII

func NewASCII(width, height int, sf SetFunc[rune]) *ASCII

func (*ASCII) Print

func (a *ASCII) Print(w io.Writer)

func (*ASCII) Reset

func (a *ASCII) Reset()

func (*ASCII) Resize

func (a *ASCII) Resize(width int, height int)

func (*ASCII) Set

func (a *ASCII) Set(x, y int, L float64) bool

func (*ASCII) SetAll

func (a *ASCII) SetAll(r rune)

type Frame

type Frame interface {
	// Set applies a luminance value to a point in the frame.
	// If the luminance value was applied, function returns true.
	Set(x, y int, L float64) bool

	// Reset returns the frame to an initial state.
	Reset()

	Print(w io.Writer)
}

type GIF

type GIF struct {
	Image   *image.Paletted
	Options gif.Options
	SF      SetFunc[color.Color]
}

GIF implements the Frame interface.

func (*GIF) Print

func (g *GIF) Print(w io.Writer)

func (*GIF) Reset

func (g *GIF) Reset()

Reset sets all pixels to the first item in the Palette.

func (*GIF) Set

func (g *GIF) Set(x, y int, L float64) bool

type Scene

type Scene struct {
	// Dimensions of the viewport.
	Width, Height int

	// Distance from camera to viewport.
	K1 float64

	// Distance from camera to torus. Essentially equal to TZ since camera is at origin.
	K2 float64

	// Light source vector. Technically should be normalized, but up to the implementation.
	LX, LY, LZ float64
}

Scene contains locations and properties of the scene.

func (*Scene) CalculateK1

func (s *Scene) CalculateK1(R1, R2 float64)

CalculateK1 is optional. Automatically sets K1 such that the given torus stays within the screen.

type SetFunc

type SetFunc[T any] func(L float64) (T, bool)

type Torus

type Torus struct {
	// Controls the resolution of the cross-sectional circle.
	ThetaSpacing float64

	// Controls the resolution of the revolution of the circle.
	PhiSpacing float64

	// Radius of the cross-sectional circle.
	R1 float64

	// Distance from axis of revolution (Y) to the center of the cross-sectional circle.
	R2 float64

	// Rotation of the torus along the X and Z axes.
	A, B float64
}

Torus contains properties of the torus to be rendered.

func DefaultTorus

func DefaultTorus() Torus

Jump to

Keyboard shortcuts

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