wire

package module
v0.2.34 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

wire

wire is a niche 3d modeling and rendering library written in Go.

Dependencies

Direct dependencies are two other Go libraries I've been working on for some years:

Concept

wire models are made of 3d points and, optionally, segments, which connect two points.

A wire model can be rendered as 3d paths (wires) formed by stroking all the segments, or as a 3d point cloud by rendering all of the points. Or both.

Constraints

So many constraints!

  • No triangles/polygons/filled surfaces,solid objects
  • No z-sorting
  • No normals
  • No shaders
  • No backface culling

Due to some of these constraints, monochromatic images and animations tend to work best. A secondary constraint.

That said, these constraints make space for a good amount of creativity in multiple styles.

Features

  • A decent set of 3d primitives:
    • Sphere
    • Circle
    • Cylinder
    • Cone
    • Box
    • Pyramid
    • Torus
    • Torus knot
    • GridPlane
    • Spring
    • Text
  • Where it makes sense, most of these can be rendered as:
    • Wireframe, with configurable longitudinal and latitudinal sections
    • Random points on the surface
    • Random points filling the object
  • Objects can be:
    • Transformed: rotated, translated, scaled, or manually manipulated with custom functions
    • Cloned
    • Combined
    • Point-culled with custom functions
    • Subdivided
    • Randomized
    • Noisified (Simplex noise)

Examples

See: https://www.artfromcode.com/tags/wire/ for some examples of what is possible.

Documentation

Overview

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Package wire implements wireframe 3d shapes.

Index

Constants

This section is empty.

Variables

View Source
var FontArcade = FontType{
	// contains filtered or unexported fields
}

FontArcade is the path data for this font. adapted from https://github.com/coolbutuseless/arcadefont/blob/master/data-raw/create-arcade-font.R with some changes.

View Source
var FontAsteroid = FontType{
	// contains filtered or unexported fields
}

FontAsteroid is the path data for this font. adapted from https://github.com/osresearch/vst/blob/master/teensyv/asteroids_font.c with some changes.

Functions

func ApplyFog

func ApplyFog(objectZ float64)

ApplyFog returns the amount of fog to apply for the given object z.

func CirclePath

func CirclePath(radius float64, res int) (PointList, []*Segment)

CirclePath creates a single path defining a circle.

func GetRGB

func GetRGB() (float64, float64, float64)

GetRGB returns the current drawing color.

func InitWorld

func InitWorld(context Context, cx, cy, cz float64)

InitWorld initializes the world.

func SetCenter

func SetCenter(x, y, z float64)

SetCenter sets the center of the 3d world.

func SetClipping

func SetClipping(near, far float64)

SetClipping sets the near and far limits of rendering.

func SetFog

func SetFog(active bool, near, far float64)

SetFog sets the fog parameters, including turning on and off.

func SetFont

func SetFont(font FontType, size, spacing float64)

SetFont sets the font type, size and spacing for future text objects. Size is the width of a single letter. Default 100. Spacing is the space between letters, as a percentage of letter width. Defaults to 0.2.

func SetFontSize

func SetFontSize(size float64)

SetFontSize sets the font size (width of one letter) used for future text objects. Default is 100.

func SetFontSpacing

func SetFontSpacing(spacing float64)

SetFontSpacing sets the spacing between letters, as a percentage of letter width. Default is 0.2.

func SetFontType

func SetFontType(font FontType)

SetFontType sets which font type will be used for future text objects. Default is wire.FontAsteroid.

func SetPerspective

func SetPerspective(fl float64)

SetPerspective sets the amount of perspective to apply.

func SetRGB

func SetRGB(r, g, b float64)

SetRGB sets the drawing color.

Types

type Context

type Context interface {
	StrokePath(geom.PointList, bool)
	FillCircle(float64, float64, float64)
	MoveTo(float64, float64)
	LineTo(float64, float64)
	Stroke()
	ClosePath()
	SetLineWidth(float64)
	GetLineWidth() float64
	Save()
	Restore()
	SetSourceColor(blcolor.Color)
	GetSourceRGB() (float64, float64, float64)
}

Context interface to allow for drawing functions. The interface defines only the used methods of cairo.Context. This is needed to avoid recursive dependencies between wire and cairo.

type FontType

type FontType = struct {
	// contains filtered or unexported fields
}

FontType is a struct holding the font data.

type Lure3d added in v0.2.4

type Lure3d interface {
	GetScale() float64
	InitVals3d() (float64, float64, float64)
	Center3d() (float64, float64, float64)
	Iterate(x, y, z float64) (float64, float64, float64)
}

Lure3d is an interface for a 3d attractor. Included here to decouple the concrete lures library and avoid a direct dependecy.

type Point

type Point struct {
	X, Y, Z         float64
	Px, Py, Scaling float64
}

Point is a 3d point.

func LerpPoint

func LerpPoint(t float64, p0, p1 *Point) *Point

LerpPoint creates a new 3d point interpolated from the two given points.

func NewPoint

func NewPoint(x, y, z float64) *Point

NewPoint creates a new 3d point.

func RandomPointInBox

func RandomPointInBox(w, h, d float64) *Point

RandomPointInBox creates a new 3d point within a 3d box of the given dimensions. The box is centered on the origin, so points will range from -w/2 to w/2, etc. on each dimension.

func RandomPointInCircle

func RandomPointInCircle(radius float64) *Point

RandomPointInCircle returns a random 3d point in a circle. The y-coordinate will be 0.

func RandomPointInCylinder

func RandomPointInCylinder(height, radius float64) *Point

RandomPointInCylinder creates a random 3d point IN a cylinder of the given radius and height.

func RandomPointInRectangle

func RandomPointInRectangle(w, d float64) *Point

RandomPointInRectangle returns a random 3d point in a rectangle. The rectangle will be centered at the origin, with the y-coordinate at 0.

func RandomPointInSphere

func RandomPointInSphere(radius float64) *Point

RandomPointInSphere creates a random 3d point IN a sphere of the given radius. https://mathworld.wolfram.com/SpherePointPicking.html Main change from the on-surface version is radius is randomized. It uses a distribution of 1/3 which evenly distributes the points throughout the sphere.

func RandomPointInSphereDist

func RandomPointInSphereDist(radius, dist float64) *Point

RandomPointInSphereDist creates a random 3d point IN a sphere of the given radius. https://mathworld.wolfram.com/SpherePointPicking.html The dist value lets you adjust the distribution of points. A value of 3 will result in a completely even distribution of points throughout the sphere. Lower values will concentrate points in the center of the sphere and higher values will send them to the edges.

func RandomPointInTorus

func RandomPointInTorus(radius1, radius2, arc float64) *Point

RandomPointInTorus creates a random 3d point IN a torus. radius1 is from the center of the torus to the center of the circle forming the torus. radius2 is the radius of the circle forming the torus.

func RandomPointOnBox

func RandomPointOnBox(w, h, d float64) *Point

RandomPointOnBox creates a new random point on the surface of a box.

func RandomPointOnCylinder

func RandomPointOnCylinder(height, radius float64, includeCaps bool) *Point

RandomPointOnCylinder creates a random 3d point ON a cylinder of the given radius and height. Can optionally include the caps on not.

func RandomPointOnSphere

func RandomPointOnSphere(radius float64) *Point

RandomPointOnSphere creates a random 3d point ON a sphere of the given radius. https://mathworld.wolfram.com/SpherePointPicking.html

func RandomPointOnTorus

func RandomPointOnTorus(radius1, radius2, arc float64) *Point

RandomPointOnTorus creates a random 3d point ON a torus. radius1 is from the center of the torus to the center of the circle forming the torus. radius2 is the radius of the circle forming the torus.

func (*Point) Clone

func (p *Point) Clone() *Point

Clone returns a copy of this point.

func (*Point) Distance

func (p *Point) Distance(other *Point) float64

Distance returns the distance from this point to another point.

func (*Point) Lerp

func (p *Point) Lerp(t float64, p1 *Point)

Lerp interpolates this point to another point, in place.

func (*Point) Magnitude added in v0.2.4

func (p *Point) Magnitude() float64

Magnitude returns the distance from the origin to this point.

func (*Point) Normalize added in v0.2.4

func (p *Point) Normalize()

Normalize normalizes each component ofthis point, in place.

func (*Point) Normalized added in v0.2.4

func (p *Point) Normalized() *Point

Normalized returns a copy of this point, normalized.

func (*Point) Project

func (p *Point) Project()

Project projects this 3d point to a 2d point, by setting the Px, Py and Scaling properties of this point.

func (*Point) Randomize

func (p *Point) Randomize(amount float64)

Randomize randomizes this point on all axes, in place.

func (*Point) RandomizeX

func (p *Point) RandomizeX(amount float64)

RandomizeX randomizes this point on the x-axis, in place.

func (*Point) RandomizeY

func (p *Point) RandomizeY(amount float64)

RandomizeY randomizes this point on the y-axis, in place.

func (*Point) RandomizeZ

func (p *Point) RandomizeZ(amount float64)

RandomizeZ randomizes this point on the z-axis, in place.

func (*Point) Randomized

func (p *Point) Randomized(amount float64) *Point

Randomized returns a copy of this point, randomized on all axes.

func (*Point) RandomizedX

func (p *Point) RandomizedX(amount float64) *Point

RandomizedX returns a copy of this point, randomized on the x-axis.

func (*Point) RandomizedY

func (p *Point) RandomizedY(amount float64) *Point

RandomizedY returns a copy of this point, randomized on the y-axis.

func (*Point) RandomizedZ

func (p *Point) RandomizedZ(amount float64) *Point

RandomizedZ returns a copy of this point, randomized on the z-axis.

func (*Point) Rotate

func (p *Point) Rotate(rx, ry, rz float64)

Rotate rotates this point around all axes, in place.

func (*Point) RotateX

func (p *Point) RotateX(angle float64)

RotateX rotates this point around the x-axis, in place.

func (*Point) RotateY

func (p *Point) RotateY(angle float64)

RotateY rotates this point around the y-axis, in place.

func (*Point) RotateZ

func (p *Point) RotateZ(angle float64)

RotateZ rotates this point around the z-axis, in place.

func (*Point) Rotated

func (p *Point) Rotated(rx, ry, rz float64) *Point

Rotated returns a copy of this point, rotated around all axes.

func (*Point) RotatedX

func (p *Point) RotatedX(angle float64) *Point

RotatedX returns a copy of this point, rotated on the x-axis.

func (*Point) RotatedY

func (p *Point) RotatedY(angle float64) *Point

RotatedY returns a copy of this point, rotated on the y-axis.

func (*Point) RotatedZ

func (p *Point) RotatedZ(angle float64) *Point

RotatedZ returns a copy of this point, rotated on the z-axis.

func (*Point) Scale

func (p *Point) Scale(sx, sy, sz float64)

Scale scales this point on all axes, in place.

func (*Point) ScaleX

func (p *Point) ScaleX(scale float64)

ScaleX scales this point on the x-axis, in place.

func (*Point) ScaleY

func (p *Point) ScaleY(scale float64)

ScaleY scales this point on the y-axis, in place.

func (*Point) ScaleZ

func (p *Point) ScaleZ(scale float64)

ScaleZ scales this point on the z-axis, in place.

func (*Point) Scaled

func (p *Point) Scaled(sx, sy, sz float64) *Point

Scaled returns a copy of this point, scaled on all axes.

func (*Point) ScaledX

func (p *Point) ScaledX(scale float64) *Point

ScaledX returns a copy of this point, scaled on the x-axis.

func (*Point) ScaledY

func (p *Point) ScaledY(scale float64) *Point

ScaledY returns a copy of this point, scaled on the y-axis.

func (*Point) ScaledZ

func (p *Point) ScaledZ(scale float64) *Point

ScaledZ returns a copy of this point, scaled on the z-axis.

func (*Point) Translate

func (p *Point) Translate(tx, ty, tz float64)

Translate translates this point on all three axes, in place.

func (*Point) TranslateX

func (p *Point) TranslateX(tx float64)

TranslateX translates this point on the x-axis, in place.

func (*Point) TranslateY

func (p *Point) TranslateY(ty float64)

TranslateY translates this point on the y-axis, in place.

func (*Point) TranslateZ

func (p *Point) TranslateZ(tz float64)

TranslateZ translates this point on the z-axis, in place.

func (*Point) Translated

func (p *Point) Translated(tx, ty, tz float64) *Point

Translated returns a copy of this point, translated on all axes.

func (*Point) TranslatedX

func (p *Point) TranslatedX(tx float64) *Point

TranslatedX returns a copy of this point, translated on the x-axis.

func (*Point) TranslatedY

func (p *Point) TranslatedY(ty float64) *Point

TranslatedY returns a copy of this point, translated on the y-axis.

func (*Point) TranslatedZ

func (p *Point) TranslatedZ(tz float64) *Point

TranslatedZ returns a copy of this point, translated on the z-axis.

func (*Point) UniScale

func (p *Point) UniScale(scale float64)

UniScale scales this point by the same amount on each axis, in place.

func (*Point) UniScaled

func (p *Point) UniScaled(scale float64) *Point

UniScaled returns a copy of this point, scaled by the same amount on each axis.

func (*Point) Visible

func (p *Point) Visible() bool

Visible returns whether or not a point should be visible.

type PointList

type PointList []*Point

PointList represents a list of 3d points.

func NewPointList

func NewPointList() PointList

NewPointList creates a new PointList.

func (*PointList) Add

func (p *PointList) Add(point *Point)

Add adds a new point to this list.

func (*PointList) AddRandomPointInBox

func (p *PointList) AddRandomPointInBox(w, h, d float64)

AddRandomPointInBox creates and adds a new 3d point within a 3d box of the given dimensions. The box is centered on the origin, so points will range from -w/2 to w/2, etc. on each dimension.

func (*PointList) AddRandomPointInCylinder

func (p *PointList) AddRandomPointInCylinder(height, radius float64)

AddRandomPointInCylinder creates and adds a random 3d point IN a cylinder of the given radius and height.

func (*PointList) AddRandomPointInSphere

func (p *PointList) AddRandomPointInSphere(radius float64)

AddRandomPointInSphere creates and adds a random 3d point IN a sphere of the given radius.

func (*PointList) AddRandomPointInTorus

func (p *PointList) AddRandomPointInTorus(radius1, radius2 float64)

AddRandomPointInTorus creates and adds a random 3d point IN a torus. radius1 is from the center of the torus to the center of the circle forming the torus. radius2 is the radius of the circle forming the torus.

func (*PointList) AddRandomPointOnBox

func (p *PointList) AddRandomPointOnBox(w, h, d float64)

AddRandomPointOnBox creates and adds a new 3d point on the surface of a 3d box of the given dimensions. The box is centered on the origin, so points will range from -w/2 to w/2, etc. on each dimension.

func (*PointList) AddRandomPointOnCylinder

func (p *PointList) AddRandomPointOnCylinder(height, radius float64, includeCaps bool)

AddRandomPointOnCylinder creates and adds a random 3d point ON a cylinder of the given radius and height.

func (*PointList) AddRandomPointOnSphere

func (p *PointList) AddRandomPointOnSphere(radius float64)

AddRandomPointOnSphere creates and adds a random 3d point ON a sphere of the given radius.

func (*PointList) AddRandomPointOnTorus

func (p *PointList) AddRandomPointOnTorus(radius1, radius2 float64)

AddRandomPointOnTorus creates and adds a random 3d point ON a torus. radius1 is from the center of the torus to the center of the circle forming the torus. radius2 is the radius of the circle forming the torus.

func (*PointList) AddXYZ

func (p *PointList) AddXYZ(x, y, z float64)

AddXYZ creates and adds a new point to this list.

func (PointList) Clone

func (p PointList) Clone() PointList

Clone returns a deep copy of this pointlist.

func (*PointList) Cull

func (p *PointList) Cull(cullFunc func(*Point) bool)

Cull removes points from the list that do not satisfy the cull function. Modifies list in place.

func (*PointList) CullBox

func (p *PointList) CullBox(minX, minY, minZ, maxX, maxY, maxZ float64)

CullBox removes points that ar not within the defined box. Modifies the shape in place.

func (PointList) Culled

func (p PointList) Culled(cullFunc func(*Point) bool) PointList

Culled returns a new point list with points removed that do not satisfy the cull function.

func (PointList) First

func (p PointList) First() *Point

First returns the first point in the list.

func (PointList) Get

func (p PointList) Get(index int) *Point

Get returns the point at the given index. Negative indexes go in reverse from end.

func (PointList) Last

func (p PointList) Last() *Point

Last returns the last point in the list.

func (PointList) Lerp

func (p PointList) Lerp(t float64, other PointList)

Lerp interpolates thispoint list towards another, in place. Thus, it should maintain segment relationships.

func (PointList) Noisify

func (p PointList) Noisify(origin *Point, scale, offset float64)

Noisify scales a point based on its postion in a 3d simplex noise field.

func (PointList) Normalize added in v0.2.4

func (p PointList) Normalize()

Normalize normalizes all the points in this list.

func (PointList) Normalized added in v0.2.4

func (p PointList) Normalized() PointList

Normalized returns a copy of this list, normalized.

func (PointList) Project

func (p PointList) Project()

Project projects this 3d point list to a 2d point list. This returns a list of 2d points as well as a list of scale values for each point.

func (PointList) Push

func (p PointList) Push(pusher *Point, radius float64)

Push pushes points away from the specified point.

func (PointList) Randomize

func (p PointList) Randomize(amount float64)

Randomize randomizes each point in this pointlist on all axes, in place.

func (PointList) RandomizeX

func (p PointList) RandomizeX(amount float64)

RandomizeX randomizes each point in this pointlist on the x-axis, in place.

func (PointList) RandomizeY

func (p PointList) RandomizeY(amount float64)

RandomizeY randomizes each point in this pointlist on the y-axis, in place.

func (PointList) RandomizeZ

func (p PointList) RandomizeZ(amount float64)

RandomizeZ randomizes each point in this pointlist on the z-axis, in place.

func (PointList) Randomized

func (p PointList) Randomized(amount float64) PointList

Randomized returns a copy of this pointlist, randomized on all axes.

func (PointList) RandomizedX

func (p PointList) RandomizedX(amount float64) PointList

RandomizedX returns a copy of this pointlist, randomized on the x-axis

func (PointList) RandomizedY

func (p PointList) RandomizedY(amount float64) PointList

RandomizedY returns a copy of this pointlist, randomized on the y-axis

func (PointList) RandomizedZ

func (p PointList) RandomizedZ(amount float64) PointList

RandomizedZ returns a copy of this pointlist, randomized on the z-axis

func (PointList) RenderPoints

func (p PointList) RenderPoints(radius float64)

RenderPoints projects and draws a circle for each point in the list.

func (PointList) Rotate

func (p PointList) Rotate(rx, ry, rz float64)

Rotate rotates each point in this pointlist around all axes, in place.

func (PointList) RotateX

func (p PointList) RotateX(angle float64)

RotateX rotates each point in this pointlist around the x-axis, in place.

func (PointList) RotateY

func (p PointList) RotateY(angle float64)

RotateY rotates each point in this pointlist around the y-axis, in place.

func (PointList) RotateZ

func (p PointList) RotateZ(angle float64)

RotateZ rotates each point in this pointlist around the z-axis, in place.

func (PointList) Rotated

func (p PointList) Rotated(rx, ry, rz float64) PointList

Rotated returns a copy of this pointlist, rotated on all axes.

func (PointList) RotatedX

func (p PointList) RotatedX(angle float64) PointList

RotatedX returns a copy of this pointlist, rotated on the x-axis.

func (PointList) RotatedY

func (p PointList) RotatedY(angle float64) PointList

RotatedY returns a copy of this pointlist, rotated on the y-axis.

func (PointList) RotatedZ

func (p PointList) RotatedZ(angle float64) PointList

RotatedZ returns a copy of this pointlist, rotated on the z-axis.

func (PointList) Scale

func (p PointList) Scale(sx, sy, sz float64)

Scale scales each point in this pointlist on all axes, in place.

func (PointList) ScaleX

func (p PointList) ScaleX(scale float64)

ScaleX scales each point in this pointlist on the x-axis, in place.

func (PointList) ScaleY

func (p PointList) ScaleY(scale float64)

ScaleY scales each point in this pointlist on the y-axis, in place.

func (PointList) ScaleZ

func (p PointList) ScaleZ(scale float64)

ScaleZ scales each point in this pointlist on the z-axis, in place.

func (PointList) Scaled

func (p PointList) Scaled(sx, sy, sz float64) PointList

Scaled returns a copy of this pointlist, scaled on all axes.

func (PointList) ScaledX

func (p PointList) ScaledX(scale float64) PointList

ScaledX returns a copy of this pointlist, scaled on the x-axis.

func (PointList) ScaledY

func (p PointList) ScaledY(scale float64) PointList

ScaledY returns a copy of this pointlist, scaled on the y-axis.

func (PointList) ScaledZ

func (p PointList) ScaledZ(scale float64) PointList

ScaledZ returns a copy of this pointlist, scaled on the z-axis.

func (*PointList) SortX added in v0.2.3

func (p *PointList) SortX(ascending bool)

SortX sorts the point list by x value.

func (*PointList) SortY added in v0.2.3

func (p *PointList) SortY(ascending bool)

SortY sorts the point list by y value.

func (*PointList) SortZ added in v0.2.3

func (p *PointList) SortZ(ascending bool)

SortZ sorts the point list by z value.

func (PointList) Translate

func (p PointList) Translate(tx, ty, tz float64)

Translate translates each point in this pointlist on all axes, in place.

func (PointList) TranslateX

func (p PointList) TranslateX(tx float64)

TranslateX translates each point in this pointlist on the x-axis, in place.

func (PointList) TranslateY

func (p PointList) TranslateY(ty float64)

TranslateY translates each point in this pointlist on the y-axis, in place.

func (PointList) TranslateZ

func (p PointList) TranslateZ(tz float64)

TranslateZ translates each point in this pointlist on the z-axis, in place.

func (PointList) Translated

func (p PointList) Translated(tx, ty, tz float64) PointList

Translated returns a copy of this pointlist, translated on all axes.

func (*PointList) TranslatedX

func (p *PointList) TranslatedX(tx float64) PointList

TranslatedX returns a copy of this pointlist, translated on the x-axis.

func (*PointList) TranslatedY

func (p *PointList) TranslatedY(ty float64) PointList

TranslatedY returns a copy of this pointlist, translated on the y-axis.

func (*PointList) TranslatedZ

func (p *PointList) TranslatedZ(tz float64) PointList

TranslatedZ returns a copy of this pointlist, translated on the z-axis.

func (PointList) UniScale

func (p PointList) UniScale(scale float64)

UniScale scales each point in this pointlist by the same amount on each axis, in place.

func (PointList) UniScaled

func (p PointList) UniScaled(scale float64) PointList

UniScaled returns a copy of this pointlist, scaled by the same amount on each axis.

type Segment

type Segment struct {
	PointA, PointB *Point
}

Segment represents a line segment between two points.

func NewSegment

func NewSegment(a, b *Point) *Segment

NewSegment creates a new segment from two points.

func (*Segment) Length

func (s *Segment) Length() float64

Length returns the length of this segment.

func (*Segment) Stroke

func (s *Segment) Stroke(width float64)

Stroke draws a line between the two points of this segment.

type Shape

type Shape struct {
	Points   PointList
	Segments []*Segment
}

Shape is a 3d shape composed of a list of points and segments connecting them.

func Box

func Box(w, h, d float64) *Shape

Box creates a 3d box shape.

func Circle

func Circle(radius float64, res int) *Shape

Circle creates a 3d cone shape made of a number of circular slices.

func Cone

func Cone(height, radius0, radius1 float64, slices, res int, showSlices, showLong bool) *Shape

Cone creates a 3d cone shape made of a number of circular slices.

func Cylinder

func Cylinder(height, radius float64, slices, res int, showSlices, showLong bool) *Shape

Cylinder creates a 3d cylinder shape made of a number of circular slices.

func GridPlane

func GridPlane(w, d float64, rows, cols int) *Shape

GridPlane creates a 3d plane containing a grid.

func NewShape

func NewShape() *Shape

NewShape creates a new shape.

func ParseChar

func ParseChar(char string, fontData FontType) *Shape

ParseChar parses a single character into a single 3d shape. The font data is initially sized from -1 to +1 on the x-axis. Height will depend on the font. Each character is scaled to 100 units wide on creation (-50 to +50). The string shape can be scaled further later.

func Pyramid

func Pyramid(height, baseRadius float64, sides int) *Shape

Pyramid creates a 3d pyramid shape.

func RandomInnerBox

func RandomInnerBox(w, h, d float64, count int) *Shape

RandomInnerBox creates a 3d box filled with random points.

func RandomInnerCylinder

func RandomInnerCylinder(height, radius float64, count int) *Shape

RandomInnerCylinder creates a 3d cylinder made of random point inside the cylinder.

func RandomInnerSphere

func RandomInnerSphere(radius float64, count int) *Shape

RandomInnerSphere creates a 3d sphere made of random points inside the sphere.

func RandomInnerTorus

func RandomInnerTorus(radius1, radius2, arc float64, count int) *Shape

RandomInnerTorus creates a 3d torus made of random point inside the torus.

func RandomSurfaceBox

func RandomSurfaceBox(w, h, d float64, count int) *Shape

RandomSurfaceBox creates a 3d box made of random points on the surface of the box.

func RandomSurfaceCylinder

func RandomSurfaceCylinder(height, radius float64, count int, includeCaps bool) *Shape

RandomSurfaceCylinder creates a 3d cylinder made of random point on the surface of the cylinder.

func RandomSurfaceSphere

func RandomSurfaceSphere(radius float64, count int) *Shape

RandomSurfaceSphere creates a 3d sphere made of random points on the surface of the sphere.

func RandomSurfaceTorus

func RandomSurfaceTorus(radius1, radius2, arc float64, count int) *Shape

RandomSurfaceTorus creates a 3d torus made of random point on the surface of the torus.

func ShapeFrom2dPath

func ShapeFrom2dPath(path geom.PointList, closed bool) *Shape

ShapeFrom2dPath creates a shape from a geom.PointList.

func ShapeFromLure added in v0.2.4

func ShapeFromLure(lure Lure3d, count int) *Shape

ShapeFromLure creates a shape filled with points forming a strange attractor.

func ShapeFromXYZ

func ShapeFromXYZ(fileName string) *Shape

ShapeFromXYZ creates a new point-only shape from an .xyz formatted point cloud file.

func Sphere

func Sphere(radius float64, long, lat int, showLong, showLat bool) *Shape

Sphere creates a 3d sphere of regular points that can be connected longitudinally, lattitudally, or both.

func Spring

func Spring(height, r0, r1, turns, res float64) *Shape

Spring creates a 3d spiral shape.

func Torus

func Torus(r1, r2, arc float64, slices, res int, showSlices, showLong bool) *Shape

Torus creates a 3d torus made of a number of circular slices.

func TorusKnot

func TorusKnot(p, q, r1, r2, res float64) *Shape

TorusKnot creates a 3d torus knot shape made of one long path that wraps around the torus.

func (*Shape) AddPoint

func (s *Shape) AddPoint(point *Point)

AddPoint adds a point to the shape.

func (*Shape) AddRandomPointInBox

func (s *Shape) AddRandomPointInBox(w, h, d float64)

AddRandomPointInBox creates and adds a new 3d point within a 3d box of the given dimensions. The box is centered on the origin, so points will range from -w/2 to w/2, etc. on each dimension.

func (*Shape) AddRandomPointInCylinder

func (s *Shape) AddRandomPointInCylinder(height, radius float64)

AddRandomPointInCylinder creates and adds a random 3d point IN a cylinder of the given radius and height.

func (*Shape) AddRandomPointInSphere

func (s *Shape) AddRandomPointInSphere(radius float64)

AddRandomPointInSphere creates and adds a random 3d point IN a sphere of the given radius.

func (*Shape) AddRandomPointInTorus

func (s *Shape) AddRandomPointInTorus(radius1, radius2, arc float64)

AddRandomPointInTorus creates and adds a random 3d point IN a torus. radius1 is from the center of the torus to the center of the circle forming the torus. radius2 is the radius of the circle forming the torus.

func (*Shape) AddRandomPointOnBox

func (s *Shape) AddRandomPointOnBox(w, h, d float64)

AddRandomPointOnBox creates and adds a new 3d point on the surface of a 3d box of the given dimensions. The box is centered on the origin, so points will range from -w/2 to w/2, etc. on each dimension.

func (*Shape) AddRandomPointOnCylinder

func (s *Shape) AddRandomPointOnCylinder(height, radius float64, includeCaps bool)

AddRandomPointOnCylinder creates and adds a random 3d point ON a cylinder of the given radius and height.

func (*Shape) AddRandomPointOnSphere

func (s *Shape) AddRandomPointOnSphere(radius float64)

AddRandomPointOnSphere creates and adds a random 3d point ON a sphere of the given radius.

func (*Shape) AddRandomPointOnTorus

func (s *Shape) AddRandomPointOnTorus(radius1, radius2, arc float64)

AddRandomPointOnTorus creates and adds a random 3d point ON a torus. radius1 is from the center of the torus to the center of the circle forming the torus. radius2 is the radius of the circle forming the torus.

func (*Shape) AddSegment

func (s *Shape) AddSegment(seg *Segment)

AddSegment adds a new segment.

func (*Shape) AddSegmentByIndex

func (s *Shape) AddSegmentByIndex(a, b int)

AddSegmentByIndex adds a new segment based on the indexes of the two points passed.

func (*Shape) AddSegmentByPoints

func (s *Shape) AddSegmentByPoints(a, b *Point)

AddSegmentByPoints adds a new segment based on the two points passed.

func (*Shape) AddShape

func (s *Shape) AddShape(shape *Shape)

AddShape adds the points and segments of another shape to this shape. Does not clone the original shape, so transforms to this shape will affect the added shape as well.

func (*Shape) AddXYZ

func (s *Shape) AddXYZ(x, y, z float64)

AddXYZ adds a point to the shape.

func (*Shape) Clone

func (s *Shape) Clone() *Shape

Clone returns a deep copy of this shape.

func (*Shape) Cull

func (s *Shape) Cull(cullFunc func(*Point) bool)

Cull removes points from the shape that do not satisfy the cull function. Modifies shape in place.

func (*Shape) CullBox

func (s *Shape) CullBox(minX, minY, minZ, maxX, maxY, maxZ float64)

CullBox removes points that ar not within the defined box. Modifies the shape in place. TODO: cull segments not just points

func (*Shape) Culled

func (s *Shape) Culled(cullFunc func(*Point) bool) *Shape

Culled returns a new shape with points removed that do not satisfy the cull function.

func (*Shape) Randomize

func (s *Shape) Randomize(amount float64)

Randomize randomizes this shape on all axes, in place.

func (*Shape) RandomizeX

func (s *Shape) RandomizeX(amount float64)

RandomizeX randomizes this shape on the x-axis, in place.

func (*Shape) RandomizeY

func (s *Shape) RandomizeY(amount float64)

RandomizeY randomizes this shape on the y-axis, in place.

func (*Shape) RandomizeZ

func (s *Shape) RandomizeZ(amount float64)

RandomizeZ randmizes this shape on the z-axis, in place.

func (*Shape) Randomized

func (s *Shape) Randomized(amount float64) *Shape

Randomized returns a copy of this shape, randomized on all axes.

func (*Shape) RandomizedX

func (s *Shape) RandomizedX(amount float64) *Shape

RandomizedX returns a copy of this shape, randomized on the x-axis.

func (*Shape) RandomizedY

func (s *Shape) RandomizedY(amount float64) *Shape

RandomizedY returns a copy of this shape, randomized on the y-axis.

func (*Shape) RandomizedZ

func (s *Shape) RandomizedZ(amount float64) *Shape

RandomizedZ returns a copy of this shape, randomized on the z-axis.

func (*Shape) RemoveSegment

func (s *Shape) RemoveSegment(seg *Segment)

RemoveSegment removes the given segment from the shape's segment list.

func (*Shape) RenderPoints

func (s *Shape) RenderPoints(radius float64)

RenderPoints draws a filled circle for each point in the path.

func (*Shape) Rotate

func (s *Shape) Rotate(rx, ry, rz float64)

Rotate rotates this shape around all axes, in place.

func (*Shape) RotateX

func (s *Shape) RotateX(angle float64)

RotateX rotates this shape around the x-axis, in place.

func (*Shape) RotateY

func (s *Shape) RotateY(angle float64)

RotateY rotates this shape around the y-axis, in place.

func (*Shape) RotateZ

func (s *Shape) RotateZ(angle float64)

RotateZ rotates this shape around the z-axis, in place.

func (*Shape) Rotated

func (s *Shape) Rotated(rx, ry, rz float64) *Shape

Rotated returns a copy of this shape, rotated on all axes.

func (*Shape) RotatedX

func (s *Shape) RotatedX(angle float64) *Shape

RotatedX returns a copy of this shape, rotated on the x-axis.

func (*Shape) RotatedY

func (s *Shape) RotatedY(angle float64) *Shape

RotatedY returns a copy of this shape, rotated on the y-axis.

func (*Shape) RotatedZ

func (s *Shape) RotatedZ(angle float64) *Shape

RotatedZ returns a copy of this shape, rotated on the z-axis.

func (*Shape) Scale

func (s *Shape) Scale(sx, sy, sz float64)

Scale scales this shape on all axes, in place.

func (*Shape) ScaleX

func (s *Shape) ScaleX(scale float64)

ScaleX scales this shape on the x-axis, in place.

func (*Shape) ScaleY

func (s *Shape) ScaleY(scale float64)

ScaleY scales this shape on the y-axis, in place.

func (*Shape) ScaleZ

func (s *Shape) ScaleZ(scale float64)

ScaleZ scales this shape on the z-axis, in place.

func (*Shape) Scaled

func (s *Shape) Scaled(sx, sy, sz float64) *Shape

Scaled returns a copy of this shape, scaled on all axes.

func (*Shape) ScaledX

func (s *Shape) ScaledX(scale float64) *Shape

ScaledX returns a copy of this shape, scaled on the x-axis.

func (*Shape) ScaledY

func (s *Shape) ScaledY(scale float64) *Shape

ScaledY returns a copy of this shape, scaled on the y-axis.

func (*Shape) ScaledZ

func (s *Shape) ScaledZ(scale float64) *Shape

ScaledZ returns a copy of this shape, scaled on the z-axis.

func (*Shape) Split added in v0.2.3

func (s *Shape) Split(split func(p *Point) bool) *Shape

Split culls points that satisfy the split function, then adds those points to a new shape and returns that. TODO: handle segments

func (*Shape) Stroke

func (s *Shape) Stroke(width float64)

Stroke strokes each path in a shape.

func (*Shape) Subdivide

func (s *Shape) Subdivide(maxDist float64)

Subdivide subdivides segments so that no segment is longer than maxDist.

func (*Shape) ThinPoints

func (s *Shape) ThinPoints(take, skip int)

ThinPoints is used to thin out a dense model. It will keep `take` number of points, and then discard `skip` number of points, repeating until all points are processed. To thin by 25% use ThinPoints(3, 1). To thin by 75%, ThinPoints(1, 3). TODO: remove invalidated segments.

func (*Shape) Translate

func (s *Shape) Translate(tx, ty, tz float64)

Translate translates this shape on all axes, in place.

func (*Shape) TranslateX

func (s *Shape) TranslateX(tx float64)

TranslateX translates this shape on the x-axis, in place.

func (*Shape) TranslateY

func (s *Shape) TranslateY(ty float64)

TranslateY translates this shape on the y-axis, in place.

func (*Shape) TranslateZ

func (s *Shape) TranslateZ(tz float64)

TranslateZ translates this shape on the z-axis, in place.

func (*Shape) Translated

func (s *Shape) Translated(tx, ty, tz float64) *Shape

Translated returns a copy of this shape, translated on all axes.

func (*Shape) TranslatedX

func (s *Shape) TranslatedX(tx float64) *Shape

TranslatedX returns a copy of this shape, translated on the x-axis.

func (*Shape) TranslatedY

func (s *Shape) TranslatedY(ty float64) *Shape

TranslatedY returns a copy of this shape, translated on the y-axis.

func (*Shape) TranslatedZ

func (s *Shape) TranslatedZ(tz float64) *Shape

TranslatedZ returns a copy of this shape, translated on the z-axis.

func (*Shape) UniScale

func (s *Shape) UniScale(scale float64)

UniScale scales this shape by the same amount on each axis, in place.

func (*Shape) UniScaled

func (s *Shape) UniScaled(scale float64) *Shape

UniScaled returns a copy of this shape, scaled by the same amount on each axis.

type String

type String struct {
	Orig        string
	Letters     []*Shape
	AspectRatio float64
}

String represents a 3d character string. Initially this only holds a list of shapes, each on representing one letter in the string. Calling one of the `As...` methods returns a single unified shape object.

func NewString

func NewString(str string) *String

NewString creates a new 3d string object.

func (*String) AsCylinder

func (s *String) AsCylinder(radius float64) *Shape

AsCylinder creates a single shape consisting of the all the chars in the string wrapped around a cylinder.

func (*String) AsLine

func (s *String) AsLine() *Shape

AsLine creates a single shape consisting of all the chars in the string laid out in a single horizontal line.

func (*String) AsVCylinder

func (s *String) AsVCylinder(radius float64) *Shape

AsVCylinder creates a single shape consisting of the all the chars in the string layed out vertically and wrapped around a cylinder.

func (*String) AsVLine

func (s *String) AsVLine() *Shape

AsVLine creates a single shape consisting of all the chars in the string laid out in a single vertical line.

Jump to

Keyboard shortcuts

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