papyrus logo

Polylines

A polyline is drawn as a set of ordered vertices relative to the shape's x,y coordinate.

Polylines may be filled or unfilled. An unfilled polyline is more conceptually familiar with what is implied by a polyline. A filled polyline is essentially an unclosed polygon.

The following contains an example that will add an unfilled polygon to a canvas. The blue lines represent the x and y axes, and show through since an alpha value of 0.9 is used.

polyline.png

Unfilled Polyline drawn by example code below

void add_polyline_unfilled( Papyrus::Canvas::pointer canvas ) {
  // Create a polyline that will form a Z
  Papyrus::Polyline::pointer polyline = Papyrus::Polyline::create();

  // Add the polyline to the canvas
  canvas->add( polyline );

  // To color the lines of a polyline shape, set the stroke paint
  polyline->set_stroke( Papyrus::RGBA(1.0, 0.0, 1.0, 0.9) );
  
  // Set a line width
  polyline->stroke()->set_width(10);

  // Add the four points of the Z (upper left, upper right, lower left, lower right)
  polyline->add_vertex( -50, -50 );
  polyline->add_vertex(  50, -50 );
  polyline->add_vertex( -50,  50 );
  polyline->add_vertex(  50,  50 );

}

The following illustrates the effects of filling a polyline.

polyline_filled.png

Filled Polyline drawn by example code below

void add_polyline_filled( Papyrus::Canvas::pointer canvas ) {
  // Create a filled polyline that will form a U
  Papyrus::Polyline::pointer polyline = Papyrus::Polyline::create();

  // Add the polyline to the canvas
  canvas->add( polyline );

  // Set the fill color to red, with an alpha value of 0.9
  polyline->set_fill( Papyrus::RGBA(0.0, 1.0, 1.0, 0.9) );

  // To color the lines of a polyline shape, set the stroke paint
  polyline->set_stroke( Papyrus::RGBA(0.0, 0.0, 0.0, 0.9) );
  
  // Set a line width
  polyline->stroke()->set_width(10);

  // Add the four points of the U (upper left, lower left, lower right, upper right)
  polyline->add_vertex( -50, -50 );
  polyline->add_vertex( -50,  50 );
  polyline->add_vertex(  50,  50 );
  polyline->add_vertex(  50, -50 );

}


Generated on Fri Apr 16 12:41:04 2010 for papyrus by doxygen 1.6.1