from PIL import Image, ImageDraw
import math
import random
def draw_concentric_circles(size=800, num_circles=15):
# Create a grey background
bg_color = (0, 0, 0, 255) # Dark grey
img = Image.new('RGBA', (size, size), bg_color)
draw = ImageDraw.Draw(img)
center = size // 2
max_radius = (size // 2) - 40
radii = [int(r) for r in range(50, max_radius, max_radius // num_circles)]
colors = [
(232, 69, 76), # Red
(117, 176, 217) # Blue
]
for r in radii:
base_color = random.choice(colors)
# Random position for the break (in radians)
break_pos = random.uniform(0, 2 * math.pi)
gap_half_width = 0.05 # Size of the break
# We draw the circle by connecting tiny segments
# 1000 steps ensures the line looks smooth
steps = 1000
for i in range(steps):
# Current angle
angle = (i / steps) * 2 * math.pi
# Calculate distance from the break to determine alpha
# This logic finds the shortest angular distance to the break
diff = abs(angle - break_pos)
if diff > math.pi:
diff = 2 * math.pi - diff
# If we are inside the "break" zone, don't draw
if diff < gap_half_width:
continue
# Normalize distance for fading:
# Near the break (diff approx gap_half_width) -> Alpha 255 (100%)
# Far from break (diff approx PI) -> Alpha 127 (50%)
# Linear interpolation:
alpha_ratio = 1.0 - (1.5 * (diff / math.pi))
alpha = max(min(int(255 * alpha_ratio), 255), 0)
# Calculate coordinates
x = center + r * math.cos(angle)
y = center + r * math.sin(angle)
# Draw a tiny point/rectangle to represent the segment
# We use a small offset to give the line some thickness
thickness = 5
draw.ellipse([x - thickness, y - thickness, x + thickness, y + thickness],
fill=(base_color[0], base_color[1], base_color[2], alpha), outline=None)
print("Showing..")
img.show()
draw_concentric_circles()
Ich habe versucht, ein Skript zu schreiben, um einige Bögen zu zeichnen, die in die Hintergrundfarbe übergehen (siehe Beispiel unten). [code]from PIL import Image, ImageDraw import math import random
center = size // 2 max_radius = (size // 2) - 40 radii = [int(r) for r in range(50, max_radius, max_radius // num_circles)]
colors = [ (232, 69, 76), # Red (117, 176, 217) # Blue ]
for r in radii: base_color = random.choice(colors) # Random position for the break (in radians) break_pos = random.uniform(0, 2 * math.pi) gap_half_width = 0.05 # Size of the break
# We draw the circle by connecting tiny segments # 1000 steps ensures the line looks smooth steps = 1000 for i in range(steps): # Current angle angle = (i / steps) * 2 * math.pi
# Calculate distance from the break to determine alpha # This logic finds the shortest angular distance to the break diff = abs(angle - break_pos) if diff > math.pi: diff = 2 * math.pi - diff
# If we are inside the "break" zone, don't draw if diff < gap_half_width: continue
# Normalize distance for fading: # Near the break (diff approx gap_half_width) -> Alpha 255 (100%) # Far from break (diff approx PI) -> Alpha 127 (50%) # Linear interpolation: alpha_ratio = 1.0 - (1.5 * (diff / math.pi)) alpha = max(min(int(255 * alpha_ratio), 255), 0)
# Calculate coordinates x = center + r * math.cos(angle) y = center + r * math.sin(angle)
# Draw a tiny point/rectangle to represent the segment # We use a small offset to give the line some thickness thickness = 5 draw.ellipse([x - thickness, y - thickness, x + thickness, y + thickness], fill=(base_color[0], base_color[1], base_color[2], alpha), outline=None)
print("Showing..") img.show()
draw_concentric_circles() [/code] Gibt mir: [img]https://i.sstatic.net/6HKJu5vB.png[/img]
Ich habe viele andere Ratschläge ausprobiert, aber keiner hat geholfen.
Habe andere Versionen von Python und Pillow ausprobiert
ist das Ergebnis
[ ! ]
Ich bin für konstruktive Hilfe dankbar
Hier...
Pythons PIL -Modul (Python -Kissen) Ich versuche, ein Bild 85 Pixel mit einer affine Transformation nach rechts zu verschieben. Der folgende Code sollte dazu, aber stattdessen verschiebt das Bild...