Turtle make triangle different color

2024/11/19 7:49:02

Hi guys I'm trying to replicate this image:

It's almost done I just have one issue, where the triangle is supposed to be yellow it isn't seeming to work.

Mine:

Code:

fill(True)
fillcolor('green')
width(3)
forward(200)
left(120)
forward(200)
left(120)
forward(200)fill(False)right(180)
forward(100)
right(60)
forward(100)
left(120)fill(True)
fillcolor('red')
forward(200)
left(120)
forward(200)
left(120)
forward(200)
fill(False)

Any help would be appreciated. (I can't add yellow to the second part of the code)

Answer

To the best of my knowledge, turtle does not support transparency. The green triangle will overlay the red triangle and the area where they overlap will not "add" to yellow. You have to explicitly draw the yellow triangle. Try adding this to your code:

fill(True)
fillcolor('yellow')
left(120)
forward(100)
left(120)
forward(100)
left(120)
forward(100)
fill(False)

Also, it might be a good idea to define a function def triangle(size, color) to reduce the amount of repetition in your code, e.g. like this:

def triangle(size, color):fill(True)fillcolor(color)for _ in range(3):      forward(size)left(120)fill(False)

Then you just have to position the turtle and call that function to draw a triangle.

https://en.xdnf.cn/q/118568.html

Related Q&A

How to DataBricks read Delta tables based on incremental data

we have to read the data from delta table and then we are joining the all the tables based on our requirements, then we would have to call the our internal APIS to pass the each row data. this is our g…

Converting an excel file to a specific Json in python using openpyxl library with datetime

I have the Excel data with the format shown in the image preview. How can I convert it into a JSON using Python? Expected Output: file_name = [ { A: Measurement( calculated_date=datetime(2022, 10, 1, …

How to find a word in a string in a list? (Python)

So im trying to find a way so I can read a txt file and find a specific word. I have been calling the file with myfile=open(daily.txt,r)r=myfile.readlines()that would return a list with a string for ea…

How to make a new default argument list every time [duplicate]

This question already has answers here:The Mutable Default Argument in Python(34 answers)Closed 10 years ago.I have the following setup:def returnList(arg=["abc"]):return arglist1 = returnLis…

How does one reorder information in an XML document in python 3?

Lets suppose I have the following XML structure:<?xml version="1.0" encoding="utf-8" ?> <Document><CstmrCdtTrfInitn><GrpHdr><other_tags>a</other_t…

Python - Replace only exact word in string [duplicate]

This question already has answers here:How to match a whole word with a regular expression?(4 answers)Closed 4 years ago.I want to replace only specific word in one string. However, some other words h…

How to write Hierarchical query in PYTHON

The given input is like:EMPLOYEE_ID NAME MANAGER_ID101 A 10102 B 1110 C 111 D 11 E nullEmployee Cycle LEVEL Path10…

Unable to launch selenium with python in mac

Im facing an issue with selenium with python in Mac OS.. Python 2.7 pydev 3.0My sample codefrom selenium import webdriver driver = webdriver.Firefox() driver.get("https://www.formsite.com/") …

Memory error In instantiating the numpy array

I have a list A of a 50,000 elements and each element is an array of shape (102400) I tried instantiating an array B.B=numpy.array(A)But this throws an exception MemoryError.I know that the memory and …

Setting column names in a pandas dataframe (Python)

When setting a column name for a pandas dataframe, why does the following work:df_coeff = pd.DataFrame(data = lm.coef_, index = X.columns, columns = [Coefficient])While this does not workdf_coeff = pd.…