How to fill any triangle by create_line() * python * | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to fill any triangle by create_line() * python *

I want to write code that draws three points from the user and draws a triangle and fills in the triangle using one pixel lines width Use **create_line()** to fill in the triangle. In fact, just use create_line() Can you guide me how to write this code to **apply to all triangles?**

16th Dec 2019, 9:17 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
30 Answers
19th Dec 2019, 9:44 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
Umm, sure but... what GUI framework are you using ? How are we supposed to know ?
16th Dec 2019, 9:21 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Mσみคოคの ʝคงค๔ คłıķみσňı technically it should be possible, but I doubt that it would be precise, one edge will definetly look messy because pixels are not really that small. This will be more of a math problem than a programming one 😂
16th Dec 2019, 11:47 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
From the GUI Tkinter .... Thank you if you can help me
16th Dec 2019, 10:06 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
Is it necessary to use create_line ? The method create_polygon seems to be the best choice for what you're trying to do
16th Dec 2019, 10:17 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
I am a student and the professor has said that to fill the triangle use one pixel wide lines to cover the whole triangle and apply to all triangles. This means that it is necessary to use some sort of line If you can help me You have done a great favor to me
16th Dec 2019, 10:28 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
Yes I know, the create_polygon also allows you to specify line width, line color and fill color
16th Dec 2019, 11:13 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
It's okay to be grateful for the help How can I ask for code?
16th Dec 2019, 11:22 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
The whole code ? Or just the create_polygon() part ?
16th Dec 2019, 11:23 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Since I don't know the code with the create_polygon part, thank you for giving me the whole code
16th Dec 2019, 11:28 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
Just a reminder, this code will NOT work on SL platform. Just a minute let me write it. EDIT: Here is the code, I have not tested it, so if something doesn't work ask here: https://code.sololearn.com/cOHybb1HVPqg/?ref=app
16th Dec 2019, 11:29 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
no problem Thank you very much Excuse me for taking your time
16th Dec 2019, 11:36 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
16th Dec 2019, 11:37 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Thank you But we should not use Fill tools (fill by lines...).
16th Dec 2019, 11:40 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
Umm so if I get this right, instead of filling, you should create hundreds of coloured lines ?
16th Dec 2019, 11:42 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
There are different ways you could do this, but the easiest way I think is this: Let say you have three points: a, b, and c 1. First we choose any line, for example bc, and try to get the coordinates of all the points that belong to it, and save them to a list or tuple 2.Draw all the lines from a to the points in bc, so simple you're looping throught the list you created, and drqwing lines from point a to it I don't know if you understood, so let me know
16th Dec 2019, 11:52 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
The master said that the lines might not be completely overlapping and even the distance between them could be even
16th Dec 2019, 11:52 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
I fully understood what you mean but I can't write it
16th Dec 2019, 11:55 PM
Mσみคოคの ʝคงค๔ คłıķみσňı
Mσみคოคの ʝคงค๔ คłıķみσňı - avatar
+ 1
Mσみคოคの ʝคงค๔ คłıķみσňı well then try to use some trigonometric function to draw lines with more precision. It's getting late here so I have to sleep, I'll try to think of better solution tomorrow
16th Dec 2019, 11:56 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Mσみคოคの ʝคงค๔ คłıķみσňı sorry I didn't yet, I'll try today again, I'll send you a message as soon as I do
18th Dec 2019, 7:48 AM
Aymane Boukrouh
Aymane Boukrouh - avatar