geopattern

package module
v0.0.0-...-0a88357 Latest Latest
Warning

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

Go to latest
Published: May 1, 2015 License: MIT Imports: 9 Imported by: 0

README

geopattern

Create beautiful generative image patterns from a string in golang.

Go port of Jason Long's awesome GeoPattern library.

GoDoc

Read geopattern's development story geo_pattern: going on the Go path

Nested Squares Pattern

Generate beautiful tiling SVG patterns from a string. The string is converted into a SHA and a color and pattern are determined based on the values in the hash. The color is determined by shifting the hue from a default (or passed in) base color. One of 16 patterns is used (or you can specify one) and the sizing of the pattern elements is also determined by the hash values.

You can use the generated pattern as the background-image for a container. Using the base64 representation of the pattern still results in SVG rendering, so it looks great on retina displays.

See the GitHub Guides site as an example of this library in action. GitHub Guides use Original Ruby implementation.

####Installation go get github.com/pravj/geopattern

####Usage Example directory contains sample go programs that explains use of geopattern

####API

#####Arguments for functions returning pattern's string

######phrase : custom pattern phrase

args := map[string]string{"phrase": "My Custom Phrase"}

######generator : custom pattern type

args := map[string]string{"generator": "plaid"}

######color : custom background color

args := map[string]string{"color": "#3b5998"}

######baseColor : custom base color that decides background color

args := map[string]string{"baseColor": "#ffcc00"}

#####Functions provided by package for pattern's string representation

######Get the SVG string :

Generate(args)

######Get the Base64 encoded string :

Base64String(args)

######Get uri image string :

URIimage(args)

####Available Pattern

chevrons

Chevrons

concentric-circles

Concentric-Circles

diamonds

Diamonds

hexagons

Hexagons

mosaic-squares

Mosaic-Squares

nested-squares

Nested-Squares

octagons

Octagons

overlapping-circles

Overlapping-Circles

overlapping-rings

Overlapping-rings

plaid

Plaid

plus-signs

Plus-Signs

sine-waves

Sine-Waves

squares

Squares

tessellation

Tessellation

triangles

Triangles

xes

Xes

####Dependencies go-colorful : for color space conversion


Made with Muzi and Appy by Pravendra Singh

Documentation

Overview

Package geopattern creates beautiful generative image patterns from a string.

Index

Constants

View Source
const (
	BaseColor      string  = "#9e2c7b"
	StrokeColor    string  = "#000"
	StrokeOpacity  float64 = 0.02
	FillColorDark  string  = "#222"
	FillColorLight string  = "#ddd"
	OpacityMin     float64 = 0.02
	OpacityMax     float64 = 0.15
)

constants representing stroke, fill's opacity and color, base color, minimum and maximum opacity value

Variables

View Source
var PATTERNS = [16]string{
	"chevrons",
	"concentric-circles",
	"diamonds",
	"hexagons",
	"mosaic-squares",
	"nested-squares",
	"octagons",
	"overlapping-circles",
	"overlapping-rings",
	"plaid",
	"plus-signs",
	"sine-waves",
	"squares",
	"tessellation",
	"triangles",
	"xes",
}

All available geo patterns

Functions

func Base64String

func Base64String(args Pattern) string

Base64String returns pattern's Base64 encoded string

func BuildChevron

func BuildChevron(width, height float64) [2]string

BuildChevron returns string representing a chevron shape

func BuildDiamond

func BuildDiamond(width, height float64) string

BuildDiamond returns string representing a diamond shape

func BuildHexagon

func BuildHexagon(sideLength float64) string

BuildHexagon returns string representing a hexagon shape

func BuildOctagon

func BuildOctagon(squareSize float64) string

BuildOctagon returns string representing an octagon shape

func BuildPlus

func BuildPlus(squareSize float64) [2]string

BuildPlus returns string representing an plus shape

func BuildRightTriangle

func BuildRightTriangle(sideLength float64) string

BuildRightTriangle returns string representing a right angle triangle shape

func BuildRotatedTriangle

func BuildRotatedTriangle(sideLength, width float64) string

BuildRotatedTriangle returns string representing a rotated triangle shape

func BuildTriangle

func BuildTriangle(sideLength, height float64) string

BuildTriangle returns string representing a triangle shape

func DrawInnerMosaicTile

func DrawInnerMosaicTile(s *SVG, x, y, triangleSize float64, values [2]float64)

DrawInnerMosaicTile returns string representing an inner mosaic tile shape

func DrawOuterMosaicTile

func DrawOuterMosaicTile(s *SVG, x, y, triangleSize, value float64)

DrawOuterMosaicTile returns string representing an outer mosaic tile shape

func FillColor

func FillColor(value float64) string

FillColor returns string to be used for fill color

func Generate

func Generate(args Pattern) string

Generate returns pattern's SVG string

func Hash

func Hash(s string) string

Hash returns SHA-1 encryption of a string

func HexVal

func HexVal(str string, index, length int) float64

HexVal returns decimal representation of a substring of a hexa decimal string

func Map

func Map(value, aMin, aMax, bMin, bMax float64) float64

Map returns respective value of a number from a range to different range

func Merge

func Merge(mapA map[string]interface{}, mapB map[string]interface{}) map[string]interface{}

Merge merges two 'map' objects and returns the resultant object

func Opacity

func Opacity(value float64) float64

Opacity returns opacity value in a particular range

func URIimage

func URIimage(args Pattern) string

URIimage returns pattern's uri image string

Types

type Pattern

type Pattern struct {
	BaseColor string
	Color     string
	Generator string
	Phrase    string
	// contains filtered or unexported fields
}

Pattern struct that contains attributes like base color, background color pattern type, phrase for the pattern and SHA-1 hash of phrase

func (*Pattern) SvgStr

func (p *Pattern) SvgStr() string

svgStr returns string representing pattern's SVG string

type SVG

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

SVG struct, SVG contains elementry attributes like svg string, width, height

func (*SVG) Circle

func (s *SVG) Circle(cx, cy, r interface{}, args map[string]interface{})

Circle adds a circle element to SVG object

func (*SVG) Group

func (s *SVG) Group(elements [2]string, args map[string]interface{})

Group adds a group element to SVG object.

It groups optionally provided elements together.

func (*SVG) Path

func (s *SVG) Path(str string, args map[string]interface{})

Path adds a path element to SVG object

func (*SVG) Polyline

func (s *SVG) Polyline(str string, args map[string]interface{})

Polyline adds a polyline element to SVG object

func (*SVG) Rect

func (s *SVG) Rect(x, y, w, h interface{}, args map[string]interface{})

Rect adds a rectangle element to SVG object

func (*SVG) SetHeight

func (s *SVG) SetHeight(h int)

SetHeight sets SVG object's height

func (*SVG) SetWidth

func (s *SVG) SetWidth(w int)

SetWidth sets SVG object's width

func (*SVG) Str

func (s *SVG) Str() string

Str returns string representing whole SVG object

func (*SVG) WriteArgs

func (s *SVG) WriteArgs(args map[string]interface{}) string

WriteArgs adds additional attributes to a SVG elements.

It parses provides 'map' arguments to add attributes to SVG element.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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