+ 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?**
30 Réponses
0
Mσみคოคの ʝคงค๔ คłıķみσňı I explained how to solve it, read more here:
https://www.sololearn.com/discuss/2104326/?ref=app
+ 3
Umm, sure but... what GUI framework are you using ? How are we supposed to know ?
+ 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 😂
+ 1
From the GUI Tkinter ....
Thank you if you can help me
+ 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
+ 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
+ 1
Yes I know, the create_polygon also allows you to specify line width, line color and fill color
+ 1
It's okay to be grateful for the help
How can I ask for code?
+ 1
The whole code ? Or just the create_polygon() part ?
+ 1
Since I don't know the code with the create_polygon part, thank you for giving me the whole code
+ 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
+ 1
no problem
Thank you very much
Excuse me for taking your time
+ 1
Mσみคოคの ʝคงค๔ คłıķみσňı no problem! Glad I could help
+ 1
Thank you
But we should not use Fill tools
(fill by lines...).
+ 1
Umm so if I get this right, instead of filling, you should create hundreds of coloured lines ?
+ 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
+ 1
The master said that the lines might not be completely overlapping and even the distance between them could be even
+ 1
I fully understood what you mean but I can't write it
+ 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
+ 1
Mσみคოคの ʝคงค๔ คłıķみσňı sorry I didn't yet, I'll try today again, I'll send you a message as soon as I do