到最后的梦里 发表于 2021-3-20 21:51
为啥用那个我自己定义的函数来画那个线为啥显示不出来?
pen_set()加上就好了
今天我不把这个解决了,我不睡觉了{:10_295:}
import turtle as t
from random import *
import math
t.hideturtle()
t.colormode(255)
t.color((255, 255, 255), (255, 0, 0))
t.setup(1200, 800)
t.tracer(10)
# 笔的位置
def position_pen(x, y):
t.pu()
t.goto(x, y)
t.pd()
# 笔的样式
def pen_set(size, r1, g1, b1, r2, g2, b2):
t.pensize(size)
t.color((r1, g1, b1), (r2, g2, b2))
def cl(a, b):
t.begin_fill()
t.circle(a, b)
t.end_fill()
pen_set(1, 238, 190, 201, 238, 190, 231)
position_pen(90, 90)
cl(10, 360)
position_pen(105, 90)
cl(10, 360)
position_pen(112, 100)
cl(10, 360)
position_pen(87, 105)
cl(10, 360)
position_pen(100, 110)
cl(10, 360)
pen_set(1, 190, 97, 97, 190, 97, 97)
position_pen(100, 100)
cl(10, 360)
pen_set(3, 80, 207, 189, 80, 207, 189)
position_pen(90, 80)
t.pd()
t.fd(100)
t.seth(90)
t.fd(100)
pen_set(3, 80, 207, 189, 80, 207, 189)
t.done()
yayc_zcyd 发表于 2021-3-20 21:54
pen_set()加上就好了
源代码中加了pen_set
到最后的梦里 发表于 2021-3-20 21:57
源代码中加了pen_set
最后一个t.fd(100)后面加上:
pen_set(3, 80, 207, 189, 80, 207, 189)
yayc_zcyd 发表于 2021-3-20 21:57
为啥在前面加了不行
到最后的梦里 发表于 2021-3-20 22:00
为啥在前面加了不行
在t.pd()后面加pen_set(3, 80, 207, 189, 80, 207, 189)也可以{:10_247:}!
yayc_zcyd 发表于 2021-3-20 22:01
在t.pd()后面加pen_set(3, 80, 207, 189, 80, 207, 189)也可以!
那我一开始的代码那样为啥会显示不出来
到最后的梦里 发表于 2021-3-20 22:06
那我一开始的代码那样为啥会显示不出来
你写的代码最后画茎的时候没写pen_set(3, 80, 207, 189, 80, 207, 189)
yayc_zcyd 发表于 2021-3-20 22:08
你写的代码最后画茎的时候没写pen_set(3, 80, 207, 189, 80, 207, 189)
pen_set(3,80,207,189,80,207,189)
position_pen(90,80)
t.rt(90)
t.fd(100)
t.seth(90)
t.done()
这就是画花茎的代码 一开始不是写了吗
你最后不是写的是这样吗?
position_pen(90,80)
t.pd()
t.fd(100)
t.seth(90)
t.fd(100)
t.done()
t.pd()去掉,然后写pen_set(3,80,207,189,80,207,189)
因为你函数里都写了
yayc_zcyd 发表于 2021-3-20 22:13
你最后不是写的是这样吗?
position_pen(90,80)
t.pd()
啊 源代码不是这样的啊 源代码中确实有t.pd()也有那个pen_set
换成pen_set(3, 80, 207, 189, 80, 207, 189)
yayc_zcyd 发表于 2021-3-20 22:22
换成pen_set(3, 80, 207, 189, 80, 207, 189)
还是不行。就那个代码运行一下还是没出横线
到最后的梦里 发表于 2021-3-20 22:23
还是不行。就那个代码运行一下还是没出横线
你再试试,我出来了
import turtle as t
from random import *
import math
t.hideturtle()
t.colormode(255)
t.color((255, 255, 255), (255, 0, 0))
t.setup(1200, 800)
t.tracer(10)
# 笔的位置
def position_pen(x, y):
t.pu()
t.goto(x, y)
t.pd()
# 笔的样式
def pen_set(size, r1, g1, b1, r2, g2, b2):
t.pensize(size)
t.color((r1, g1, b1), (r2, g2, b2))
def cl(a, b):
t.begin_fill()
t.circle(a, b)
t.end_fill()
pen_set(1, 238, 190, 201, 238, 190, 231)
position_pen(90, 90)
cl(10, 360)
position_pen(105, 90)
cl(10, 360)
position_pen(112, 100)
cl(10, 360)
position_pen(87, 105)
cl(10, 360)
position_pen(100, 110)
cl(10, 360)
pen_set(1, 190, 97, 97, 190, 97, 97)
position_pen(100, 100)
cl(10, 360)
pen_set(3, 80, 207, 189, 80, 207, 189)
position_pen(90, 80)
pen_set(3, 80, 207, 189, 80, 207, 189)
t.fd(100)
t.seth(90)
t.fd(100)
t.done()
yayc_zcyd 发表于 2021-3-20 22:25
你再试试,我出来了
为啥要两次pen_set
你用的是函数,而不是pencolor
yayc_zcyd 发表于 2021-3-20 22:40
你用的是函数,而不是pencolor
我的pencolor不是在函数里面定义好了吗{:10_266:}