Orientation
In our previous tutorial we explored position as a preattentive feature. Specifically, we investigated how to control the location of our shapes through manipulation of the transformation matrix. However, we can do more than just change the origin (0, 0 point) of our coordinate system, we can rotate it as well! In this tutorial, we conclude Skills Lab 3 by looking at our final preattentive feature: orientation.Contents
Rotate
We will start by doing a global rotation. This also changes the transformation matrix. However, give this a run and you might notice a problem.import sketchingpy sketch = sketchingpy.Sketch2D(500, 500) sketch.set_rect_mode('radius') sketch.set_angle_mode('degrees') size = 5 for rotation in range(0, 12): sketch.draw_rect(200, 0, size, size) sketch.rotate(30) size += 5 sketch.show()Our work is off the screen! Try changing the position of the squares.
Rotate and Translate
Using that first sketch as motiviation, it is common to translate prior to rotation to indicate the point around which the rotation should occur.import sketchingpy sketch = sketchingpy.Sketch2D(500, 500) sketch.set_rect_mode('radius') sketch.set_angle_mode('degrees') def draw_at(x, y, color): sketch.push_transform() sketch.push_style() sketch.translate(x, y) sketch.set_fill(color) size = 5 for rotation in range(0, 12): sketch.draw_rect(100, 0, size, size) sketch.rotate(30) size += 2 sketch.pop_style() sketch.pop_transform() sketch.translate(250, 250) draw_at(0, -100, "#1b9e7750") draw_at(-100, 100, "#d95f0250") draw_at(100, 100, "#7570b350") sketch.show()It is also common to push and pop within a function so that you can keep track of what transforms have occurred.
Next
You've reached the end of Skills Lab 3! Continue on to Tutorial 8 which starts Skills Lab 4 to learn about text.Citations
- A. Pottinger, "Sketchingpy." Sketchingpy Project, 2024. [Online]. Available: https://sketchingpy.org/
- C. Brewer, M Harrower, and The Pennsylvania State University, "Colorbrewer 2.0," The Pennsylvania State University, 2013. [Online]. Available: https://colorbrewer2.org/