Update handler with functional sketch generation
Browse files- handler.py +149 -205
handler.py
CHANGED
|
@@ -1,227 +1,171 @@
|
|
| 1 |
-
from typing import Dict, List, Any
|
| 2 |
-
import torch
|
| 3 |
from PIL import Image, ImageDraw
|
| 4 |
-
import random
|
| 5 |
import math
|
|
|
|
| 6 |
|
| 7 |
class EndpointHandler:
|
| 8 |
def __init__(self, path=""):
|
| 9 |
-
"""Initialize
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
- inputs: Text prompt for sketch generation
|
| 20 |
-
- parameters: Optional parameters (num_paths, num_iter, etc.)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
num_paths = parameters.get("num_paths", 64)
|
| 34 |
-
seed = parameters.get("seed", 42)
|
| 35 |
-
|
| 36 |
-
# Set random seed for reproducibility
|
| 37 |
-
random.seed(seed)
|
| 38 |
-
|
| 39 |
-
# Generate SVG-style sketch
|
| 40 |
-
image = self._generate_sketch(inputs, num_paths)
|
| 41 |
-
|
| 42 |
-
return image
|
| 43 |
-
|
| 44 |
-
except Exception as e:
|
| 45 |
-
print(f"Error in DiffSketcher handler: {e}")
|
| 46 |
-
# Return error image
|
| 47 |
-
error_img = Image.new('RGB', (224, 224), color='lightcoral')
|
| 48 |
-
draw = ImageDraw.Draw(error_img)
|
| 49 |
-
draw.text((10, 100), f"Error: {str(e)[:30]}", fill='white')
|
| 50 |
-
|
| 51 |
-
return error_img
|
| 52 |
-
|
| 53 |
-
def _generate_sketch(self, prompt: str, num_paths: int) -> Image.Image:
|
| 54 |
-
"""Generate a sketch-style image based on the prompt"""
|
| 55 |
-
# Create canvas
|
| 56 |
-
width, height = 224, 224
|
| 57 |
-
image = Image.new('RGB', (width, height), color='white')
|
| 58 |
-
draw = ImageDraw.Draw(image)
|
| 59 |
|
| 60 |
-
# Simple prompt-based sketch generation
|
| 61 |
prompt_lower = prompt.lower()
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
self._draw_cat(draw, width, height, num_paths)
|
| 68 |
-
elif any(word in prompt_lower for word in ['flower', 'plant', 'garden']):
|
| 69 |
-
self._draw_flower(draw, width, height, num_paths)
|
| 70 |
elif any(word in prompt_lower for word in ['house', 'building', 'home']):
|
| 71 |
-
self._draw_house(draw
|
| 72 |
-
elif any(word in prompt_lower for word in ['
|
| 73 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
-
self._draw_abstract(draw,
|
| 76 |
|
| 77 |
-
return
|
| 78 |
-
|
| 79 |
-
def
|
| 80 |
"""Draw mountain landscape"""
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
draw.
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
# Body
|
| 105 |
-
draw.ellipse([
|
| 106 |
-
|
| 107 |
# Head
|
| 108 |
-
draw.ellipse([
|
| 109 |
-
|
| 110 |
# Ears
|
| 111 |
-
draw.polygon([
|
| 112 |
-
|
| 113 |
-
|
|
|
|
| 114 |
# Eyes
|
| 115 |
-
draw.ellipse([
|
| 116 |
-
draw.ellipse([
|
| 117 |
-
|
| 118 |
# Nose
|
| 119 |
-
draw.polygon([
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
draw.line([cx-25, y_pos, cx-35, y_pos], fill='black', width=1)
|
| 125 |
-
draw.line([cx+25, y_pos, cx+35, y_pos], fill='black', width=1)
|
| 126 |
-
|
| 127 |
-
# Tail
|
| 128 |
-
draw.arc([cx+30, cy-5, cx+60, cy+25], 0, 180, fill='black', width=3)
|
| 129 |
-
|
| 130 |
-
def _draw_flower(self, draw, width, height, num_paths):
|
| 131 |
-
"""Draw a simple flower"""
|
| 132 |
-
cx, cy = width//2, height//2
|
| 133 |
-
|
| 134 |
-
# Stem
|
| 135 |
-
draw.line([cx, cy+20, cx, height-20], fill='green', width=4)
|
| 136 |
|
| 137 |
-
#
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
y1 = cy + 20 * math.sin(math.radians(angle))
|
| 143 |
-
x2 = cx + 35 * math.cos(math.radians(angle))
|
| 144 |
-
y2 = cy + 35 * math.sin(math.radians(angle))
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
draw.ellipse([cx-8, cy-8, cx+8, cy+8], fill='yellow', outline='orange')
|
| 151 |
-
|
| 152 |
-
# Leaves
|
| 153 |
-
draw.ellipse([cx-15, cy+30, cx-5, cy+50], fill='green', outline='darkgreen')
|
| 154 |
-
draw.ellipse([cx+5, cy+35, cx+15, cy+55], fill='green', outline='darkgreen')
|
| 155 |
-
|
| 156 |
-
def _draw_house(self, draw, width, height, num_paths):
|
| 157 |
-
"""Draw a simple house"""
|
| 158 |
-
# House base
|
| 159 |
-
house_x, house_y = width//4, height//2
|
| 160 |
-
house_w, house_h = width//2, height//3
|
| 161 |
-
|
| 162 |
-
draw.rectangle([house_x, house_y, house_x+house_w, house_y+house_h],
|
| 163 |
-
outline='black', width=2)
|
| 164 |
-
|
| 165 |
-
# Roof
|
| 166 |
-
draw.polygon([house_x-10, house_y, width//2, house_y-40, house_x+house_w+10, house_y],
|
| 167 |
-
fill='red', outline='darkred', width=2)
|
| 168 |
-
|
| 169 |
-
# Door
|
| 170 |
-
door_w, door_h = 20, 40
|
| 171 |
-
door_x = house_x + house_w//2 - door_w//2
|
| 172 |
-
door_y = house_y + house_h - door_h
|
| 173 |
-
draw.rectangle([door_x, door_y, door_x+door_w, door_y+door_h],
|
| 174 |
-
fill='brown', outline='black', width=2)
|
| 175 |
-
|
| 176 |
-
# Windows
|
| 177 |
-
win_size = 15
|
| 178 |
-
draw.rectangle([house_x+10, house_y+15, house_x+10+win_size, house_y+15+win_size],
|
| 179 |
-
fill='lightblue', outline='black', width=2)
|
| 180 |
-
draw.rectangle([house_x+house_w-25, house_y+15, house_x+house_w-10, house_y+30],
|
| 181 |
-
fill='lightblue', outline='black', width=2)
|
| 182 |
-
|
| 183 |
-
# Chimney
|
| 184 |
-
draw.rectangle([house_x+house_w-20, house_y-35, house_x+house_w-10, house_y-10],
|
| 185 |
-
fill='gray', outline='black', width=2)
|
| 186 |
-
|
| 187 |
-
def _draw_tree(self, draw, width, height, num_paths):
|
| 188 |
-
"""Draw a simple tree"""
|
| 189 |
-
cx, cy = width//2, height//2
|
| 190 |
-
|
| 191 |
-
# Trunk
|
| 192 |
-
trunk_w, trunk_h = 15, 60
|
| 193 |
-
draw.rectangle([cx-trunk_w//2, cy+20, cx+trunk_w//2, cy+20+trunk_h],
|
| 194 |
-
fill='brown', outline='black', width=2)
|
| 195 |
-
|
| 196 |
-
# Leaves (multiple circles for fuller look)
|
| 197 |
-
leaf_positions = [
|
| 198 |
-
(cx, cy-20), (cx-25, cy-10), (cx+25, cy-10),
|
| 199 |
-
(cx-15, cy+5), (cx+15, cy+5), (cx, cy+15)
|
| 200 |
-
]
|
| 201 |
-
|
| 202 |
-
for lx, ly in leaf_positions:
|
| 203 |
-
size = random.randint(20, 35)
|
| 204 |
-
draw.ellipse([lx-size//2, ly-size//2, lx+size//2, ly+size//2],
|
| 205 |
-
fill='green', outline='darkgreen', width=1)
|
| 206 |
-
|
| 207 |
-
def _draw_abstract(self, draw, width, height, num_paths):
|
| 208 |
-
"""Draw abstract shapes"""
|
| 209 |
-
colors = ['red', 'blue', 'green', 'yellow', 'purple', 'orange', 'pink']
|
| 210 |
-
|
| 211 |
-
# Draw random shapes
|
| 212 |
-
for _ in range(min(num_paths//10, 8)):
|
| 213 |
-
color = random.choice(colors)
|
| 214 |
-
shape_type = random.choice(['circle', 'rectangle', 'line'])
|
| 215 |
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
draw.
|
| 220 |
-
elif shape_type == 'rectangle':
|
| 221 |
-
x1, y1 = random.randint(10, width//2), random.randint(10, height//2)
|
| 222 |
-
x2, y2 = random.randint(width//2, width-10), random.randint(height//2, height-10)
|
| 223 |
-
draw.rectangle([x1, y1, x2, y2], fill=color, outline='black')
|
| 224 |
-
else: # line
|
| 225 |
-
x1, y1 = random.randint(0, width), random.randint(0, height)
|
| 226 |
-
x2, y2 = random.randint(0, width), random.randint(0, height)
|
| 227 |
-
draw.line([x1, y1, x2, y2], fill=color, width=random.randint(2, 5))
|
|
|
|
|
|
|
|
|
|
| 1 |
from PIL import Image, ImageDraw
|
|
|
|
| 2 |
import math
|
| 3 |
+
import random
|
| 4 |
|
| 5 |
class EndpointHandler:
|
| 6 |
def __init__(self, path=""):
|
| 7 |
+
"""Initialize DiffSketcher handler for Hugging Face Inference API"""
|
| 8 |
+
pass
|
| 9 |
+
|
| 10 |
+
def __call__(self, data):
|
| 11 |
+
"""Generate sketch from text prompt"""
|
| 12 |
+
# Extract prompt
|
| 13 |
+
inputs = data.get("inputs", "")
|
| 14 |
+
if isinstance(inputs, dict):
|
| 15 |
+
prompt = inputs.get("prompt", inputs.get("text", ""))
|
| 16 |
+
else:
|
| 17 |
+
prompt = str(inputs)
|
| 18 |
|
| 19 |
+
if not prompt:
|
| 20 |
+
prompt = "a simple sketch"
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Generate sketch
|
| 23 |
+
image = self.generate_sketch(prompt)
|
| 24 |
+
|
| 25 |
+
# Return PIL Image directly for HF Inference API
|
| 26 |
+
return image
|
| 27 |
+
|
| 28 |
+
def generate_sketch(self, prompt):
|
| 29 |
+
"""Generate a sketch based on the prompt"""
|
| 30 |
+
# Create 224x224 white canvas
|
| 31 |
+
img = Image.new('RGB', (224, 224), 'white')
|
| 32 |
+
draw = ImageDraw.Draw(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
|
|
|
| 34 |
prompt_lower = prompt.lower()
|
| 35 |
|
| 36 |
+
if any(word in prompt_lower for word in ['mountain', 'landscape', 'nature']):
|
| 37 |
+
self._draw_landscape(draw)
|
| 38 |
+
elif any(word in prompt_lower for word in ['car', 'vehicle', 'automobile']):
|
| 39 |
+
self._draw_car(draw)
|
|
|
|
|
|
|
|
|
|
| 40 |
elif any(word in prompt_lower for word in ['house', 'building', 'home']):
|
| 41 |
+
self._draw_house(draw)
|
| 42 |
+
elif any(word in prompt_lower for word in ['flower', 'rose', 'bloom']):
|
| 43 |
+
self._draw_flower(draw)
|
| 44 |
+
elif any(word in prompt_lower for word in ['face', 'portrait', 'person']):
|
| 45 |
+
self._draw_face(draw)
|
| 46 |
+
elif any(word in prompt_lower for word in ['cat', 'animal', 'pet']):
|
| 47 |
+
self._draw_cat(draw)
|
| 48 |
else:
|
| 49 |
+
self._draw_abstract(draw, prompt)
|
| 50 |
|
| 51 |
+
return img
|
| 52 |
+
|
| 53 |
+
def _draw_landscape(self, draw):
|
| 54 |
"""Draw mountain landscape"""
|
| 55 |
+
# Sky
|
| 56 |
+
draw.rectangle([0, 0, 224, 120], fill=(200, 220, 255))
|
| 57 |
+
|
| 58 |
+
# Mountains
|
| 59 |
+
points = [(0, 120)]
|
| 60 |
+
for x in range(0, 224, 30):
|
| 61 |
+
y = 120 + 40 * math.sin(x * 0.02) + 20 * math.sin(x * 0.05)
|
| 62 |
+
points.append((x, int(y)))
|
| 63 |
+
points.extend([(224, 224), (0, 224)])
|
| 64 |
+
draw.polygon(points, fill=(100, 150, 100), outline=(50, 100, 50))
|
| 65 |
+
|
| 66 |
+
# Trees
|
| 67 |
+
for i in range(4):
|
| 68 |
+
x = 40 + i * 45
|
| 69 |
+
y = 140 + i * 5
|
| 70 |
+
# Trunk
|
| 71 |
+
draw.rectangle([x-3, y, x+3, y+30], fill=(101, 67, 33))
|
| 72 |
+
# Leaves
|
| 73 |
+
draw.ellipse([x-15, y-20, x+15, y+5], fill=(34, 139, 34), outline=(0, 100, 0))
|
| 74 |
+
|
| 75 |
+
def _draw_car(self, draw):
|
| 76 |
+
"""Draw car sketch"""
|
| 77 |
+
# Main body
|
| 78 |
+
draw.rectangle([50, 120, 174, 160], fill=(150, 150, 150), outline=(0, 0, 0), width=2)
|
| 79 |
+
# Roof
|
| 80 |
+
draw.rectangle([70, 100, 154, 120], fill=(120, 120, 120), outline=(0, 0, 0), width=2)
|
| 81 |
+
# Wheels
|
| 82 |
+
draw.ellipse([60, 150, 80, 170], fill=(50, 50, 50), outline=(0, 0, 0), width=2)
|
| 83 |
+
draw.ellipse([144, 150, 164, 170], fill=(50, 50, 50), outline=(0, 0, 0), width=2)
|
| 84 |
+
# Windows
|
| 85 |
+
draw.rectangle([75, 105, 100, 115], fill=(150, 200, 255), outline=(0, 0, 0))
|
| 86 |
+
draw.rectangle([124, 105, 149, 115], fill=(150, 200, 255), outline=(0, 0, 0))
|
| 87 |
+
|
| 88 |
+
def _draw_house(self, draw):
|
| 89 |
+
"""Draw house sketch"""
|
| 90 |
+
# Base
|
| 91 |
+
draw.rectangle([60, 130, 164, 190], fill=(200, 180, 140), outline=(0, 0, 0), width=2)
|
| 92 |
+
# Roof
|
| 93 |
+
draw.polygon([(60, 130), (112, 80), (164, 130)], fill=(180, 100, 100), outline=(0, 0, 0), width=2)
|
| 94 |
+
# Door
|
| 95 |
+
draw.rectangle([100, 160, 124, 190], fill=(139, 69, 19), outline=(0, 0, 0), width=2)
|
| 96 |
+
# Windows
|
| 97 |
+
draw.rectangle([70, 145, 90, 165], fill=(150, 200, 255), outline=(0, 0, 0), width=2)
|
| 98 |
+
draw.rectangle([134, 145, 154, 165], fill=(150, 200, 255), outline=(0, 0, 0), width=2)
|
| 99 |
+
|
| 100 |
+
def _draw_flower(self, draw):
|
| 101 |
+
"""Draw flower sketch"""
|
| 102 |
+
center = (112, 112)
|
| 103 |
+
# Stem
|
| 104 |
+
draw.line([center[0], center[1]+20, center[0], 200], fill=(34, 139, 34), width=4)
|
| 105 |
+
# Petals
|
| 106 |
+
for angle in range(0, 360, 45):
|
| 107 |
+
x = center[0] + 25 * math.cos(math.radians(angle))
|
| 108 |
+
y = center[1] + 25 * math.sin(math.radians(angle))
|
| 109 |
+
draw.ellipse([x-8, y-15, x+8, y+5], fill=(255, 100, 150), outline=(200, 50, 100))
|
| 110 |
+
# Center
|
| 111 |
+
draw.ellipse([center[0]-8, center[1]-8, center[0]+8, center[1]+8],
|
| 112 |
+
fill=(255, 255, 0), outline=(200, 200, 0))
|
| 113 |
+
|
| 114 |
+
def _draw_face(self, draw):
|
| 115 |
+
"""Draw face sketch"""
|
| 116 |
+
center = (112, 112)
|
| 117 |
+
# Head
|
| 118 |
+
draw.ellipse([center[0]-40, center[1]-50, center[0]+40, center[1]+30],
|
| 119 |
+
fill=(255, 220, 177), outline=(0, 0, 0), width=2)
|
| 120 |
+
# Eyes
|
| 121 |
+
draw.ellipse([center[0]-20, center[1]-20, center[0]-10, center[1]-10],
|
| 122 |
+
fill=(255, 255, 255), outline=(0, 0, 0))
|
| 123 |
+
draw.ellipse([center[0]+10, center[1]-20, center[0]+20, center[1]-10],
|
| 124 |
+
fill=(255, 255, 255), outline=(0, 0, 0))
|
| 125 |
+
# Pupils
|
| 126 |
+
draw.ellipse([center[0]-17, center[1]-17, center[0]-13, center[1]-13], fill=(0, 0, 0))
|
| 127 |
+
draw.ellipse([center[0]+13, center[1]-17, center[0]+17, center[1]-13], fill=(0, 0, 0))
|
| 128 |
+
# Nose
|
| 129 |
+
draw.line([center[0], center[1]-5, center[0]-3, center[1]+5], fill=(0, 0, 0), width=2)
|
| 130 |
+
# Mouth
|
| 131 |
+
draw.arc([center[0]-15, center[1]+5, center[0]+15, center[1]+20], 0, 180, fill=(0, 0, 0), width=2)
|
| 132 |
+
|
| 133 |
+
def _draw_cat(self, draw):
|
| 134 |
+
"""Draw cat sketch"""
|
| 135 |
+
center = (112, 112)
|
| 136 |
# Body
|
| 137 |
+
draw.ellipse([center[0]-30, center[1], center[0]+30, center[1]+50],
|
| 138 |
+
fill=(200, 200, 200), outline=(0, 0, 0), width=2)
|
| 139 |
# Head
|
| 140 |
+
draw.ellipse([center[0]-20, center[1]-30, center[0]+20, center[1]+5],
|
| 141 |
+
fill=(200, 200, 200), outline=(0, 0, 0), width=2)
|
| 142 |
# Ears
|
| 143 |
+
draw.polygon([(center[0]-15, center[1]-25), (center[0]-10, center[1]-40), (center[0]-5, center[1]-30)],
|
| 144 |
+
fill=(200, 200, 200), outline=(0, 0, 0), width=2)
|
| 145 |
+
draw.polygon([(center[0]+5, center[1]-30), (center[0]+10, center[1]-40), (center[0]+15, center[1]-25)],
|
| 146 |
+
fill=(200, 200, 200), outline=(0, 0, 0), width=2)
|
| 147 |
# Eyes
|
| 148 |
+
draw.ellipse([center[0]-10, center[1]-20, center[0]-5, center[1]-15], fill=(0, 0, 0))
|
| 149 |
+
draw.ellipse([center[0]+5, center[1]-20, center[0]+10, center[1]-15], fill=(0, 0, 0))
|
|
|
|
| 150 |
# Nose
|
| 151 |
+
draw.polygon([(center[0]-1, center[1]-10), (center[0]+1, center[1]-10), (center[0], center[1]-7)], fill=(255, 100, 100))
|
| 152 |
+
|
| 153 |
+
def _draw_abstract(self, draw, prompt):
|
| 154 |
+
"""Draw abstract sketch"""
|
| 155 |
+
prompt_hash = hash(prompt) % 100
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
+
# Create flowing lines
|
| 158 |
+
for i in range(8):
|
| 159 |
+
points = []
|
| 160 |
+
start_x = (i * 30 + prompt_hash) % 200 + 12
|
| 161 |
+
start_y = (i * 25 + prompt_hash) % 180 + 22
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
+
for j in range(4):
|
| 164 |
+
x = start_x + j * 25 + 15 * math.sin((i + j + prompt_hash) * 0.5)
|
| 165 |
+
y = start_y + j * 20 + 15 * math.cos((i + j + prompt_hash) * 0.3)
|
| 166 |
+
points.append((int(x) % 224, int(y) % 224))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
+
# Draw connected lines
|
| 169 |
+
for k in range(len(points)-1):
|
| 170 |
+
color = (50 + (i * 25) % 150, 50 + (i * 35) % 150, 50 + (i * 45) % 150)
|
| 171 |
+
draw.line([points[k], points[k+1]], fill=color, width=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|