Code Monkey home page Code Monkey logo

raster's Introduction

Raster

A very simple library for drawing 2D shapes onto images or the screen with minimal dependencies.

I wrote it to learn, and to render simple shapes for games. You're probably looking for something more fully featured, like this: https://github.com/fogleman/gg

There's also a Turtle library similar to PyTurtle I wrote for my son to play with.

Features

// Circle
circle := raster.NewCircle(image.Point{500, 500}, 250, colornames.Maroon)
circle.Draw(img)

// Square
square := raster.NewSquare(image.Point{250, 250}, 500, colornames.Green)
square.Draw(img)

// Polygon
a := image.Point{500, 0}
b := image.Point{750, 250}
c := image.Point{1000, 500}
d := image.Point{750, 750}
e := image.Point{500, 1000}
f := image.Point{250, 750}
g := image.Point{0, 500}
h := image.Point{250, 250}

p := raster.NewFilledPolygon(colornames.Gray, colornames.Antiquewhite, a, b, c, d, e, f, g, h)
p.Draw(img)

// Text
t := raster.NewText(image.Point{0, 0}, "Hello!", colornames.White)
t.Draw(img)

// Combine elements together.
circleInsideSquare := raster.NewComposition(image.Point{250, 250},
    raster.NewCircle(image.Point{250, 250}, 250, colornames.Maroon),
    raster.NewSquare(image.Point{0, 0}, 500, colornames.Green))
circleInsideSquare.Draw(img)

Turtle

See ./examples/turtle

t := turtle.New(img)
t.Position = image.Point{width / 2, (height / 2) - 60}
// Walk out a bit.
t.Pen.Active = false
t.Forward(30)
// Then draw an octogon.
sides := 8
angle := 360 / float64(sides)

t.Pen.Active = true
for i := 0; i < sides; i++ {
    t.Rotate(angle)
    t.Forward(50)
}

Complete examples

See ./examples

raster's People

Contributors

a-h avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.