两段代码单独运行时不会报错,拼接就运行不了怎么回事
用代码块功能插入代码
#第一段
from PIL import Image
im = Image.open("2(2).jpg")
x, y = im.size
print(x, y)
import turtle
canvasX = x
canvasY = y
turtle.setup(x*1.2,y*1.2,600,300)
def D(x, y):
return x - canvasX // 2, - y + canvasY // 2
turtle.screensize(canvasX,canvasY, "black")
turtle.penup()
turtle.goto(D(0,0))
turtle.pendown()
turtle.pensize(1)
turtle.speed(0)
turtle.colormode(255)
turtle.delay(0)
turtle.tracer(x,0)
turtle.hideturtle()
for y in range(im.size[1]):
turtle.penup()
turtle.goto(D(0,y))
turtle.pendown()
for x in range(im.size[0]):
pix = im.getpixel((x, y))
turtle.pencolor(pix)
turtle.forward(1)
#第二段
turtle.pensize(5)
turtle.tracer(False)
r,g,b=255,255,255
for i in range(3):
r, g, b=255-30*(i),255-30*(i),255-30*(i)
turtle.pencolor(r/255,g/255, b/255)
turtle.circle(1+3*i,360)
turtle.penup()
turtle.goto(0,-3*i)
turtle.pendown()
```,请勿粘贴截图
###### 图片成功绘制,圆点无法绘制
```python
TypeError Traceback (most recent call last)
<ipython-input-1-e881053ab609> in <module>
37 for i in range(3):
38 r, g, b=255-30*(i),255-30*(i),255-30*(i)
---> 39 turtle.pencolor(r/255,g/255, b/255)
40 turtle.circle(1+3*i,360)
41 turtle.penup()
C:\ProgramData\Anaconda3\lib\turtle.py in pencolor(*args)
C:\ProgramData\Anaconda3\lib\turtle.py in pencolor(self, *args)
2250 """
2251 if args:
-> 2252 color = self._colorstr(args)
2253 if color == self._pencolor:
2254 return
C:\ProgramData\Anaconda3\lib\turtle.py in _colorstr(self, args)
2694
2695 def _colorstr(self, args):
-> 2696 return self.screen._colorstr(args)
2697
2698 def _cc(self, args):
C:\ProgramData\Anaconda3\lib\turtle.py in _colorstr(self, color)
1165 if not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255)):
1166 raise TurtleGraphicsError("bad color sequence: %s" % str(color))
-> 1167 return "#%02x%02x%02x" % (r, g, b)
1168
1169 def _color(self, cstr):
TypeError: %x format: an integer is required, not float
我的解答思路和尝试过的方法
调整过不少次,不知道问题在哪
我想要达到的结果
图片基础上绘制圆点