How to fill with multiple color in Python using turtle module? -
i pretty new in python, trying have fun before going serious stuffs. trying draw simple 1 wheel cart type something, body , cart have different colors. trying code:
import turtle truck = turtle.turtle() truck.color("blue", "green") truck.begin_fill () truck.fd(50) truck.color("blue", "red") truck.begin_fill () truck.circle(50) truck.end_fill() truck.fd(50) in range(2): truck.right(90) truck.fd (100) truck.right(90) truck.fd(100) truck.end_fill ()
this code fill red color in wheel. box remains uncolored. if remove color filling codes circle, full structure becomes green.
i know using penup , pendown, can draw ease. like, using code:
import turtle truck = turtle.turtle() truck.color("blue", "green") truck.begin_fill () in range(4): truck.right(90) truck.fd (100) truck.end_fill () truck.penup() truck.bk(50) truck.pendown() truck.color("blue", "red") truck.begin_fill () truck.circle(50) truck.end_fill()
can somehow tweak first code sothat wouldn't need use penup , pendown methods?
#!/usr/bin/python # -*- coding: utf-8 -*- import turtle truck = turtle.turtle() truck.fd(50) truck.color("blue", "red") truck.begin_fill () truck.circle(50) truck.fd(50) truck.end_fill() truck.color("blue", "green") truck.begin_fill () in range(2): truck.right(90) truck.fd (100) truck.right(90) truck.fd(100) truck.end_fill () turtle.done()
Comments
Post a Comment