Cloud::Cloud
A Perl Module to create a Word Cloud, or Image Cloud as SVG or HTML elements
use strict;use warnings;
use lib "../lib/"; # folder for Cloud/Cloud.pm
use Cloud::Cloud;
my $cloud = new Cloud();
my $firstElement= new CloudElement(textbox=>[100,110,"Oversight",20],
lineColour=>"blue",
textColour=>"red");
$cloud->addElement( $firstElement);
$cloud->save("test.svg");Generate clouds of words, links, images as addressable elements either in SVG or HTM, for interactive and dynamic use. This potentially allows such a cloud to be used as part of a UI, and do fancy things like animation. Two packages are provided, Cloud and CloudElement in the same module. It has no other external dependencies. Similar modules exist and it is relatively easy to generate "Word Cloud"s online. This module aims to give this feature to Perl applications. Efforts on MetaCPAN are listed below. The images genrated are vector (SVG), or HTML Elements and therefore may also be dynamic, adaptable for animations and user interactions. There are various algorithms that may be used to place the elements. The examples below merely place these elements in random free space and then move them towards the centre until they nearly touch another element.
Two Packages are provided. Cloud and CloudElement. The Cloud object may contain various kinds of CloudElements (e.g. "rectangles","text","textbox", "image").
use Cloud::Cloud;This objects contains the CloudElements
my $cloud=new Cloud; # using default size
my $cloud=new Cloud([3000,3000]);# specifying width and height$cloud->addElement(@elements) adds one or more elements to the cloud
$cloud->checkOverlap($element) checks if an element overlaps any other elements in the cloud, returns 0 if no overlaps or an arrayRef of indexes of elements that overlap.
$cloud->moveTowards($element,$target) moves an element as close to the $target coordinates until it can not do so without overlapping
$cloud->center() returns the center coordinates of the cloud;
$cloud->save("test.svg") ; $cloud->save([filename],[format]) ; saves the cloud. The format can be passed separately or derived from the extension (`.svg` or `.htm(l)?`).
$cloud->center() returns the center coordinates of the cloud center;
$cloud->placeAtCenter($element) ; places element at cloud center;
$cloud->placeRandomly($element) ; places element randomly at at empty space on cloud;
$cloud->placeArchimedian($element) ; places element on the path of an Archimedian spiral starting from the cloud center.
$cloud->compactAdd($element) ; this work by placing element at center, then progressively moving it at along Archimedian spiral until it does not overlap, then moving it towards the center.
my $firstElement= new CloudElement(textbox=>[100,110,"Perl Cloud",20],
lineColour=>(qw/red orange yellow green blue indigo violet/)[rand()*7],
textColour=>"red");
my $secondElement= new CloudElement(text=>[100,110,"Interaction",20],
textColour=>"red");
my $thirdElement= new CloudElement(rectangle=>[100,110,50,20],
bgColour=>"red",
lineColour=>"black");The element creation requires a set of parameters as key value pairs, or another element to clone.
* One Key defines basic parameters specific to the entity to display (e.g. rectangle, text, textbox) * Set of optional parameters follw as Key-Value pairs All
$element->move($delta); relative move
$element->moveTo($pos); absolute move
$element->proximity($anotherElement); how close to another element, in which direction as a hash, or undef if overlapping
$element->clone(); returns a clone of the CloudElement
c0bra(Brian Hann)] created Image::WordCloud to generate raster Word Cloud Images. Depends on SDL to determine the dimensions of a word.
Sarah Roberts created HTML::TagCloud to generate HTML Tags. A useful utility creating boxes that link to pages with thumbnail images or a text summary.
Copyright (c) 2025 Saif Ahmed.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This program 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.
