randbitmap

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

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

Go to latest
Published: Jun 24, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

README

randbitmap Build Status GoDoc Go Report Card

Generate random bitmaps.

Random color bitmap

Installation

go get -u github.com/trubitsyn/randbitmap/cmd/randbitmap

Usage

Execute randbitmap to save black & white 100x100 image to random.png.

Usage of randbitmap:
  -color
        Color bitmap
  -file string
        Output file (default "random.png")
  -overwrite
        Overwrite existing file
  -size uint
        Bitmap size (default 100)
Defaults
randbitmap -size=100 -color=false -file=random.png -overwrite=false

Library

Installation
go get -u github.com/trubitsyn/randbitmap
Usage
package main

import (
	"flag"
	"fmt"
	"github.com/trubitsyn/randbitmap"
	"math/rand"
	"os"
)

var (
	width    = flag.Uint("width", 100, "Bitmap size")
	height   = flag.Uint("height", 100, "Bitmap size")
	color    = flag.Bool("color", false, "Color bitmap")
	filename = flag.String("file", "random.png", "Output file")
)

func main() {
	flag.Parse()
	bitmap := randbitmap.NewBitmap(*width, *height, *color)
	bitmap.SetGenerator(func(n int) int {
		return rand.Intn(n)
	})
	f, err := os.Create(*filename)
	if err != nil {
		fmt.Println(err)
	}
	if err := bitmap.Render(f); err != nil {
		fmt.Println(err)
	}
}

Testing

go get -t github.com/trubitsyn/randbitmap
go test github.com/trubitsyn/randbitmap

LICENSE

Copyright 2019 Nikola Trubitsyn

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Documentation

Overview

Package randbitmap provides functions to generate random bitmaps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitmap

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

Bitmap represents a random bitmap.

func NewBitmap

func NewBitmap(width uint, height uint, color bool) *Bitmap

NewBitmap creates new Bitmap.

func (*Bitmap) Render

func (bitmap *Bitmap) Render(w io.Writer) error

Render performs rendering and writes the bitmap to w.

func (*Bitmap) SetGenerator

func (bitmap *Bitmap) SetGenerator(generator generator)

SetGenerator sets function that generates random numbers.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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