New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/yalue/turtle_graphics

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/yalue/turtle_graphics

  • v1.0.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

Turtle Graphics

A library for generating "Turtle graphics", based on instruction strings. For the Go language. Made for fun, there are better alternatives if you care about features or efficiency.

Usage

See simple_tester/simple_tester.go for a more complete example. But, as a simple showcase:

import (
    "github.com/yalue/turtle_graphics"
)

func main() {
    // Draw a simple 'Y' shape. The turtle starts out facing 0 degrees: left.
    t := turtle_graphics.NewTurtle()
    t.Turn(90)
    t.MoveForward(1)
    t.Turn(-30)
    t.PushPosition()
    t.MoveForward(1)
    t.PopPosition()
    t.Turn(60)
    t.MoveForward(1)

    // Get a dummy canvas to compute the image bounds with.
    dummyCanvas := turtle_graphics.NewDummyCanvas()
    err := t.RenderToCanvas(dummyCanvas)
    if err != nil {
        return fmt.Errorf("Failed rendering to dummy canvas: %s", err)
    }
    minX, minY, maxX, maxY := dummyCanvas.GetExtents()
    aspectRatio := (maxX - minX) / (maxY - minY)
    height := 1000
    width := int(float64(height) * aspectRatio)

    // Get a "real" canvas to draw the image on.
    rgbaCanvas, err := turtle_graphics.NewRGBACanvas(width, height, minX, minY,
        maxX, maxY, color.White)
    if err != nil {
        // Handle error
        return fmt.Errorf("Failed initializing RGBA canvas: %s", err)
    }
    err = t.RenderToCanvas(rgbaCanvas)
    if err != nil {
        return fmt.Errorf("Failed rendering to RGBA canvas: %s", err)
    }
    // The rgbaCanvas now satisfies the image/Image interface, and can be saved
    // using any of the standard image libraries.
}

For a mildly more advanced example, see the l_system_render directory to show how this package can be used to render the dragon curve.

FAQs

Package last updated on 23 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc