How to use graphic.draw_filled_polygon?
11-29-2021, 08:40 PM
Post: #12
 Guenter Schink Senior Member Posts: 483 Joined: Dec 2013
RE: How to use graphic.draw_filled_polygon?
(11-29-2021 02:22 PM)toml_12953 Wrote:
(11-29-2021 10:04 AM)Guenter Schink Wrote:  Yes, an integer is required, be it decimal or hex. A little "lambda" may be of help to create it rather than calculate it by hand. E.g:

Code:
RGB=lambda red, green, blue: (((red*256)+green)*256)+blue draw_filled_polygon([(0,0),(160,120),(0,240)],RGB(120,120,120))

gets you a grey triangle

Günter

I'm a Python beginner. Can you tell me why use lambda over the following? What's the advantage?

Code:
def RGB(red,green,blue):   return (((red*256)+green)*256)+blue

I'm a Python beginner too

Both are equivalent. Once something can be done in a one liner I'm tempted to do this.
In principle, as a beginner, I try to use some language specifics where I see them fit.
Here is some discussion on this subject. In short: you don't need it, but it may serve you well once you're accustomed to it.

Usually you would use <lambda> as an anonymous function directly:
Code:
draw_filled_polygon([(0,0),(160,120),(0,240)],(lambda red, green, blue: (((red*256) +green) *256) +blue)(120,120,100))
the arguments of the lambda function can of course be variables

Günter
 « Next Oldest | Next Newest »

 Messages In This Thread How to use graphic.draw_filled_polygon? - jfelten - 08-23-2021, 08:09 PM RE: How to use graphic.draw_filled_polygon? - pol95 - 08-26-2021, 02:23 AM RE: How to use graphic.draw_filled_polygon? - jfelten - 08-26-2021, 02:50 AM RE: How to use graphic.draw_filled_polygon? - albud44 - 08-31-2021, 08:01 PM RE: How to use graphic.draw_filled_polygon? - jfelten - 09-04-2021, 07:43 PM RE: How to use graphic.draw_filled_polygon? - Guenter Schink - 09-04-2021, 08:53 PM RE: How to use graphic.draw_filled_polygon? - StephenG1CMZ - 11-29-2021, 12:42 AM RE: How to use graphic.draw_filled_polygon? - Guenter Schink - 11-29-2021, 10:04 AM RE: How to use graphic.draw_filled_polygon? - toml_12953 - 11-29-2021, 02:22 PM RE: How to use graphic.draw_filled_polygon? - Guenter Schink - 11-29-2021 08:40 PM RE: How to use graphic.draw_filled_polygon? - jfelten - 09-04-2021, 11:10 PM RE: How to use graphic.draw_filled_polygon? - Guenter Schink - 11-28-2021, 10:25 PM

User(s) browsing this thread: 1 Guest(s)