Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please create a Python Programming code using the following specifications. Thank you! This programming aims to create a closed polygon (triangle) and an arbitrary visual

Please create a Python Programming code using the following specifications. Thank you!

This programming aims to create a closed polygon (triangle) and an arbitrary visual element that uses at least three line segments or arcs on a canvas.

Firstly, these are the ONLY required imports that are allowed

import PIL.Image, PIL.ImageDraw

from math import sin, cos, pi

The ONLY methods from Pillow Library that are allowed in creating these images are ImageDraw.line and ImageDraw.arc

After this, create a class Polygon. The following required function attributes for this class are the following:

def draw_triangle(center, side_length, rotation, color):

this function aims to create a triangle on a canvas whereas the center is a (two-int tuple), side_length is a (float), rotation is a (float, degrees), and the color is a (three-int tuple)

if I call this function and give an example:

Polygon.draw_triangle((0,0), (2), (45), (255,0,0)), it should create a red triangle with a side length of 2 and at the center of the canvas rotated at 45 that is based on the given provided.

Lastly,

def draw_element(pivot, size, rotation, color):

this function aims to draw an arbitrary visual element of your choice that uses at least three line segments or arcs (or a combination thereof) with the given pivot point (two-int tuple), size (float, arbitrary scaling variable) angle of rotation (float, degrees), and color (three-int tuple) onto the image.

The coding should look like this:

image text in transcribed

That is all, thank you for answering it will be appreciated and I will be sure to give a thumbs up if the coding is correct! :)

You are free to try different examples as an output.

Q: Can I use methods such as ImageDraw.polygon or ImageDraw.regular_polygon?

A: No, you may not. As I stated, the only allowed methods are ImageDraw.line and ImageDraw.arc

The output should be a JPEG image of the drawing mentioned above.

import PIL.Image, PIL.ImageDraw from math import sin, cos, pi class Polygon: def draw_triangle(center, side_length, rotation, color): #insert code here return def draw_element(pivot, size, rotation, color): #insert code here return if name '__main__': # create a 200 x 200 RGB image with a gray background canvas = PIL.Image.new("RGB", (200,200), (255,255,255)) # get a drawing context for the image draw = PIL.ImageDraw.Draw(canvas) # insert and call the 2 functions here to draw an image # show the image canvas.show() # save the image to a file canvas.save("sample.png")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

Students also viewed these Databases questions

Question

=+ How would you advise those problems be resolved?

Answered: 1 week ago