stdg

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: MIT

README

Standard Graphics

Standard Graphics is a universal rendering engine abstraction for 2D graphics. It provides a cross-platform, language-agnostic interface based on the stdin and stdout streams available on most operating systems. This allows you or your team to change developer environments (operating system, languages, stack, etc.) without having to change platform support (operating systems, hardware, back-end, etc.) and to change platform support without having to change developer environment. Standard Graphics is implemented in Rust with a binding to SDL2 and compiles to a safe, efficient binary with help from LLVM.

Features

Standard Graphics currently provides a small but growing set of commands to print graphics and handle events.

  • Draw lines, points
  • Draw circles, squares, rectangles
  • Draw with fill or outline
  • Handle mouse events, touch events

This allows Standard Graphics to be used to create simple data visualizations, visual simulations, animations, etc.

Examples

Here is an example of stdg being used by a Ruby program-

loop do
	puts 'color 255 255 255'
	puts 'clear'
	puts 'color 255 0 0'
	puts 'rect 50 50 100 100'
	puts 'present'
	puts 'handle'
end

The graphics for this program can be rendered by piping the program's standard output to standard graphics.

ruby draw_rectangle.rb | stdg

This will open the following window to output the graphics.

An example output through standard graphics

Here's another example. This example is taken from Khan Academy's "Making animations" lesson. Since this program is written in Python, you will have to use the Python interpreter to run it.

# position of the car
x = 10

while True:
	print("color 151 244 247")
	print("clear")

	# draw the car body
	print("color 255 0 115")
	print("fill rect " + str(x) + " 200 100 20")
	print("fill rect " + str(x + 15) + " 178 70 40")

	# draw the wheels
	print("color 77 66 66")
	print("fill circle " + str(x + 25) + " 221 12")
	print("fill circle " + str(x + 75) + " 221 12")

	print("present")
	print("handle")

	x = x + 1
python moving_car.py | stdg

An example output through standard graphics

Usage

The easiest way to install Standard Graphics is by downloading and installing the binaries from here.

You can also install Standard Graphics by building from source.

$ curl https://sh.rustup.rs -sSf | sh
$ git clone https://www.github.com/calebwin/stdg
$ cd stdg
$ cargo install --path .

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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