Two-Dimensional Graphics Elements

Basic two-dimensional graphics elements.

Here is a line primitive:

sawline=Line[Table[{n,(-1)^n},{n,6}]]

This shows the line as a two-dimensional graphics object:

sawgraph=Graphics[sawline]

This redisplays the line, with axes added:

Show[%,Axes->True]

You can combine graphics objects that you have created explicitly from graphics primitives with ones that are produced by functions like (RefLink[Plot, paclet:ref/Plot]).

This produces an ordinary Wolfram System plot:

Plot[Sin[Pi x],{x,0,6}]

This combines the plot with the sawtooth picture made above:

Show[%,sawgraph]

You can combine different graphical elements simply by giving them in a list. In two-dimensional graphics, the Wolfram System will render the elements in exactly the order you give them. Later elements are therefore effectively drawn on top of earlier ones.

Here are two blue (RefLink[Rectangle, paclet:ref/Rectangle]) graphics elements:

{Blue, Rectangle[{1,-1},{2,-0.6}],Rectangle[{4,.3},{5,.8}]}

This draws the rectangles on top of the line that was defined above:

Graphics[{sawline,%}]

The (RefLink[Polygon, paclet:ref/Polygon]) graphics primitive takes a list of x, y coordinates, corresponding to the corners of a polygon. The Wolfram System joins the last corner with the first one, and then fills the resulting area.

Here are the coordinates of the corners of a regular pentagon:

pentagon=Table[{Sin[2 Pi n/5],Cos[2 Pi n/5]},{n,5}]

This displays the pentagon. With the default choice of aspect ratio, the pentagon looks somewhat squashed:

Graphics[Polygon[pentagon]]

Primitives which can take multiple elements.

A large number of points can be represented by putting a list of coordinates inside of a single (RefLink[Point, paclet:ref/Point]) primitive. Similarly, a large number of lines or polygons can be represented as a list of coordinate lists. This representation is efficient and can generally be rendered more quickly by the Wolfram System front end. Graphics directives such as (RefLink[RGBColor, paclet:ref/RGBColor]) apply uniformly to the entire set of primitives.

This creates a multipolygon based upon the set of coordinates defined previously:

Graphics[Polygon[{pentagon, 1+.5pentagon, 1.5+.2pentagon}]]

Here is a multipoint that is colored blue:

Graphics[{Blue,Point[Table[{x,Cos[x]},{x,-6,6,.2}]]},Axes->True]

Circles and disks.

This shows two circles with radius 2:

Graphics[{Circle[{0,0},2],Circle[{1,1},2]}]

This shows a sequence of disks with progressively larger semiaxes in the x direction, and progressively smaller ones in the y direction:

Graphics[Table[Disk[{3n,0},{n/4,2-n/4}],{n,4}]]

The Wolfram System allows you to generate arcs of circles and segments of ellipses. In both cases, the objects are specified by starting and finishing angles. The angles are measured counterclockwise in radians with zero corresponding to the positive x direction.

This draws a 149° wedge centered at the origin:

Graphics[Disk[{0,0},1,{0,140 Degree}]]

Raster-based graphics elements.

Here is a 4×4 array of values between 0 and 1:

modtab=Table[Mod[i,j]/3,{i,4},{j,4}]//N

This uses the array of values as gray levels in a raster:

Graphics[Raster[modtab]]

This shows two overlapping copies of the raster:

Graphics[{Raster[modtab,{{0,0},{2,2}}],Raster[modtab,{{1.5,1.5},{3,2}}]}]

The (RefLink[ColorFunction, paclet:ref/ColorFunction]) option can be used to change the default way in which a (RefLink[Raster, paclet:ref/Raster]) is colored:

Graphics[{Raster[modtab,ColorFunction->Hue]}]