import drawsvg as dw
import random
# Function to create a random gradient
def random_gradient():
gradient = dw.LinearGradient(
random.uniform(-500, 1500), 0,
random.uniform(-500, 1500), 0
)
gradient.add_stop(0, 'rgb({},{},{})'.format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
gradient.add_stop(1, 'rgb({},{},{})'.format(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)))
return gradient
# Create the main drawing
d = dw.Drawing(1000, 1000, origin='center')
# Create a horizontal gradient for the background
bg_gradient = dw.LinearGradient(0, 0, 1000, 0)
bg_gradient.add_stop(0, 'white')
bg_gradient.add_stop(1, 'lightgreen')
background = dw.Rectangle(-500, -500, 1000, 1000, fill=bg_gradient)
d.append(background)
# Function to generate a random path with rounded corners
def random_path():
path = dw.Path(fill=random_gradient(), stroke='black', stroke_width=1)
start_x, start_y = random.uniform(-400, 400), random.uniform(-400, 400)
path.M(start_x, start_y)
for _ in range(random.randint(3, 8)): # Random number of points
x, y = random.uniform(-400, 400), random.uniform(-400, 400)
path.L(x, y)
path.Z()
return path
# Keep track of the area covered by shapes
covered_area = 0
total_area = 1000 * 1000
# Generate shapes until at least 10% of the background is visible
while covered_area / total_area < 0.9:
shape = random_path()
d.append(shape)
# Estimate covered area by assuming each shape is approximately 100x100 in size
covered_area += 100 * 100
# Save the SVG file
d.setPixelScale(1) # Set scale to 1:1
d.saveSvg('random_shapes_with_gradient.svg')
import drawsvg as draw
import math
# Create a new drawing
d = draw.Drawing(1000, 1000, origin='center', displayInline=False)
# Create a gradient for the sunset sky
gradient = draw.LinearGradient(0, 500, 0, -500)
gradient.add_stop(0, 'darkred')
gradient.add_stop(0.1, 'red')
gradient.add_stop(0.3, 'orange')
gradient.add_stop(0.6, 'yellow')
gradient.add_stop(1, 'lightblue')
# Draw the sky rectangle with the gradient
sky = draw.Rectangle(-500, 0, 1000, 500, fill=gradient)
d.append(sky)
# Create a hill using a path
hill = draw.Path(fill='darkgreen', stroke_width=0)
hill.M(-500, -350)
hill.q(250, 100, 500, 0)
hill.q(250, -100, 500, 0)
hill.L(-500, -500)
hill.Z()
d.append(hill)
# Add trees to the hill
for i in range(-450, 451, 100):
tree_trunk = draw.Rectangle(i+10, -350, 10, 50, fill='saddlebrown')
tree_crown = draw.Circle(i+15, -280, 30, fill='darkgreen')
d.append(tree_trunk)
d.append(tree_crown)
# Add houses to the hill
for i in range(-400, 401, 200):
# House body
house_body = draw.Rectangle(i, -350, 80, 60, fill='burlywood')
d.append(house_body)
# House roof
house_roof = draw.Lines(i, -290, i+40, -250, i+80, -290, close=True, fill='maroon')
d.append(house_roof)
# Save the SVG file
d.save_svg('gpt-shapes.svg') # save *.svg file
d