Python3 Turtle Draw Chess board

Source: Internet
Author: User
Tags goto

Python3 Turtle Draw Chess board

#!/usr/bin/env python#-*-coding:utf-8-*-# author:hiuhung wanimport turtlen = 60 # each line interval x = -300 # x Initial value y =-300 #        X initial value Turtle.speed (one) turtle.pensize (2) # First draw the square of the 8*8, and apply black as required for I in range (8): for J in range (1, 9): Turtle.penup () Turtle.goto (x + i * N, y + J * N) Turtle.pendown () if (i + j)% 2 = = 1: #不涂黑 for index I            N Range (4): Turtle.forward (n) turtle.left (All) elif (i + j)% 2 = = 0: #涂黑 Turtle.begin_fill () Turtle.fillcolor (' black ') for index in range (4): Turtle.forward (n ) Turtle.left (+) Turtle.end_fill () Turtle.penup () # Draw out again two squares x1 = x-n * 0.12y1 = y-n * 0.12 + nturtle.goto (x1, y1) Turtle.pendown () turtle.pensize (4) for index in range (4): Turtle.forward (n * 8 + 2 * n * 0.1 2) Turtle.left (+) Turtle.penup () #-----------------------------------------------x2 = x-n * 0.3y2 = y-n * 0.3 + NTU Rtle.goto (x2, y2) turtle.Pendown () turtle.pensize () for index in range (4): Turtle.forward (n * 8 + 2 * n * 0.3) Turtle.left (+) Turtle.hideturt Le () turtle.done ()

As follows:

Python3 Turtle Draw Chess board

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.