banner

package module
v0.0.0-...-dbc6c68 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

README

Project

banner is a simple raster graphics generator that generates randomly a background and two lines of text.

Warning

banner is my first Go repository cretaed for language learning and is not ready for production.

Example

This is default image (when no commandline options are provided) example

Usage

The usage options are as follows:

Usage of input:
  -alg int
    	Background painter algorithm; valid values are: 
    	7 -> random hexagons with offset
    	0 -> random rectangles
    	1 -> random rectangles with offset
    	2 -> plain color
    	3 -> concentric circles
    	4 -> concentric circles offset
    	5 -> random horizontal lines
    	6 -> random hexagons
    	 (default 5)
  -h int
    	height of the resulting image (default 600)
  -o string
    	name of output file where banner in .png format will be saved (default "out.png")
  -p int
    	palette type; valid values are: 
    	0 -> Warm
    	1 -> Happy
    	2 -> Hue
    	
  -st string
    	explanatory text to display in the image below the text
  -t string
    	text to display in the image
  -ts float
    	size of tile (default 30)
  -w int
    	width of the resulting image (default 800)

Readme generator

The project also contains readme generator binary (in cmd/readmegenerator/main.go) which takes path to image directory where it generates images, and writes this file's contents to stdout, with image linked to this markdown file.

For details, see the source

Usage
cd /cmd/readmegenerator && go build .
cd ../..
./cmd/readmegenerator/readmegenerator ../..

Images

And here are images:

Image img/out_alg0_pal0.png

random rectangles

Image img/out_alg0_pal1.png

random rectangles

Image img/out_alg0_pal2.png

random rectangles

Image img/out_alg1_pal0.png

random rectangles with offset

Image img/out_alg1_pal1.png

random rectangles with offset

Image img/out_alg1_pal2.png

random rectangles with offset

Image img/out_alg2_pal0.png

plain color

Image img/out_alg2_pal1.png

plain color

Image img/out_alg2_pal2.png

plain color

Image img/out_alg3_pal0.png

concentric circles

Image img/out_alg3_pal1.png

concentric circles

Image img/out_alg3_pal2.png

concentric circles

Image img/out_alg4_pal0.png

concentric circles offset

Image img/out_alg4_pal1.png

concentric circles offset

Image img/out_alg4_pal2.png

concentric circles offset

Image img/out_alg5_pal0.png

random horizontal lines

Image img/out_alg5_pal1.png

random horizontal lines

Image img/out_alg5_pal2.png

random horizontal lines

Image img/out_alg6_pal0.png

random hexagons

Image img/out_alg6_pal1.png

random hexagons

Image img/out_alg6_pal2.png

random hexagons

Image img/out_alg7_pal0.png

random hexagons with offset

Image img/out_alg7_pal1.png

random hexagons with offset

Image img/out_alg7_pal2.png

random hexagons with offset

Documentation

Index

Constants

View Source
const DEF_ALG = 5
View Source
const DEF_HEIGHT = 600
View Source
const DEF_OUT = "out.png"
View Source
const DEF_PAL = Warm
View Source
const DEF_SUB = "this time about really important things"
View Source
const DEF_TILE = 30
View Source
const DEF_TITLE = "My blogpost"
View Source
const DEF_WIDTH = 800
View Source
const DEF_WITH_TEXT = false
View Source
const FONT_FILE = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"

Variables

View Source
var PainterAlgs = map[AlgType]Alg{
	RandomRect:              {DrawRectRand, "random rectangles", gridGenerator},
	RandomRectOffset:        {DrawRectRand, "random rectangles with offset", gridDeltaGenerator},
	PlainColor:              {DrawRect, "plain color", plainGenerator},
	ConcentricCircles:       {DrawBgCircles, "concentric circles", gridGenerator},
	ConcentricCirclesOffset: {DrawBgCircles, "concentric circles offset", gridDeltaGenerator},
	HorizontalLines:         {DrawBgLines, "random horizontal lines", linesRandomGenerator},
	RandomHexagons:          {DrawHexagon, "random hexagons", gridGenerator},
	RandomHexagonsOffset:    {DrawHexagon2, "random hexagons with offset", gridHexDeltaGenerator},
}

array of identifiers presented to the user to Alg struct

View Source
var PaletteInfos = map[PaletteType]PaletteInfo{
	Warm:  {colorful.WarmPalette, "Warm"},
	Happy: {colorful.HappyPalette, "Happy"},
	Hue:   {HuePalette, "Hue"},
}

Functions

func Draw

func Draw(pc PatternContext, texts []*string, patternDraw BgFn)

Draws with pc as PatternContext, filling background with patternDraw and using Textx.

func DrawBgCircles

func DrawBgCircles(c PatternContext)

Single tile painter: draws concentric circles

func DrawBgLines

func DrawBgLines(c PatternContext)

func DrawHexagon

func DrawHexagon(c PatternContext)

DrawHexagon draws hexagon

func DrawHexagon2

func DrawHexagon2(c PatternContext)

here c.size is the size of the rectangle, not the tile

func DrawRect

func DrawRect(c PatternContext)

Draws rect of size with first color of the palette

func DrawRectRand

func DrawRectRand(c PatternContext)

Draws rect of size with random color of the palette

func DrawT

func DrawT(dc *gg.Context, t Text, textMaxWidth float64)

func GenerateBanner

func GenerateBanner(i Input)

Types

type Alg

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

struct representing drawing algorithm fn - function BgFn desc - description displayed when -h option was given pg - function that generates Rects for drawing tile

func (Alg) Desc

func (a Alg) Desc() string

type AlgType

type AlgType = int
const (
	RandomRect AlgType = iota
	RandomRectOffset
	PlainColor
	ConcentricCircles
	ConcentricCirclesOffset
	HorizontalLines
	RandomHexagons
	RandomHexagonsOffset
)

type BgFn

type BgFn = func(PatternContext)

type DeltaCalculation

type DeltaCalculation = func(col int, row int) (float64, float64)

Function type: calculation of dx and dy

For given column and row number in a grid returns dx and dy used to calculate top-left position of a next tile

type DescProvider

type DescProvider interface {
	Desc() string
}

type InpData

type InpData struct {
	Alg int
	H   int
	O   string
	P   int
	T   string
	St  string
	Ts  float64
	W   int
}

func (InpData) From

func (id InpData) From(i Input) InpData

type Input

type Input struct {
	W        *int
	H        *int
	Texts    []*string
	AlgIdx   *int
	TileSize *float64
	Pt       *int
	OutName  *string
}

func GetInput

func GetInput() Input

Parses commandline parameters and gives Input object with fields initalized with provided values (or defaults) TODO - sanitize input

func InputFlagSet

func InputFlagSet() (*flag.FlagSet, Input)

func (Input) From

func (i Input) From(id InpData) Input

type Palette

type Palette = []colorful.Color

func DefaultPalette

func DefaultPalette(t PaletteType, n int) Palette

func GenPaletteOf

func GenPaletteOf(t PaletteType, n int) Palette

func HuePalette

func HuePalette(n int) (Palette, error)

type PaletteGenerator

type PaletteGenerator = func(int) (Palette, error)

type PaletteInfo

type PaletteInfo struct {
	Generator PaletteGenerator
	Desc      string
}

type PaletteType

type PaletteType = int
const (
	Warm PaletteType = iota
	Happy
	Hue
	Unknown
)

type PatternContext

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

type Point

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

Point struct, represents location inside drawing area

type Rect

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

Represents rectangle used to draw a tile

type RectGenerator

type RectGenerator = func(p Point, s Size, tileSize Size) []Rect

p - top left corner of canvas s - size of canvas ts - tile size

type Size

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

Size struct with wi (width) and hi (height) of drawing area

type Text

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

Text with rendering info

func (Text) Size

func (s Text) Size(dc *gg.Context, width float64) Size

Calculates Size for Text when given maz width

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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