Skip to content

Instantly share code, notes, and snippets.

@nwjlyons
Last active April 5, 2021 20:16
Show Gist options
  • Save nwjlyons/c96495bdcc3003207c74afc134504f4e to your computer and use it in GitHub Desktop.
Save nwjlyons/c96495bdcc3003207c74afc134504f4e to your computer and use it in GitHub Desktop.
Plot points along circumference using Trigonometry
import math
radius = 20
circumference_points_ratios = [(math.cos(degree), math.sin(degree)) for degree in range(360)]
circumference_points = [(x * radius, y * radius) for x, y in circumference_points_ratios]
circumference_points_ints = [(int(x), int(y)) for x, y in circumference_points]
for y in range(-30, 30):
for x in range(-30, 30):
if (x, y) in circumference_points_ints:
print("*", end="")
else:
print(" ", end="")
print()
@nwjlyons
Copy link
Author

nwjlyons commented Apr 5, 2021

$ python circle.py
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                        *************                       
                      ***           ***                     
                    ***               ***                   
                   **                   **                  
                 **                       **                
                **                         **               
                *                           *               
               *                             *              
              *                               *             
             **                               **            
             *                                 *            
            **                                 **           
            *                                   *           
           **                                   **          
           *                                     *          
           *                                     *          
           *                                     *          
           *                                     *          
           *                                     *          
           *                                     **         
           *                                     *          
           *                                     *          
           *                                     *          
           *                                     *          
           *                                     *          
            *                                   *           
            *                                   *           
            **                                 **           
             *                                 *            
             **                               **            
              *                               *             
               *                             *              
               **                           **              
                **                         **               
                  *                       **                
                   **                   **                  
                    ***               ***                   
                      ***           ***                     
                        *************                       
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                           

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment