Object Model Reference : Classes : P : PatternCanvas : Methods : PatternCanvas.CopyArea |
Sub CopyArea(x1 As Long, y1 As Long, x2 As Long, y2 As Long, x As Long, y As Long)
Member of PatternCanvas
The CopyArea method copies an area of a pattern canvas, defined by two coordinates, and then moves that area to a new location on the canvas.
The following VBA example creates a windmill pattern by drawing a circle and rotating half of that circle by 90°. It then copies the resulting pattern and rotates the copy by 180°.
Sub Test() |
Dim c As New PatternCanvas |
Dim a As Double, x As Long, y As Long |
c.Size = cdrPatternCanvas64x64 |
c.Clear |
DrawCircle c, 32, 16, 16, True |
c.CopyArea 0, 0, 31, 31, 32, 0 |
c.RotateArea 32, 0, 63, 31, -90 |
c.CopyArea 0, 0, 63, 31, 0, 32 |
c.RotateArea 0, 32, 63, 63, 180 |
With ActiveLayer.CreateRectangle(0, 0, 2, 2) |
.Fill.ApplyPatternFill cdrTwoColorPattern |
.Fill.Pattern.Canvas = c |
End With |
End Sub |
' ==== The following two subroutines draw a circle on a canvas |
Private Sub DrawCircle(c As PatternCanvas, CenterX As Long, CenterY As Long, Radius As Long, Filled As Boolean) |
Dim p As Long, x As Long, y As Long |
x = 0 |
y = Radius |
Plot c, x, y, CenterX, CenterY, Filled |
p = 1 - Radius |
While x < y |
If p < 0 Then |
x = x + 1 |
p = p + 2 * x + 1 |
Else |
x = x + 1 |
y = y - 1 |
p = p + 2 * (x - y) + 1 |
End If |
Plot c, x, y, CenterX, CenterY, Filled |
Wend |
End Sub |
Private Sub Plot(c As PatternCanvas, x As Long, y As Long, cx As Long, cy As Long, Filled As Boolean) |
If Filled Then |
c.Line (cx + x, cy + y)-(cx - x, cy + y) |
c.Line (cx + x, cy - y)-(cx - x, cy - y) |
c.Line (cx + y, cy + x)-(cx - y, cy + x) |
c.Line (cx + y, cy - x)-(cx - y, cy - x) |
Else |
c.PSet (cx + x, cy + y) |
c.PSet (cx - x, cy + y) |
c.PSet (cx + x, cy - y) |
c.PSet (cx - x, cy - y) |
c.PSet (cx + y, cy + x) |
c.PSet (cx - y, cy + x) |
c.PSet (cx + y, cy - x) |
c.PSet (cx - y, cy - x) |
End If |
End Sub |
Copyright 2013 Corel Corporation. All rights reserved.