我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用turtle.begin_fill()。
def szesciokat(bok, bokPrzekatna, kat): turtle.colormode(255) turtle.fillcolor(251, 255, 135) turtle.begin_fill() turtle.lt(kat) turtle.fd(bokPrzekatna) turtle.rt(kat) turtle.fd(bok) turtle.rt(kat) turtle.fd(bokPrzekatna) turtle.rt(90) turtle.fd(bokPrzekatna) turtle.rt(kat) turtle.fd(bok) turtle.rt(kat) turtle.fd(bokPrzekatna) turtle.lt(45) turtle.end_fill()
def element(dlBokKw, dlBokMalKw, kolor): numPow = 1 turtle.fillcolor(kolor) turtle.begin_fill() kwadrat(dlBokKw) turtle.end_fill() turtle.pu() turtle.bk(dlBokMalKw) turtle.lt(90) turtle.fd(dlBokMalKw) turtle.rt(90) turtle.pd() while numPow <= 4: turtle.begin_fill() kwadrat(dlBokMalKw) turtle.end_fill() turtle.pu() turtle.fd(dlBokMalKw*4) turtle.rt(90) turtle.pd() numPow = numPow + 1
def tetka(orient=1, bokKw=10): turtle.colormode(255) turtle.fillcolor(0, 91, 24) turtle.begin_fill() turtle.fd(bokKw*3) turtle.rt(90*orient) turtle.fd(bokKw) turtle.rt(90*orient) turtle.fd(bokKw) turtle.lt(90*orient) turtle.fd(bokKw) turtle.rt(90*orient) turtle.fd(bokKw) turtle.rt(90*orient) turtle.fd(bokKw) turtle.lt(90*orient) turtle.fd(bokKw) turtle.rt(90*orient) turtle.fd(bokKw) turtle.rt(90*orient) turtle.end_fill()
def strzalka(bokStrzalki): alfa = 120 beta = 60 turtle.colormode(255) turtle.fillcolor(255, 255, 0) turtle.begin_fill() turtle.fd(bokStrzalki) turtle.lt(180 - alfa) turtle.fd(bokStrzalki) turtle.rt(180+alfa) turtle.fd(bokStrzalki) turtle.lt(180 - alfa) turtle.fd(bokStrzalki) turtle.rt(180+beta) turtle.fd(bokStrzalki) turtle.rt(alfa / 2) turtle.fd(bokStrzalki) turtle.lt(beta * 2) turtle.end_fill()
def kwiatek(r): numPow = 1 turtle.colormode(255) turtle.fillcolor(238, 255, 0) ustDoKolka(r) turtle.begin_fill() turtle.circle(r) turtle.end_fill() ustDoPlatkow(r) while numPow <= 12: turtle.pu() turtle.fd(r) turtle.pd() trojkat(r) turtle.pu() turtle.fd(r) turtle.rt(180) turtle.rt(360/12) numPow = numPow + 1
def duzyKwadrat(dlBokMalKw): numPow = 1 wnd = turtle.Screen() wnd.colormode(255) turtle.fillcolor(255, 255, 0) turtle.pu() turtle.bk(225) turtle.lt(90) turtle.bk(225 - dlBokMalKw) turtle.pd() turtle.begin_fill() while(numPow <= 4): turtle.fd(450 - dlBokMalKw * 2 - 15) turtle.rt(90) numPow = numPow + 1 turtle.end_fill() turtle.pu() turtle.setx(0) turtle.sety(0) turtle.pd() turtle.rt(90)
def wielokatP(jedn): turtle.colormode(255) turtle.fillcolor(0, 255, 63) turtle.begin_fill() turtle.lt(90) turtle.fd(jedn * 2) turtle.rt(90) turtle.fd(jedn * 2) turtle.rt(45) turtle.fd((math.sqrt(jedn ** 2 * 2)) * 2) turtle.rt(45) turtle.fd(jedn * 2) turtle.rt(90) turtle.fd(jedn * 2) turtle.rt(45) turtle.fd((math.sqrt(jedn ** 2 * 2)) * 2) turtle.rt(45) turtle.end_fill()
def nos(a): turtle.begin_fill() wielokatZeSkrP(6, 2 * a, 4) turtle.end_fill() turtle.lt(360 / 6) turtle.fd(2 * a) turtle.rt(360 / 6) turtle.fd(2 * a) turtle.rt(360/ 6) turtle.fd(a * 2) turtle.lt(360 / 6) turtle.lt(30) wasP(a) turtle.rt(60) wasL(a) #turtle.lt(90) #turtle.fd(a * 8)
def romb(bok): beta = 360 / 5 alpha = 180 - beta turtle.colormode(255) turtle.fillcolor(255, 0, 0) turtle.begin_fill() turtle.lt(beta / 2) turtle.fd(60) turtle.rt(beta) turtle.fd(60) turtle.rt(alpha) turtle.fd(60) turtle.rt(beta) turtle.fd(60) turtle.rt(alpha + beta/2) turtle.end_fill()
def wieza(): ##Rysujemy od LEWEGO DOLNEGO ROGU bokProst1 = 20 bokProst2 = 40 bokTroj = 40 turtle.colormode(255) turtle.fillcolor(0, 140, 39) turtle.begin_fill() turtle.fd(bokProst1) turtle.rt(30) turtle.fd(bokTroj) turtle.rt(120) turtle.fd(bokTroj) turtle.rt(30) turtle.fd(bokProst1) turtle.rt(90) turtle.fd(bokProst2) turtle.lt(90+180) turtle.end_fill()
def najmnElem(bok): przeciwProst = sqrt((bok**2)*2) numPow = 1 turtle.colormode(255) turtle.fillcolor(119, 119, 119) turtle.lt(45) turtle.fd(bok) turtle.lt(90+45) while numPow <= 2: turtle.begin_fill() trojkat(bok) turtle.end_fill() turtle.fd(przeciwProst) turtle.lt(90) turtle.fd(przeciwProst) turtle.lt(180) turtle.begin_fill() trojkat(bok) turtle.end_fill() turtle.rt(90) numPow = numPow + 1 turtle.lt(45) turtle.fd(bok) turtle.lt(90+45)
def glowaWonsza(bok, bokPrzekatna, kat): turtle.colormode(255) szesciokat(bok, bokPrzekatna, kat) turtle.pu() ##Start turtle.lt(180) turtle.pd() naGoreWielokata(bok, bokPrzekatna, kat) turtle.pu() turtle.lt(180) turtle.fd(bok) turtle.fillcolor(206, 136, 22) turtle.begin_fill() turtle.rt(90) turtle.circle(5) turtle.lt(90) turtle.end_fill() turtle.fillcolor(251, 255, 135) turtle.bk(bok) turtle.pd() naGoreWielokata(bok, bokPrzekatna, kat) turtle.pu() turtle.lt(90) turtle.pd() ##Koniec szesciokat(bok, bokPrzekatna, kat) turtle.rt(180) naGoreWielokata(bok, bokPrzekatna, kat) turtle.rt(90)
def trojkat(r2): a = (math.sqrt(2)-1)*r2 b = (2-math.sqrt(2))*r2 turtle.fillcolor(randint(0, 255), randint(0, 255), randint(0, 255)) turtle.begin_fill() turtle.rt(90) turtle.fd(a) turtle.lt(135) turtle.fd(b) turtle.lt(90) turtle.fd(b) turtle.lt(135) turtle.fd(a) turtle.lt(90) turtle.end_fill()
def platek(): turtle.fd(50) turtle.fillcolor(randint(0,255),randint(0,255),randint(0,255)) turtle.begin_fill() trojkat(50) turtle.end_fill()
def kwadratNaSrodkuElem(bokDl, bokMalKw): turtle.fillcolor(255, 255, 255) turtle.pu() turtle.fd(bokDl / 3) turtle.rt(90) turtle.fd(bokMalKw) turtle.lt(90) turtle.pd() turtle.begin_fill() kwadrat(bokDl / 3) turtle.end_fill()
def elementMotywu(bokMalKw): numPow = 1 bokDl = bokMalKw * 6 bokKr = bokMalKw*4 turtle.colormode(255) turtle.fillcolor(0, 182, 255) turtle.begin_fill() prostokat(bokDl, bokKr) turtle.end_fill() turtle.fillcolor(255, 255, 0) while numPow <= 2: turtle.begin_fill() kwadrat(bokMalKw) turtle.end_fill() turtle.pu() turtle.fd(bokDl) turtle.rt(90) turtle.pd() turtle.begin_fill() kwadrat(bokMalKw) turtle.end_fill() turtle.pu() turtle.fd(bokKr) turtle.rt(90) turtle.pd() numPow = numPow + 1 kwadratNaSrodkuElem(bokDl, bokMalKw)
def trapez(kolor): turtle.colormode(255) turtle.fillcolor(kolor) turtle.begin_fill() turtle.rt(90) turtle.fd(26 * 2) turtle.lt(90+45) turtle.fd(37) turtle.lt(45) turtle.fd(26) turtle.lt(90) turtle.fd(26) turtle.lt(180) turtle.end_fill()
def kwScRog(dlBokKw): wnd = turtle.Screen() wnd.colormode(255) turtle.fillcolor(102, 51, 0) numPow = 1 bokMalKw = math.floor((dlBokKw - (dlBokKw / 5) * 2)) scBok = math.sqrt(((dlBokKw / 5) ** 2) * 2) turtle.begin_fill() while(numPow <= 4): turtle.fd(bokMalKw) turtle.lt(45) turtle.fd(scBok) turtle.lt(45) numPow = numPow + 1 turtle.end_fill()
def spiczKwadrat(jedn): turtle.colormode(255) turtle.fillcolor(0, 255, 63) turtle.begin_fill() turtle.fd(jedn * 2) turtle.rt(45) turtle.fd(math.sqrt(jedn ** 2 * 2)) turtle.rt(90) turtle.fd(math.sqrt(jedn ** 2 * 2)) turtle.rt(45) turtle.fd(jedn * 2) turtle.rt(90) turtle.fd(jedn * 2) turtle.rt(90) turtle.end_fill()
def kwadrat(jedn): turtle.colormode(255) turtle.fillcolor(0, 255, 63) numPow = 1 turtle.begin_fill() while(numPow <= 4): turtle.fd(jedn * 2) turtle.rt(90) numPow = numPow + 1 turtle.end_fill()
def wielokatNaSr(jedn): turtle.colormode(255) turtle.fillcolor(0, 255, 63) turtle.begin_fill() turtle.lt(45) turtle.fd(math.sqrt(jedn ** 2 * 2)) turtle.rt(45) turtle.fd(jedn * 2) turtle.rt(45) turtle.fd(math.sqrt(jedn ** 2 * 2)) turtle.end_fill()
def lUcho(a): turtle.begin_fill() wielokat(8, a * 4, 0) turtle.end_fill()
def pUcho(a): turtle.begin_fill() wielokat(8, a * 4, 0) turtle.end_fill()
def okoL(a): turtle.begin_fill() wielokat(6, a *4, 1) turtle.end_fill() turtle.rt(180) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.fd(a * 4) turtle.lt(360 / 6) turtle.colormode(255) turtle.fillcolor(255, 255, 255) turtle.fd(a) turtle.rt(120) turtle.begin_fill() wielokatZeSkrP(6, 2 * a, 4) turtle.end_fill() turtle.rt(60) turtle.fd(a / 2) turtle.rt(120) turtle.fillcolor(0, 0, 0) turtle.begin_fill() wielokatZeSkrP(6, a, 4) turtle.end_fill()
def jeden(): turtle.fd(50) turtle.fillcolor(randint(0,255),randint(0,255),randint(0,255)) turtle.begin_fill() kwadrat(50) turtle.end_fill() turtle.bk(50)
def kwZam(bok): numPow = 1 turtle.colormode(255) turtle.fillcolor(randint(0, 255), randint(0, 255), randint(0, 255)) turtle.begin_fill() while(numPow <= 4): turtle.fd(bok) turtle.lt(90) numPow = numPow + 1 korMala(bok) turtle.end_fill()
def kwadratZolty(a): dlBokKw = a / 5 turtle.colormode(255) turtle.fillcolor(255, 255, 0) turtle.begin_fill() kwadrOdWierz(dlBokKw) turtle.end_fill()
def tscheme_begin_fill(): """Start a sequence of moves that outline a shape to be filled.""" _tscheme_prep() turtle.begin_fill() return okay
def tscheme_end_fill(): """Fill in shape drawn since last begin_fill.""" _tscheme_prep() turtle.end_fill() return okay
def run_instruction(t): if t.data == 'change_color': turtle.color(*t.children) # We just pass the color names as-is elif t.data == 'movement': name, number = t.children { 'f': turtle.fd, 'b': turtle.bk, 'l': turtle.lt, 'r': turtle.rt, }[name](int(number)) elif t.data == 'repeat': count, block = t.children for i in range(int(count)): run_instruction(block) elif t.data == 'fill': turtle.begin_fill() run_instruction(t.children[0]) turtle.end_fill() elif t.data == 'code_block': for cmd in t.children: run_instruction(cmd) else: raise SyntaxError('Unknown instruction: %s' % t.data)