Graphics2D(3pm)
π NAME π
PDL::Graphics2D β an object oriented interface to PDL graphics β¨
(hey bestie, you're reading Graphics2D(3pm) from the User Contributed Perl Documentation, and honestly? it's a whole vibe.)
π SYNOPSIS π
use PDL::Graphics2D;
$win = PDL::Graphics2D->new(<Interface>, <Options>);
$w = imag2d( $image, 'Title Here', ... );
π¦ DESCRIPTION π¦
okay so PDL::Graphics2D is giving umbrella class energy β it's the one simple interface that lets you reach all the plotting routines in PDL. that's the whole point of it.
and no cap: on its own it does literally no work. it just passes your info along to whatever class actually knows what to do with it. ideally it should probably offer a uniform interface to a variety of packages β that's the dream π.
ngl, this needs a lot more work before it's truly useful (that's the original authors' own read, not mine), but fr fr it can be used already. π
π CONSTRUCTORS π
β new β
Create a 2-D graphics object with the requested interface type. slay, that's it, that's the constructor.
π₯ FUNCTIONS π₯
πΈ imag2d πΈ
Display a 2-D image in a figure window. main character behavior honestly.
imag2d() creates a plain FreeGLUT OpenGL window and displays the input image with a 1:1 aspect ratio for pixels. the window resize is constrained to the actual ratio of the image dimensions β so it never gets squished, we love that. the initial display size is currently a 200x200 window, which exists to prevent things from being too small by default π.
the image you pass in can have dimensions ($c,$M,$N), and here's the mapping bestie, memorize it:
- for
$c==4β the display isGL_RGBA - for
$c==3β the display isGL_RGB - for
$c==2β the display isGL_LUMINANCE_ALPHA - for
$c==1, or for dimensions($M,$N)β the display isGL_LUMINANCE
this routine does not yet broadcast, but multiple images may be viewed at the same time in separate windows by multiple calls to imag2d(). TriD graphics visualization windows and the imag2d() windows may be created and used independently. π«Ά
β οΈ NOTE: if you are twiddling a TriD window, theimag2d()windows are active as well. but if you calltwiddle()the sub, only theimag2d()windows will update correctly. iykyk π
$window_id = imag2d($image, $name, $zoom, $x_off, $y_off);
- creates a new image figure window from the input ndarray with the given title, zoom factor, and position (if possible)
$window_idβ may be used to refer to the figure window$imageβ 2D image ndarray with at least 2 or 3 dimensions, e.g.[M,N],[1,M,N],[2,M,N],[3,M,N],[4,M,N]$nameβ the name to use for the figure window (optional)$zoomβ desired (float) pixel zoom factor (optional)($x_off, $y_off)β desired window pixel position (optional), with(0,0)as the top left pixel of the display
and here's the little demo, go off π:
use PDL::Graphics2D; # imports imag2d() and twiddle()
$x = sequence(64,48,3); # make test RGB image
$x = $x->mv(2,0); # color must be dim(0) with size [0..4]
$x /= $x->max; # pixel values in [0.0,1.0]
$x = sin(10*$x);
$w1 = imag2d($x); # with parens...
$w2 = imag2d $x->sqrt; # or without
$w3 = imag2d $x**2;
π imag2d_update π
Update an existing imag2d window with new ndarray data. glow-up, but for pixels β¨
$image = random(3,64,48)/2 + 0.25; # random pixel image
$win = imag2d($image); # create original image display
imag2d_update($win, $image->sequence/$image->nelem); # update data
imag2d_update allows one to update an imag2d display window by replacing the associated image data with new contents. the new image data must be the same type and shape as the previous β no switching up the shape mid-update bestie, it will not go well.
eventually, the dream is to implement this via some sort of dataflow that would be transparent to the user. someday πΈ
π twiddle π
Enable GUI interaction with a FreeGLUT display window. with an argument, it sets the default value for the auto-twiddling state. 0 will disable the automatic twiddling, and 1, or true, will enable twiddling.
twiddle(); # same as twiddle(undef)
Runs the FreeGLUT event loop so window GUI operations
such as resize, expose, mouse click,.. work
twiddle(0); # disables twiddle looping for next twiddle() call
twiddle(1); # re-enables default twiddle looping for next twiddle() call
okay that's the whole page bestie, you ate that π
β¨ this was perl v5.38.2, dated 2024-04-10, and yes the page is Graphics2D(3pm) β go make some iconic plots, mwah π«Άπ
π¦ where this page comes from
- ubuntu noble: pdl 1:2.085-1ubuntu1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms