<gh_stars>0
from turtle import Turtle, Screen
from typing import List, Tuple
import random
import colorgram

### TURTLE GRAPHICS

WIDTH = 900
HEIGHT = 600

BACKGROUND = 'black'
TURTLE_COLOR = 'white'

def random_color():
    rgb = tuple([random.randint(0, 255) for x in range(0, 3)])
    return rgb

def random_moves(pen: Turtle, screen: Screen, max:int):
    screen.colormode(255)
    pen.pensize(10)
    for _ in range(0, 1000):
        screenheight, screenwidth = screen.window_height(), screen.window_width()
        xcor = random.randint(-(screenwidth/2), screenwidth/2)
        ycor = random.randint(-(screenheight/2), screenheight/2)
        rgb = random_color()
        pen.pencolor(rgb)
        pen.goto(xcor, ycor)

def draw_square(pen, side:int):
    pen.forward(side)
    for _ in range(3):
        pen.left(90)
        pen.forward(side)

def dashed_lines(pen: Turtle, length: int, dash_width: int):
    pen.pensize(10)
    dash = False
    for _ in range(round(length / dash_width)):
        if (dash):
            pen.penup()
        else:
            pen.pendown()
        dash = not dash
        pen.forward(dash_width)

def random_walk(pen: Turtle, total_walks: int, step=30):
    pen.pensize(10)
    pen.speed(8)
    moves = [pen.forward, pen.backward]
    rots = [pen.right, pen.left]
    angles = [90, 180, -90, -180]
    
    for _ in range(total_walks):
        rgb = random_color()
        pen.pencolor(rgb)
        random.choice(moves)(step)
        random.choice(rots)(random.choice(angles))

def draw_spirograph(size_of_gap: int):
    for _ in range(int(360 / size_of_gap)):
        box.pencolor(random_color())
        box.setheading(box.heading() + size_of_gap)
        box.circle(radius=100)

def spot_painting(pen, screensize: Tuple, num_of_dots=260, x_count=20, step=50):
    
    colors = [[230, 215, 101], [234, 246, 242], [154, 80, 38],[244, 231, 236], [207, 159, 105], [181, 175, 18], 
            [108, 165, 210], [25, 91, 160], [106, 176, 124], [194, 91, 105], [13, 37, 97], [72, 43, 23], [50, 121, 23], [187, 133, 150], [94, 192, 47], [106, 32, 54], [195, 94, 75], [25, 97, 25], [100, 120, 169], [180, 206, 170], [250, 169, 173], [24, 53, 110], [251, 171, 163], [149, 191, 244], [104, 60, 18], [81, 30, 46], [132, 79, 90], [18, 75, 105]]

    screenheight, screenwidth = screensize
    pen.penup()
    pen.goto(-1*(screenwidth/2) + 10, -1*(screenheight/2) + 10)

    num_of_dots = 260
    x_count = 20
    step = 50

    pen.pensize(10)
    pen.speed('fastest')
    for x in range(1, num_of_dots+1):

        pen.dot(20, random.choice(colors))
        pen.forward(step)

        if (x % x_count == 0):
            pen.setheading(90)
            pen.forward(step)
            pen.setheading(180)
            pen.forward(step * x_count)
            pen.setheading(0)


        
    

box = Turtle()
# triangle = Turtle('triangle')

box.color(TURTLE_COLOR)
# triangle.color(TURTLE_COLOR)

box.shape("turtle")
# box.shape("triangle")

screen = Screen()
screen.colormode(255)
screen.setup(WIDTH, HEIGHT) # size of the screen
screen.title("Box")
screen.bgcolor(BACKGROUND)
# custom shape
# screen.addshape("triangle", ((5,-3), (0,5), (-5,-3)))
# screen size
screenheight, screenwidth = screen.window_height(), screen.window_width()
####


# random_moves(box, screen, 1000)
# draw_square(box, 200)
# dashed_lines(box, 400, 20)
# random_walk(box, 1000)

# spirograph
# box.pensize(3)
# box.speed(10)
# draw_spirograph(20)

# spot painting
# colors = colorgram.extract('./day-18/spotpainting.jpg', 30)
# colors = [list(color.rgb) for color in colors]

spot_painting(box, (screenheight, screenwidth))

####    
# blocking code
screen.exitonclick()
from turtle import Turtle, Screen
from typing import List, Tuple
import random
import colorgram

### TURTLE GRAPHICS

WIDTH = 900
HEIGHT = 600

BACKGROUND = 'black'
TURTLE_COLOR = 'white'

def random_color():
    rgb = tuple([random.randint(0, 255) for x in range(0, 3)])
    return rgb

def random_moves(pen: Turtle, screen: Screen, max:int):
    screen.colormode(255)
    pen.pensize(10)
    for _ in range(0, 1000):
        screenheight, screenwidth = screen.window_height(), screen.window_width()
        xcor = random.randint(-(screenwidth/2), screenwidth/2)
        ycor = random.randint(-(screenheight/2), screenheight/2)
        rgb = random_color()
        pen.pencolor(rgb)
        pen.goto(xcor, ycor)

def draw_square(pen, side:int):
    pen.forward(side)
    for _ in range(3):
        pen.left(90)
        pen.forward(side)

def dashed_lines(pen: Turtle, length: int, dash_width: int):
    pen.pensize(10)
    dash = False
    for _ in range(round(length / dash_width)):
        if (dash):
            pen.penup()
        else:
            pen.pendown()
        dash = not dash
        pen.forward(dash_width)

def random_walk(pen: Turtle, total_walks: int, step=30):
    pen.pensize(10)
    pen.speed(8)
    moves = [pen.forward, pen.backward]
    rots = [pen.right, pen.left]
    angles = [90, 180, -90, -180]
    
    for _ in range(total_walks):
        rgb = random_color()
        pen.pencolor(rgb)
        random.choice(moves)(step)
        random.choice(rots)(random.choice(angles))

def draw_spirograph(size_of_gap: int):
    for _ in range(int(360 / size_of_gap)):
        box.pencolor(random_color())
        box.setheading(box.heading() + size_of_gap)
        box.circle(radius=100)

def spot_painting(pen, screensize: Tuple, num_of_dots=260, x_count=20, step=50):
    
    colors = [[230, 215, 101], [234, 246, 242], [154, 80, 38],[244, 231, 236], [207, 159, 105], [181, 175, 18], 
            [108, 165, 210], [25, 91, 160], [106, 176, 124], [194, 91, 105], [13, 37, 97], [72, 43, 23], [50, 121, 23], [187, 133, 150], [94, 192, 47], [106, 32, 54], [195, 94, 75], [25, 97, 25], [100, 120, 169], [180, 206, 170], [250, 169, 173], [24, 53, 110], [251, 171, 163], [149, 191, 244], [104, 60, 18], [81, 30, 46], [132, 79, 90], [18, 75, 105]]

    screenheight, screenwidth = screensize
    pen.penup()
    pen.goto(-1*(screenwidth/2) + 10, -1*(screenheight/2) + 10)

    num_of_dots = 260
    x_count = 20
    step = 50

    pen.pensize(10)
    pen.speed('fastest')
    for x in range(1, num_of_dots+1):

        pen.dot(20, random.choice(colors))
        pen.forward(step)

        if (x % x_count == 0):
            pen.setheading(90)
            pen.forward(step)
            pen.setheading(180)
            pen.forward(step * x_count)
            pen.setheading(0)


        
    

box = Turtle()
# triangle = Turtle('triangle')

box.color(TURTLE_COLOR)
# triangle.color(TURTLE_COLOR)

box.shape("turtle")
# box.shape("triangle")

screen = Screen()
screen.colormode(255)
screen.setup(WIDTH, HEIGHT) # size of the screen
screen.title("Box")
screen.bgcolor(BACKGROUND)
# custom shape
# screen.addshape("triangle", ((5,-3), (0,5), (-5,-3)))
# screen size
screenheight, screenwidth = screen.window_height(), screen.window_width()
####


# random_moves(box, screen, 1000)
# draw_square(box, 200)
# dashed_lines(box, 400, 20)
# random_walk(box, 1000)

# spirograph
# box.pensize(3)
# box.speed(10)
# draw_spirograph(20)

# spot painting
# colors = colorgram.extract('./day-18/spotpainting.jpg', 30)
# colors = [list(color.rgb) for color in colors]

spot_painting(box, (screenheight, screenwidth))

####    
# blocking code
screen.exitonclick()
### TURTLE GRAPHICS # triangle = Turtle('triangle') # triangle.color(TURTLE_COLOR) # box.shape("triangle") # size of the screen # custom shape # screen.addshape("triangle", ((5,-3), (0,5), (-5,-3))) # screen size #### # random_moves(box, screen, 1000) # draw_square(box, 200) # dashed_lines(box, 400, 20) # random_walk(box, 1000) # spirograph # box.pensize(3) # box.speed(10) # draw_spirograph(20) # spot painting # colors = colorgram.extract('./day-18/spotpainting.jpg', 30) # colors = [list(color.rgb) for color in colors] #### # blocking code