How To Use Modules In Julia. A quick lesson on how modules and… | by Emmett Boudreau | Oct, 2020


With the fundamentals of using modules in Julia out of the best way, we will now take a look at the module we’re going to be working with right this moment:


Compose is a declarative vector graphics library written in pure Julia that makes it extremely straightforward to functionally draw graphics utilizing just a few parameters and nodes. You can view the Compose documentation on Juliahub right here:

Speaking of which, in case you are new to Julia and utilizing Julia modules, it definitely could be price it to take a look at JuliaHub. JuliaHub is an all-in-one bundle vacation spot for Julia programmers with the documentation readily included and built-in robotically inside the web site. If you wish to be taught extra, I’ve a complete article on how cool it’s!:

Pulling instantly from the Compose documentation, our first instance is easy however will get the purpose throughout:

composition = compose(context(), rectangle(), fill("tomato"))
(Image by writer)

Looking extra into this assertion, the compose() methodology is answerable for returning a composition and takes parameters. These parameters are varieties known as Compose kinds and nodes. Inside of the tactic name, we see the arguments as context(), rectangle(), and fill(). Context is the foundation node, so it may well basically be ignored on this explicit occasion. Next within the arguments is rectangle. This is in fact the sort that’s on show within the rendered picture. The final argument is fill(), which takes a string that represents the title of the specified colour for this whole context().

Fortunately, we will use the ?() methodology on any of those arguments to be taught extra about them. Let’s create extra rectangles! We will begin by seeing what sort of knowledge we will present every time we create the sort:

Rectangle is each able to taking zero arguments, or 4. Four arguments on this regard will likely be positional arguments, the x place of our kind, the y place of our kind, after which the width and top in that order. With this newly discovered info, let’s modify our previous code to alter the scale of the rectangle:

composition = compose(context(), rectangle(.5, .5, 5px, 5px), fill("tomato"))
(Image by writer)

And including extra rectangles:

composition = compose(context(), rectangle(.5, .5, 20px, 20px),
rectangle(.5, .2, 20px, 20px),
rectangle(.5, .8, 20px, 20px),
(Image by writer)


Source hyperlink

Write a comment