| McNeel Wiki | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| edit · print · help · all topics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Main Pages
Languages
|
The general syntax for Drawing Geometric PrimitivesRhPicture supports the drawing and filling of several geometric primitives, and the function calls are all very similar. All Draw**** methods can be used to draw the outlines of geometry and they accept (apart from the essential data that defines the primitive) either a GDIPen object or a GDIColor + Width combo. All Fill**** methods can be used to paint the contents of geometry and they accept either a GDIBrush object or a single GDIColor .
When drawing geometry you have to use the Image coordinate system. This is a floating point system which is infinite in all directions (though large numbers can cause overflow errors). The origin of the system is located at the upper-left pixel (0,0) and every system unit represents a single pixel. The highest value on the bitmap is (width-1, height-1) and everything drawn beyond this will not be visible.
It is possible in GDI+ to apply a linear transformation to a drawing pipeline, but this feature has not yet been exposed in the RhPicture plugin.
Drawing lines, polylines and curvesLines, polylines and curves are essentially defined by an array of 2D bitmap coordinates. Drawing lines is the simplest example since it doesn't involve variable arrays:
Dim RhPicture : Set RhPicture = Rhino.GetPluginObject("RhPicture")
Call RhPicture.CreateImage(50, 50, vbWhite)
Call RhPicture.DrawLine(Array(10, 30), Array(40, 10), vbBlack, 4)
Polylines and curves take an array of 2D points instead of two singular coordinates. When the distance between the first and last point in the array is less than one tenth of a pixel, the polyline/curve is considered closed and no end caps will be drawn. When drawing line geometry, one can also use GDI Pen objects :
RhPicture.DrawLine(A As Point, B As Point, Col As GDIColor [, Width As Double]) RhPicture.DrawLine(A As Point, B As Point, Pen As GDIPen) RhPicture.DrawPolyline(Pts() As Point, Col As GDIColor [, Width As Double]) RhPicture.DrawPolyline(Pts() As Point, Pen As GDIPen) RhPicture.DrawCurve(Pts() As Point, Col As GDIColor [, Width As Double]) RhPicture.DrawCurve(Pts() As Point, Pen As GDIPen)
Note! The current version of the plugin does not accept variables which are declared as arrays. You have to box these before calling procedures like DrawPolyline(): Dim vertices() 'Create a polyline vertex array here Dim v : v = vertices Call RhPicture.DrawPolyline(v, vbBlack)
Drawing the content of polylines and curves requires the same coordinates but the functions are called differently:
RhPicture.FillPolyline(Pts() As Point, Col As GDIColor) RhPicture.FillPolyline(Pts() As Point, Brush As GDIBrush) RhPicture.FillCurve(Pts() As Point, Col As GDIColor) RhPicture.FillCurve(Pts() As Point, Brush As GDIBrush)
If the coordinates do not define a closed shape, the shape will be closed with a single linear segment. Instead of GDIPen objects, Fill routines accept GDIBrush objects.
Drawing primitivesYou can also draw rectangles, circles and ellipses directly. They work similar to the other drawing methods. Note the difference in coordinate specification between ellipses and circles though:
RhPicture.DrawRectangle(Corner As Point, Width As Double, Height As Double, Col As GDIColor [, Width As Double]) RhPicture.DrawRectangle(Corner As Point, Width As Double, Height As Double, Pen As GDIPen) RhPicture.DrawEllipse(Corner As Point, Width As Double, Height As Double, Col As GDIColor [, Width As Double]) RhPicture.DrawEllipse(Corner As Point, Width As Double, Height As Double, Pen As GDIPen) RhPicture.DrawCircle(Center As Point, Radius As Double, Col As GDIColor [, Width As Double]) RhPicture.DrawCircle(Center As Point, Radius As Double, Pen As GDIPen)
and...
RhPicture.FillRectangle(Corner As Point, Width As Double, Height As Double, Col As GDIColor) RhPicture.FillRectangle(Corner As Point, Width As Double, Height As Double, Brs As GDIBrush) RhPicture.FillEllipse(Corner As Point, Width As Double, Height As Double, Col As GDIColor) RhPicture.FillEllipse(Corner As Point, Width As Double, Height As Double, Brs As GDIBrush) RhPicture.FillCircle(Center As Point, Radius As Double, Col As GDIColor) RhPicture.FillCircle(Center As Point, Radius As Double, Brs As GDIBrush)
Drawing StringsText is drawn using a single overloaded method:
RhPicture.DrawString(Text As String, Pt As Point) RhPicture.DrawString(Text As String, Pt As Point, F as GDIFont) RhPicture.DrawString(Text As String, Pt As Point, F as GDIFont, Col As GDIColor [, Angle As Double]) RhPicture.DrawString(Text As String, Pt As Point, F as GDIFont, Brs As GDIBrush [, Angle As Double]) RhPicture.DrawString(Text As String, Pt As Point, FontName as String) RhPicture.DrawString(Text As String, Pt As Point, FontName as String, Col As GDIColor [, Angle As Double]) RhPicture.DrawString(Text As String, Pt As Point, FontName as String, Brs As GDIBrush [, Angle As Double])
Drawing ImagesIt's also possible to draw images on top of other images. This allows for a number of possibilities which are not possible with texture brushes:
There are two distinct ways of drawing images in the RhPicture plugin. The simplest one is very similar to drawing rectangles, except of brushes you have to supply the path to an image file on the disk:
RhPicture.DrawImage(FileName As String) RhPicture.DrawImage(FileName As String, Corner As Point [, Width [, Height [, Quality [, Alpha [, Mask]]]]])
The second way of drawing images is to use the Merge methods in RhPicture. Rather than pasting the new image on top of the old one the Merge method performs a per-pixel comparison and the final result is usually a combination of the input pixels. This means that the overlay image cannot be drawn in a different size since that would break the 1-to-1 pixel relationship between the images. You can however specify the upper-left corner of the overlay and the blending mode to be used:
RhPicture.Merge(Other As RhPicture [, Style As Integer [, Corner As Point]]) RhPicture.Merge(FileName As String [, Style As Integer [, Corner As Point]])
As you can see you either use an existing image file on the disk or another (not the same, NEVER the same!) instance of the RhPicture plugin. I'll explain the blendings styles per example. We'll be merging image B with image A:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rename · changes · history · subscriptions · lost and found · references · file upload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||