void Path(Painter& sw) { sw.Translate(52, 52); for(int i = 0; i < 2; i++) { sw.Rectangle(20, 20, 60, 60); sw.Move(0, 0); sw.Cubic(99, 0, 50, 50, 99, 99); sw.Cubic(0, 99, 50, 50, 0, 0); sw.EvenOdd(i).Fill(Green()); sw.Stroke(1, Black()); sw.Translate(120, 0); } }
void Div(Painter& sw) { sw.Character(100, 100, 'O', Arial(100)) .Character(100, 150, 'O', Arial(100)) .Fill(Black()); sw.Translate(200, 0); sw.Character(100, 100, 'O', Arial(100)) .Div() .Character(100, 150, 'O', Arial(100)) .Fill(Black()); }
void Paint(Painter& Painter, Portfolio& Portfolio) { /*For this example, we'll move the origin to the center to make things a little easier to see. The most important thing to know is that by default Belle uses the bottom-left corner of the canvas as the origin and not the top-left corner (with reversed y) as many graphics libraries do. While this is a bit unconventional, it allows for the x and y dimensions to be treated the same and makes for clearer code.*/ Painter.Translate(Dimensions / 2.0); //Draw a silhouette of the untransformed shape. DrawShape(Painter, Colors::gray, Colors::lightgray); //For each page show a different example of using affine transformations. switch(Painter.GetPageNumber()) { case 0: //Page 1 //Just show the gray coordinate axis... break; case 1: //Page 2 //Show a translation over 1.3 and up 1.8. Painter.Translate(Vector(1.3, 1.8)); DrawShape(Painter); Painter.Revert(); break; case 2: //Page 3 //Show a rotation of 30 degrees. Painter.Rotate(30.0 * Deg); /*(Deg is just a unit that converts degrees to radians when multiplying and radians to degress when dividing).*/ DrawShape(Painter); Painter.Revert(); break; case 3: //Page 4 //Show a scaling of 1.5. Painter.Scale(1.5); DrawShape(Painter); Painter.Revert(); break; case 4: //Page 5 /*Scaling and translating is not the same as translating and scaling. This is related to the fact that matrix multiplication is not generally commutative.*/ Painter.Translate(Vector(1, 1)); //Translate-scale Painter.Scale(2.0); DrawShape(Painter, Colors::green); Painter.Revert(2); /*(Revert defaults to undoing one transformation, but you can specify any number of previous transformations to revert at once.)*/ Painter.Scale(2.0); //Scale-translate Painter.Translate(Vector(1, 1)); DrawShape(Painter, Colors::red); Painter.Revert(2); break; case 5: //Page 6 /*For the same underlying reason, rotating and translating is not the same as translating and rotating.*/ Painter.Translate(Vector(1, 1)); //Translate-rotate Painter.Rotate(30.0 * Deg); DrawShape(Painter, Colors::green); Painter.Revert(2); Painter.Rotate(30.0 * Deg); //Rotate-translate Painter.Translate(Vector(1, 1)); DrawShape(Painter, Colors::red); Painter.Revert(2); break; case 6: //Page 7 //However, scaling and rotation happen to be commutative. Painter.Scale(2.0); //Scale-rotate Painter.Rotate(30.0 * Deg); DrawShape(Painter, Colors::green); Painter.Revert(2); Painter.Rotate(30.0 * Deg); //Rotate-scale Painter.Scale(2.0); DrawShape(Painter, Colors::green); Painter.Revert(2); break; case 7: //Page 8 /*Occasionally, one may find a need to scale by different amounts in the x- and y- dimensions. This is typically done to create a mirror image.*/ Painter.Scale(Vector(-1.0, 1.0)); //Horizontal mirror DrawShape(Painter, Colors::lightgreen); Painter.Revert(); DrawShape(Painter, Colors::green); //Original break; case 8: //Page 9 { /*You can also create an affine transformation using the Affine object, and call Transform with the object. The TranslateScaleRotate method on Affine can be used to position an object at a given size and angle. It is equivalent to multiplying by a Translate, Scale, and Rotate in that order (though the scale and rotation order could be flipped per the result shown on page 7).*/ Affine a = Affine::TranslateScaleRotate(Vector(1, 1), 2.0, 30.0 * Deg); Painter.Transform(a); DrawShape(Painter, Colors::green); Painter.Revert(); Affine b = (Affine::Translate(Vector(1, 1)) * Affine::Scale(2.0)) * Affine::Rotate(30.0 * Deg); Painter.Transform(b); DrawShape(Painter, Colors::green); Painter.Revert(); Painter.Translate(Vector(1, 1)); Painter.Scale(2.0); Painter.Rotate(30.0 * Deg); DrawShape(Painter, Colors::green); Painter.Revert(3); } break; case 9: //Page 10 /*You can easily change units from the default inches to another unit. The following creates a horizontal unit-sized vector in Centimeters and converts that to Inches. The x-component is thus the relative scale.*/ Painter.Scale(Inches(Centimeters(1.0, 0.0)).x); DrawShape(Painter); Painter.Revert(); break; } Painter.Revert(); //Revert the page centering transformation. }