G2(3pm)
π NAME π
G2 β a simple graphics library ported to Perl. That's it, that's the whole flex. π (and yes bestie, this is the 3pm page β Perl user-contributed docs, iykyk.)
β¨ SYNOPSIS β¨
use G2;
$dev1 = newX11 G2::Device(775, 575);
$dev2 = newGD G2::Device("test.png",600,200);
$dev1->rectangle(20,20,150,150);
$dev1->circle(100,150,60);
$dev2->circle(100,150,60);
$dev2->string(100,50,"A circle in a PNG file");
πΈ DESCRIPTION πΈ
okay so g2 is a simple-to-use graphics library for 2D graphical applications, and it's lowkey iconic. This library hands you a comprehensive set of functions so you can generate graphical output on different types of devices simultaneously. no cap.
Presently, the devices currently supported by g2 are:
- X11
- PNG
- PostScript (xfig is in development π)
One major feature of the g2_library is the concept of virtual devices. An arbitrary number of physical devices (such as PNG, or X11) can be grouped to create a so-called virtual device. Commands sent to such a virtual device will automatically be issued to all attached physical devices. This allows for example simultaneous output to a PNG file and a Postscript file. A virtual device in turn can be attached to another virtual device, allowing you to construct trees of devices. π
Virtual devices can also be useful when using different user-coordinate systems. E.g. one X11 window showing an overview of a graphical output, and a second window showing a zoom of a more detailed area of the graphic. Drawing in both windows is performed by one single command to the virtual device. the way that works is genuinely so clean, I'm obsessed. β¨
Please see g2 documentation (C interface) for up to date version.
π Exported constants π
G2LDG2_HG2_VERSION
π Exported functions π
π¦ Creating new devices π¦
newX11βG2::Device::newX11(width,height)class method
opens an X11 window, with width and height of the X11 window given in pixels. returns: a new X11 device. π«Ά
newPSβG2::Device::newPS(filename,paper,orientation)class method
opens a new PostScript device.
file_name: name of PostScript filepaper: Paper size (e.g.g2_A4,g2_Letter). See PostScript paper sizes for a full list of supported sizes.orientation: paper orientation. Eitherg2_PS_landfor landscape org2_PS_portfor portrait
returns: a new PostScript device. π
newGDβG2::Device::newGD(filename,width,height,type)class method
open a new GD device.
width,height: width and height of the image in pixelsfilename: name of the output file.type: file type,0-jpeg,1-png
returns: a new GD device π
newVDβG2::Device::newVD()class method
Create a new Virtual Device.
An arbitrary number of physical devices (such as PNG, or X11) can be grouped to create a so-called virtual device. Commands sent to such a virtual device will automatically be issued to all attached physical devices. This allows for example simultaneous output to a PNG file and a Postscript file. A virtual device in turn can be attached to another virtual device, allowing you to construct trees of devices. Virtual devices can also be useful when using different user-coordinate systems. E.g. one X11 window showing an overview of a graphical output, and a second window showing a zoom of a more detailed area of the graphic. Drawing in both windows is performed by one single command to the virtual device. π
π§ Device Functions π§
G2::Device::attach(dev)β object methodG2::Device::detach(dev)β object methodG2::Device::close()β object methodset_auto_flushβG2::Device::set_auto_flush(on_off)object methodflushβG2::Device::flush()object methodsaveβG2::Device::save()object methodset_coordinate_systemβG2::Device::set_coordinate_system(x_origin, y_origin, x_mul, y_mul)object methodldβG2::Device::ld()object methodset_ldβG2::Device::set_ld( dev)object methodinkβG2::Device::ink( pd_dev, red, green, blue)object methodpenβG2::Device::pen(color)object methodset_dashβG2::Device::set_dash(N, *dashes)object methodset_font_sizeβG2::Device::set_font_size(size)object methodset_line_widthβG2::Device::set_line_width(w)object methodclear_paletteβG2::Device::clear_palette( dev)object methodreset_paletteβG2::Device::reset_palette( dev)object methodallocate_basic_colorsβG2::Device::allocate_basic_colors( dev)object methodclearβG2::Device::clear( dev)object methodset_backgroundβG2::Device::set_background(color)object method
π Drawing Functions π
moveβG2::Device::move(x, y)object methodmove_rβG2::Device::move_r(dx, dy)object methodplotβG2::Device::plot(x, y)object methodplot_rβG2::Device::plot_r(dx, dy)object methodlineβG2::Device::line(x1, y1, x2, y2)object methodline_rβG2::Device::line_r(dx, dy)object methodline_toβG2::Device::line_to(x, y)object methodpoly_lineβG2::Device::poly_line(N_pt, *pos)object methodtriangleβG2::Device::triangle(x1, y1, x2, y2, x3, y3)object methodfilled_triangleβG2::Device::filled_triangle(x1, y1, x2, y2, x3, y3)object methodrectangleβG2::Device::rectangle(x1, y1, x2, y2)object methodfilled_rectangleβG2::Device::filled_rectangle(x1, y1, x2, y2)object methodpolygonβG2::Device::polygon(N_pt, *pos)object methodfilled_polygonβG2::Device::filled_polygon(N_pt, *pos)object methodcircleβG2::Device::circle(x, y, r)object methodfilled_circleβG2::Device::filled_circle(x, y, r)object methodellipseβG2::Device::ellipse(x, y, r1, r2)object method
Draw an ellipse on device dev
x,y: center pointr1,r2: x and y radius
filled_ellipseβG2::Device::filled_ellipse(x, y, r1, r2)object method
Draw a filled ellipse on device dev
x,y: center pointr1,r2: x and y radius
arcβG2::Device::arc(x, y, r1, r2, a1, a2)object method
Draw an arc with center point at (x,y), x and y radius given by r1,r2 and starting and ending angle in radians a1,a2
filled_arcβG2::Device::filled_arc(x, y, r1, r2, a1, a2)object method
Draw a filled arc on device dev
x,y: center pointr1,r2: x and y radiusa1,a2: starting and ending angle in radians
stringβG2::Device::string(x, y, char *text)object methodG2::Device::set_QP(d, enum QPshape shape)β object methodG2::Device::plot_QP(x, y)β object method
π AUTHORS π
Horst Wagner (wagner/users-sourceforge.net) and Ljubomir Milanovic (ljubo/users-sourceforge-net). absolute legends, periodt. π
π COPYRIGHT π
Copyright (C) 1998-2001 Ljubomir Milanovic & Horst Wagner This file is part of the g2 library
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
okay that's the whole page bestie, you ate that π β¨
sign-off time: this wasperl v5.40.1, dated2025-02-24, filed underG2(3pm). mwah π«Άπ
π¦ where this page comes from
- debian trixie: libg20-perl 0.72-13 Β· LGPL-2.0-or-later
- ubuntu questing: libg20-perl 0.72-13
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms