Created
          June 2, 2015 16:27 
        
      - 
      
- 
        Save adusak/97c7fbea980448333b4a to your computer and use it in GitHub Desktop. 
    Examples of linear transformations
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from python.common.polygon import Polygon | |
| from python.common.svg import Svg | |
| from python.less9.transformations import * | |
| def transform(transformation, polygon, repeats, name="trans"): | |
| _svg = Svg() | |
| for i in range(repeats): | |
| for _line in polygon.lines(): | |
| _svg.add_line(_line) | |
| polygon.apply_transformation(transformation) | |
| _svg.save(name) | |
| def uk1(): | |
| pol = Polygon([(0, 1), (1, 1), (1, 0), (0, 0), (0, 1)]) | |
| pol.apply_transformation(scaling(300, 300)) | |
| trans = combine(translation(5, 10), scaling(1.1, 1.1), rotation(20)) | |
| transform(trans, pol, 11, "uk1") | |
| def uk2(): | |
| pol = Polygon([(-1, 1), (1, 1), (1, -1), (-1, -1), (-1, 1)]) | |
| pol.apply_transformation(scaling(300, 300)) | |
| trans = combine(scaling(1.1, 0.8), rotation(10)) | |
| transform(trans, pol, 15, "uk2") | |
| def uk3(): | |
| pol = Polygon([(-1, 1), (1, 1), (1, -1), (-1, -1), (-1, 1)]) | |
| pol.apply_transformation(scaling(50, 50)) | |
| trans = combine(translation(50, 50), scaling(0.9, 0.9), rotation(10), shear(1.3)) | |
| transform(trans, pol, 25, "uk3") | |
| uk1() | |
| uk2() | |
| uk3() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment