def box(x, y, size):
# Draw a box at (x, y) with the given size
print(f"Drawing box at ({x}, {y}) with size {size}")
def grid(x, y, size):
if size < 10: # Base case to stop recursion
return
box(x, y, size)
new_size = size / 2
grid(x, y, new_size)
grid(x + new_size, y, new_size)
grid(x, y + new_size, new_size)
grid(x + new_size, y + new_size, new_size)
# Example usage
grid(0, 0, 100)
from pygame import *
from math import *
WHITE = (255, 255, 255)
YELLOW = (255, 255, 0)
def xy(x, y, mag, ang):
x2 = x + cos(radians(ang))*mag
y2 = y - sin(radians(ang))*mag
return (x2, y2)
def star(x,y,size,ang):
poly = []
for a in range(18,360,72):
p = xy(x,y,size,a)
poly.append(p)
x = size * (sin18) /126
draw.polygon(screen, YELLOW, poly)
screen = display.set_mode((800, 600))
running = True
while running:
for evnt in event.get():
if evnt.type == QUIT:
running = False
mx,my = mouse.get_pos()
mb = mouse.get_pressed()
if mb[0]:
star(mx,my, 90, 90)
display.flip()
quit()
# Star Drawing with Pygame
from pygame import *
from math import *
WHITE = (255, 255, 255)
YELLOW = (255, 255, 0)
def xy(x, y, mag, ang):
x2 = x + cos(radians(ang)) * mag
y2 = y - sin(radians(ang)) * mag
return (x2, y2)
def star(x, y, size):
poly = []
for a in range(0, 360, 72):
p = xy(x, y, size, a)
poly.append(p)
draw.polygon(screen, YELLOW, poly)
screen = display.set_mode((800, 600))
running = True
while running:
for evnt in event.get():
if evnt.type == QUIT:
running = False
mx, my = mouse.get_pos()
mb = mouse.get_pressed()
if mb[0]:
star(mx, my, 90)
display.flip()
quit()