• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.10.1/pyobjc-45/2.6/pyobjc/pyobjc-framework-Quartz/Examples/Programming with Quartz/BasicDrawing/
1from Quartz import *
2import math
3import Utilities
4
5def doRotatedEllipses(context):
6    totreps = 144
7    tint = 1.0
8    tintIncrement = 1.0/totreps
9    # Create a new transform consisting of a 45 degrees rotation.
10    theTransform = CGAffineTransformMakeRotation(math.pi/4)
11    # Apply a scale to the transform just created.
12    theTransform = CGAffineTransformScale(theTransform, 1, 2)
13    # Place the first ellipse at a good location.
14    CGContextTranslateCTM(context, 100.0, 100.0)
15
16    for i in range(totreps):
17        # Make a snapshot the coordinate system.
18        CGContextSaveGState(context)
19        # Set up the coordinate system for the rotated ellipse.
20        CGContextConcatCTM(context, theTransform)
21        CGContextBeginPath(context)
22        CGContextAddArc(context, 0.0, 0.0, 45.0, 0.0, 2*math.pi, 0);
23        # Set the fill color for this instance of the ellipse.
24        CGContextSetRGBFillColor(context, tint, 0.0, 0.0, 1.0)
25        CGContextDrawPath(context, kCGPathFill)
26        # Restore the coordinate system to that of the snapshot.
27        CGContextRestoreGState(context)
28        # Compute the next tint color.
29        tint -= tintIncrement
30        # Move over by 1 unit in x for the next ellipse.
31        CGContextTranslateCTM(context, 1.0, 0.0)
32
33def drawSkewedCoordinateSystem(context):
34    # alpha is 22.5 degrees and beta is 15 degrees.
35    alpha = math.pi/8
36    beta = math.pi/12
37    # Create a rectangle that is 72 units on a side
38    # with its origin at (0,0).
39    r = CGRectMake(0, 0, 72, 72)
40
41    CGContextTranslateCTM(context, 144, 144)
42    # Draw the coordinate axes untransformed.
43    Utilities.drawCoordinateAxes(context)
44    # Fill the rectangle.
45    CGContextFillRect(context, r)
46
47    # Create an affine transform that skews the coordinate system,
48    # skewing the x-axis by alpha radians and the y-axis by beta radians.
49    skew = CGAffineTransformMake(1, math.tan(alpha), math.tan(beta), 1, 0, 0)
50    # Apply that transform to the context coordinate system.
51    CGContextConcatCTM(context, skew)
52
53    # Set the fill and stroke color to a dark blue.
54    CGContextSetRGBStrokeColor(context, 0.11, 0.208, 0.451, 1)
55    CGContextSetRGBFillColor(context, 0.11, 0.208, 0.451, 1)
56
57    # Draw the coordinate axes again, now transformed.
58    Utilities.drawCoordinateAxes(context)
59    # Set the fill color again but with a partially transparent alpha.
60    CGContextSetRGBFillColor(context, 0.11, 0.208, 0.451, 0.7)
61    # Fill the rectangle in the transformed coordinate system.
62    CGContextFillRect(context, r)
63