from PIL import Image, ImageDraw
import random
# === CONFIG ===
W, H = 32, 32
GRASS_BASE = (34, 139, 34) # base grass color (RGB)
GRASS_VARIATION = 30 # how much to randomly vary each channel
FENCE_COLOR = (200, 0, 0) # red fence
FENCE_THICK = 2 # fence thickness in pixels
# ==============
# Create blank image
img = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(img)
# Paint grass with a little per-pixel variation
for x in range(W):
for y in range(H):
r_base, g_base, b_base = GRASS_BASE
# vary each channel by ±GRASS_VARIATION, clamped to [0..255]
r = max(0, min(255, r_base + random.randint(-GRASS_VARIATION, GRASS_VARIATION)))
g = max(0, min(255, g_base + random.randint(-GRASS_VARIATION, GRASS_VARIATION)))
b = max(0, min(255, b_base + random.randint(-GRASS_VARIATION, GRASS_VARIATION)))
img.putpixel((x, y), (r, g, b))
# Draw fence around the perimeter
for i in range(FENCE_THICK):
# top & bottom rails
draw.line([(0, i), (W-1, i)], fill=FENCE_COLOR)
draw.line([(0, H-1-i), (W-1, H-1-i)], fill=FENCE_COLOR)
# left & right posts
draw.line([(i, 0), (i, H-1)], fill=FENCE_COLOR)
draw.line([(W-1-i, 0), (W-1-i, H-1)], fill=FENCE_COLOR)
# Save or show
img.save("grass_field_with_red_fence.png")
img.show()