Demo entry 6746016

dfsfsf

   

Submitted by anonymous on May 28, 2018 at 08:06
Language: Python 3. Code size: 2.4 kB.

import turtle
import random
from random import randint
import math

def fillSquare(x,y,lineX,lineY,r,g,b):
    turtle.penup()
    turtle.setpos(x,y)
    turtle.pendown()
    turtle.color(r,g,b)
    turtle.begin_fill()
    turtle.forward(lineX)
    turtle.left(90)
    turtle.forward(lineY)
    turtle.left(90)
    turtle.forward(lineX)
    turtle.left(90)
    turtle.forward(lineY)
    turtle.left(90)
    turtle.end_fill()

def drawSquare(x,y,lineX,lineY,col):
    turtle.penup()
    turtle.setpos(x,y)
    turtle.pendown()
    turtle.pencolor(col)
    turtle.begin_fill()
    turtle.forward(lineX)
    turtle.left(90)
    turtle.forward(lineY)
    turtle.left(90)
    turtle.forward(lineX)
    turtle.left(90)
    turtle.forward(lineY)
    turtle.left(90)



def drawChessBoard(width, height, numTilesX, numTilesY,pattern=0):
    offsetToCornerX = (-width / 2)
    offsetToCornerY = (-height / 2)
    squareWidth = (width / numTilesX)
    squareHeight = (height / numTilesY)
    drawSquare(offsetToCornerX-1,offsetToCornerY-1,width+2,height+2,"black")
    for y in range(numTilesY):
        for x in range(numTilesX):
            

            if(pattern == 0):
                r = g = b = 0
                if((x+y)%2==0):
                    r = g = b = 1 

            if(pattern == 1):
                r = math.fabs(offsetToCornerX+(squareWidth*x)) / (width/2)
                g = math.fabs(offsetToCornerY+(squareHeight*y)) / (height/2)
                b = (x+y) / (numTilesX+numTilesY)

            if(pattern == 2):
                r = math.fabs(math.sin(x))
                g = math.fabs(math.cos(y))
                b = math.fabs(math.sin(x+y))

            if(pattern == 3):
                g = math.fabs(offsetToCornerX+(squareWidth*x)) / (width/2)
                b = math.fabs(offsetToCornerY+(squareHeight*y)) / (height/2)
                r = (x+y) / (numTilesX+numTilesY)

            if(pattern == 4):
                r = 0
                g = (x+y) / (numTilesX+numTilesY)
                b = 0
                
            fillSquare(offsetToCornerX+(squareWidth*x),offsetToCornerY+(squareHeight*y),squareWidth,squareHeight,r,g,b)

    turtle.penup()
    turtle.setpos(offsetToCornerX,offsetToCornerY)
    turtle.pendown()

#turtle.ht()
turtle.tracer(1000,0)

drawChessBoard(600,600,120,120,1)


turtle.update()
turtle.exitonclick()

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).