Commit acaf6d94 authored by Taras Postument's avatar Taras Postument
Browse files

make "draw" functions accept io.Writer instead of http.ResponseWriter

parent 64dff00f
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ package isogrids

import (
	"image/color"
	"net/http"
	"io"

	svg "github.com/ajstarks/svgo"
	"github.com/taironas/tinygraphs/colors"
@@ -11,8 +11,7 @@ import (

// RandomGradientColor builds a isogrid image with with x colors selected at random for each quadrant.
// the background color stays the same the other colors get mixed in a gradient color from the first one to the last one.
func RandomGradientColor(w http.ResponseWriter, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int, prob float64) {

func RandomGradientColor(w io.Writer, colors, gColors []color.RGBA, gv colors.GradientVector, width, height, lines int, prob float64) {
	var gradientColors []svg.Offcolor
	gradientColors = make([]svg.Offcolor, len(gColors))
	percentage := uint8(0)
+3 −3
Original line number Diff line number Diff line
@@ -2,14 +2,14 @@ package isogrids

import (
	"image/color"
	"net/http"
	"io"

	"github.com/ajstarks/svgo"
	svg "github.com/ajstarks/svgo"
	"github.com/taironas/tinygraphs/draw"
)

// Hexa builds an image with lines x lines grids of half diagonals in the form of an hexagon
func Hexa(w http.ResponseWriter, key string, colors []color.RGBA, size, lines int) {
func Hexa(w io.Writer, key string, colors []color.RGBA, size, lines int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

+3 −3
Original line number Diff line number Diff line
@@ -3,16 +3,16 @@ package isogrids
import (
	"errors"
	"image/color"
	"net/http"
	"io"

	"github.com/ajstarks/svgo"
	svg "github.com/ajstarks/svgo"
	"github.com/taironas/tinygraphs/draw"
)

// Hexa16 builds an image with lines x lines grids of half diagonals in the form of an hexagon
// it draws 6 triangles, triangle 1 to 5 are all rotations of triangle 0.
// triangle zero triangle on the center left.
func Hexa16(w http.ResponseWriter, key string, colors []color.RGBA, size, lines int) {
func Hexa16(w io.Writer, key string, colors []color.RGBA, size, lines int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

+3 −3
Original line number Diff line number Diff line
@@ -2,14 +2,14 @@ package isogrids

import (
	"image/color"
	"net/http"
	"io"

	"github.com/ajstarks/svgo"
	svg "github.com/ajstarks/svgo"
	"github.com/taironas/tinygraphs/draw"
)

// Isogrids builds an image with 10x10 grids of half diagonals
func Isogrids(w http.ResponseWriter, key string, colors []color.RGBA, size, lines int) {
func Isogrids(w io.Writer, key string, colors []color.RGBA, size, lines int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

+5 −5
Original line number Diff line number Diff line
@@ -3,14 +3,14 @@ package isogrids
import (
	"fmt"
	"image/color"
	"net/http"
	"io"

	"github.com/ajstarks/svgo"
	svg "github.com/ajstarks/svgo"
	"github.com/taironas/tinygraphs/draw"
)

// Diagonals builds an image with 10x10 grids of diagonals.
func Diagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) {
func Diagonals(w io.Writer, key string, color1, color2 color.RGBA, size int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

@@ -48,7 +48,7 @@ func Diagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, siz
}

// HalfDiagonals builds an image with 10x10 grids of half diagonals
func HalfDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) {
func HalfDiagonals(w io.Writer, key string, color1, color2 color.RGBA, size int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

@@ -86,7 +86,7 @@ func HalfDiagonals(w http.ResponseWriter, key string, color1, color2 color.RGBA,
}

// Skeleton builds an image with 10x10 grids of half diagonals
func Skeleton(w http.ResponseWriter, key string, color1, color2 color.RGBA, size int) {
func Skeleton(w io.Writer, key string, color1, color2 color.RGBA, size int) {
	canvas := svg.New(w)
	canvas.Start(size, size)

Loading