Drawing Chess

1  # Chess 
2  Import Turtle
 . 3 turtle.pensize (. 3 )
 . 4 turtle.screensize (1200,1000)    # canvas size 
. 5 turtle.color ( " Black " , " Black " )  
 . 6 n-= the eval (INPUT ())     # Input a number 
7  
8  turtle.penup ()  
 9 turtle.goto (the n--4 *, * the n-4)      # from the top left corner to start drawing 
10  turtle.pendown ()           
 11 turtle.forward (the n-8 *)        # first draw a large square 
12 is turtle.right (90)          
13 turtle.forward(8*n)
14 turtle.right(90)
15 turtle.forward(8*n)
16 turtle.right(90)
17 turtle.forward(8*n)
18 
19 coordA=[-3*n,-n,n,3*n]    
20 coordB=[4*n,2*n,0,-2*n]
21 
22 for i in range(4):
23     for j in range(4):
24         turtle.penup()
25         turtle.goto(coordA[i],coordB[j])
26         turtle.pendown()
27         turtle.begin_fill()
28         turtle.right(90)
29         turtle.forward(n)
30         turtle.right(90)
31         turtle.forward(n)
32         turtle.right(90)
33         turtle.forward(n)
34         turtle.right(90)
35         turtle.forward(n)
36         turtle.end_fill()
37 
38 coordC=[-4*n,-2*n,0,2*n]
39 coordD=[3*n,n,-n,-3*n]
40 
41 for i in range(4):
42     for j in range(4):
43         turtle.penup()
44         turtle.goto(coordC[i],coordD[j])
45         turtle.pendown()
46         turtle.begin_fill()
47         turtle.right(90)
48         turtle.forward(n)
49         turtle.right(90)
50         turtle.forward(n)
51         turtle.right(90)
52         turtle.forward(n)
53         turtle.right(90)
54         turtle.forward(n)
55         turtle.end_fill()
56 
57 turtle.hideturtle()
International chess

Title: Draw 2020-03-19

Ideas: first draw a large square, the side length N is set to a small square. So that we can find the coordinates of each small square. Start painting, click the idea, here will use two-cycle Oh!

This is a process diagram:

 

This is the result:

 

 Note: From start to finish filling the filling, the need is the starting point and end point are the same. In other words, a closed figure can only be filled, otherwise, it will be filled with all enclosed connection between the graphics of the start and end points. This is also the reason I used this idea.

Thank you for browsing!

 

Guess you like

Origin www.cnblogs.com/xugama/p/12527513.html