painter

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2023 License: MIT Imports: 8 Imported by: 4

README

Painter (WIP)

A simple utility Golang package to help you with drawing on images

This package is currently work-in-progress and subject to change at any time.

Installation

$ go get github.com/haashemi/painter@master

Example

There are some examples in the examples folder, but here is one of them.

package main

import (
	"image/color"

	"github.com/haashemi/painter"
)

func main() {
	img := painter.New(Width, Height)

	black := color.RGBA{0, 0, 0, 255}
	white := color.RGBA{255, 255, 255, 255}

	painter.Render(img, painter.LinearGradient(45, black, white))

	err := painter.SavePNG(img, "painter.png")
	// handle the error
}

Contributions

All type of contributions are highly appreciated. <3

Documentation

Overview

Painter is a simple image.RGBA utility packages which helps you with drawing on images.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clamp

func Clamp(x, minVal, maxVal float64) float64

Clamp returns the value of x constrained to the range minVal to maxVal.

more: https://thebookofshaders.com/glossary/?search=clamp

func MixRGBA

func MixRGBA(a float64, x, y color.RGBA) color.RGBA

MixRGBA merges to color with the provided alpha.

"a" should be between 0 and 1.

func New

func New(width, height int) *image.RGBA

New returns a new image.RGBA in the specified width and height.

func Radians

func Radians(angle float64) float64

Radians converts the degrees to radians.

func Render

func Render(img *image.RGBA, renderer Renderer)

Render calls the renderer in each pixel of the image in NumCPU*2 goroutines for better performance.

func SaveJPEG

func SaveJPEG(img image.Image, path string, o *jpeg.Options) error

SaveJPEG creates a file in the specified path and encodes the image as jpeg to it.

func SavePNG

func SavePNG(img image.Image, path string) error

SavePNG creates a file in the specified path and encodes the image as png to it.

func SmoothStep

func SmoothStep(edge0, edge1, x float64) float64

SmoothStep performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where a threshold function with a smooth transition is desired.

more: https://thebookofshaders.com/glossary/?search=smoothstep

Types

type Renderer

type Renderer func(img image.Image, point image.Point) color.RGBA

Renderer is a function which gets the image.Image and the current image.Point, and returns a image/color.RGBA for that point.

func LinearGradient

func LinearGradient(angle float64, startColor, endColor color.RGBA) Renderer

LinearGradient is a Renderer which draws a linear gradient on the image from startColor to endColor with in the passed angle in degrees.

func RadialGradient

func RadialGradient(startColor, endColor color.RGBA, center image.Point) Renderer

RadialGradient is a Renderer which draws a radial gradient on the image from startColor to endColor. startColor starts from provided center point.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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