Graphics-Simple

 view release on metacpan or  search on metacpan

Simple.pm  view on Meta::CPAN

	use Graphics::Simple;

	line 100,100,200,200;
	circle 50,50,25;
	stop(); clear(); # Wait for a button press, clear the page

=head1 DESCRIPTION

Ever had a Commodore C-64 or Vic-20 or some other of the machines
of that era? Where doing graphics was as simple as

	line 20,20,50,30;

and you didn't have to go through things like C<XOpenDisplay> etc.

This module tries to bring back the spirit of that era in a modern
environment:
this module presents a simple, unified API to several different
graphics devices - currently X (using Gtk and Gnome) and PostScript.

The interface is primarily made easy-to-use, starting from the idea
that the above C<line> command must work. Therefore, it exports
most of the primitives by default (you can turn this off).

However, everything is not sacrificed in the name
of simplicity: believing in "simple things simple, complicated
things possible", this module also allows multiple windows
(all the primitives also work as methods of window objects)
as well as raw access to the underlying devices - although the
device-independence is then lost.
In future plans are some sort of interactions with the devices
with which it is possible as well as the addition of more devices.

The C<use> command currently accepts the forms

	use Graphics::Simple;
	use Graphics::Simple qw/line circle/;
	use Graphics::Simple 300,400; # portrait paper
	use Graphics::Simple 300,400, qw/line circle/;

i.e. the optional size of the default window first and then
normal C<Exporter> arguments.

C<Graphics::Simple> has several different back-ends, currently 
GnomeCanvas, TkCanvas, PostScript and (not fully working yet) Fig.
Other backends are expected.

To start C<Graphics::Simple> with a given backend, you should set
the environment variable C<GSIMPL> to the value, e.g. by running
your script with the command

	GSIMPL='PostScript' perl gt1.pl

or by setting the environment variable permanently in your shell, by

	GSIMPL=PostScript
	export GSIMPL

or 

	setenv GSIMPL PostScript

depending on which shell you use.

=cut

# Handle output files as well

@Graphics::Simple::Window::ISA = Graphics::Simple;

package Graphics::Simple;

require Exporter;
@ISA='Exporter';

@EXPORT = qw/line linewidth circle text clear stop new_window line_to color arrow/;

@DefSize = (300,300);

sub import {
	if($_[1] =~ /^[0-9]+$/) {
		@DefSize = splice @_,1,2;
	}
	goto &Exporter::import;
}


$VERSION='0.04';

@impl = qw/
	GSGtk.pm
/;

# require 'GSGtk.pm';
# require 'GSPS.pm';

$impl = GnomeCanvas;
# $impl = PostScript;
if($ENV{GSIMPL}) {
	$impl = $ENV{GSIMPL}
}

sub new_window {
	my($x, $y) = @_;
	($x,$y) = @DefSize if(!$x) ;
	eval "use Graphics::Simple::$impl";
	die("Couldn't get implementation! '$@'") if $@;
	my($win) = "Graphics::Simple::$impl"->_construct($x,$y) ;
	$win->{Current_Color} = '#000000';
	$win->{Current_LineWidth} = 1;
	return $win;
}

$Graphics::ObjectName = "GOAAA0";

sub startargs {
	my  ($win, $name);
	$win = (UNIVERSAL::isa($_[0],Graphics::Simple::Window) ?
			shift :
			$Graphics::Simple::Window || 
			($Graphics::Simple::Window = new_window()));



( run in 0.543 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )