[英]How to draw a unit circle that's inscribed in a square in python using PIL
我想绘制600x600的图像,同时循环遍历每个像素以绘制四分之一的圆(半径为pi)。 我如何根据相应坐标(x,y)落在单位圆的内部还是外部来对每个像素(xp,yp)进行不同的着色:x2 + y2 = 1,就像我放置if语句时一样,我应该在什么条件下进行着色采用?
我正在试着刻成正方形的四分之一圆。这是我到目前为止所拥有的:
from PIL import Image
img=Image.new('RGB',(600,600),(0,0,255))
yp = 0
while yp < 600:
xp = 0
while xp < 600:
img.putpixel((xp,yp),(0,255,0))
xp += 1
yp += 1
您在谈论两个半径,例如圆环-对吗?
您需要使用比例乘数将半径为Pi的圆拟合到整个矩形上
Scale = 600 / Pi
并在循环中检查条件:
if (xp * xp + yp * yp) < Scale * Scale: #inside R=1 circle
color = InnerColorConst
elif (xp * xp + yp * yp) < Scale * Scale * Pi * Pi: #inside R=Pi circle
color = OuterColorConst
else:
color = BackgroundColorConst # or omit putpixel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.