Socket
Book a DemoInstallSign in
Socket

trtl

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trtl

0.0.2
bundlerRubygems
Version published
Maintainers
1
Created
Source

Trtl - Simple Ruby Turtle Graphics

example session

Installation

gem install trtl

Description

Trtl is a simple turtle system inspired by Python's turtle.py. It provides simple turtle drawing capabilities in Ruby, even if you're just at an IRb prompt. It leans on Tk which is part of MRI 1.9's standard library so in theory it should work 'out of the box' with most MRI 1.9 installs.

Usage

If Trtl detects you're in an IRb or Pry session, it'll automatically make turtle methods available directly at the prompt. For example:

$ irb
> require 'trtl'
> forward 100
# At this point, a window appears with the turtle

If you wish to use Trtl from a regular Ruby script, you have a few options. You can create a Trtl instance and use it directly:

require 'trtl'
t = Trtl.new
10.times { t.left(24); t.forward(30); t.ensure_drawn }
t.wait

You can use Trtl's run method to use it in a more interactive fashion:

Trtl.new.run { 10.times { left(24); forward(30); ensure_drawn } }

Or you can include InteractiveTurtle and get a similar effect as if you were in IRb:

include InteractiveTurtle
10.times { left(24); forward(30) }

Note: Using InteractiveTurtle makes drawing slower as it ensures all graphics are drawn after every action (as necessary for IRb use).

Commands

Only a small number of commands are currently implemented, but they're enough for the major actions:

  • title(title_name)
  • forward(distance) - aliased as fd
  • back(distance) - aliased as bk and backward
  • left(angle) - aliased as lt
  • right(angle) - aliased as rt
  • pen_up - aliased as pu and up and penup
  • pen_down - aliased as pd and down and pendown
  • color(color_name) - aliased as pencolor
  • move(x, y) - aliased as goto
  • position - aliased as pos
  • circle(radius, extent = 360, steps = 360)
  • dot(size) - draws a dot, defaults to a sensible size but you can supply if you want
  • is_drawing?
  • width(width_in_pixels)

More documentation to come later.

Examples

The examples in the examples folder should be reasonably illustrative. If you try any of them, try example4.rb - it renders an awesome looking tree.

tree

Credits

  • turtle.py for inspiration (in the 'Ruby needs this!' sense)
  • Some of the examples taken from examples for an earlier Ruby turtle found at http://www.rubyquiz.com/quiz104.html

Copyright (c) 2012 Peter Cooper (other than minor parts of some samples.)

MIT licensed. See LICENSE.md

FAQs

Package last updated on 14 Feb 2017

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.