1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
scoundrel [369]
3 years ago
5

You will write a program that generates random drawings that can be drawn using the shape painter.

Computers and Technology
1 answer:
DiKsa [7]3 years ago
6 0

Answer:

import random

f_name = input('Enter the drawing file name: ')

total_shapes = int(input('Enter the no. of total shapes: '))

file = open(f_name,'w')

for i in range(total_shapes):

              category = random.randint(0,1)

              if category == 0:

                             left_coordinate = [random.randint(0,499),random.randint(0,499)]

                             while left_coordinate[0] == 499 and left_coordinate[499] == 0:

                                            left_coordinate = [random.randint(0,499),random.randint(0,499)]

                                           

                             right_coordinate = [random.randint(left_coordinate[0]+1,499), random.randint(left_coordinate[1]+1,499)]

                             

                             red_intensity = random.randint(0,100)

                             green_intensity = random.randint(100,200)

                             blue_intensity = random.randint(192,255)

                             if i == total_shapes-1:      

                                            file.write('Rectange; '+str(left_coordinate[0])+', '+str(left_coordinate[1])+'; '+str(right_coordinate[0])+', '+str(right_coordinate[1])+'; '+str(red_intensity)+', '+str(green_intensity)+', '+str(blue_intensity))

                             else:

                                            file.write('Rectange; '+str(left_coordinate[0])+', '+str(left_coordinate[1])+'; '+str(right_coordinate[0])+', '+str(right_coordinate[1])+'; '+str(red_intensity)+', '+str(green_intensity)+', '+str(blue_intensity)+'\n')

              else: #Circle

                             center = [random.randint(0,499),random.randint(0,499)]

                             if center[0] > center[1]:

                                            radius = random.randint(0,499-center[0])

                             else:

                                            radius = random.randint(0,499-center[1])

                             red_intensity = random.randint(0,100)

                             green_intensity = random.randint(100,200)

                             blue_intensity = random.randint(192,255)

                                           

                             if i == total_shapes-1:    

                                            file.write('Circle; '+str(center[0])+', '+str(center[1])+'; '+str(radius)+'; '+str(red_intensity)+', '+str(blue_intensity)+', '+str(green_intensity))

                             else:

                                            file.write('Circle; '+str(center[0])+', '+str(center[1])+'; '+str(radius)+'; '+str(red_intensity)+', '+str(blue_intensity)+', '+str(green_intensity)+'\n')

                                           

file.close()                                        

Explanation:

  • Get the file name from the user.
  • Loop through to generate total shapes  .
  • Use randInt to randomly generate the category.
  • If category is zero, then that means its a rectangle.
  • Check for last record using an If statement and then display relevant information.
You might be interested in
From the binary search algorithm, it follows that every iteration of the while loop cuts the size of the search list by half.
Colt1911 [192]

Answer:

True: In binary search algorithm, we follow the below steps sequentially:

Input: A sorted array  B[1,2,...n] of n items and one item x to be searched.

Output: The index of x in B if exists in B, 0 otherwise.

  1. low=1
  2. high=n
  3. while( low < high )
  4.  {      mid=low + (high-low)/2
  5.         if( B[mid]==x)
  6.          {
  7.             return(mid)  //returns mid as the index of x
  8.           }
  9.          else
  10.          {
  11.              if( B[mid] < x)      //takes only right half of the array
  12.               {
  13.                 low=mid+1
  14.               }
  15.              else               // takes only the left half of the array
  16.               {
  17.                high=mid-1
  18.               }
  19.           }
  20.  }
  21. return( 0 )

Explanation:

For each iteration the line number 11 or line number 15 will be executed.

Both lines, cut the array size to half of it and takes as the input for next iteration.

6 0
4 years ago
You can italicize a word by selecting it and clicking the italics icon. what keyboard shortcut could you use instead of clicking
andrew-mc [135]
CTRL+i, press them at the same time

8 0
3 years ago
Read 2 more answers
Recent trends on operating system
katovenus [111]

Answer:

Windows 10 if this is what I think u mean

7 0
3 years ago
Which of these steps comes first in the boot process
strojnjashka [21]

Answer:

Missing Reference

Explanation:

7 0
3 years ago
Mail merge requires an MS Word document in order to work.<br><br> True<br> False
Kipish [7]

True is correct. Hope it helps


3 0
3 years ago
Read 2 more answers
Other questions:
  • You have been doing a lot of web surfing lately as part of your research for your course and along the way you have noticed a gr
    14·1 answer
  • You buy a new workstation that features an embedded RAID controller on the motherboard. You want to setup hardware RAID 10. How
    10·2 answers
  • Choose the HTML5 element below that is used to configure an area on a web page that can stand on its own and could potentially b
    5·1 answer
  • Different network scenarios require the
    9·1 answer
  • What should be used to screw on broadheads? needle-nose pliers gloves thumb and forefinger only specially designed wrench
    6·1 answer
  • What is net pay?<br> What is net pay?
    11·2 answers
  • Who here has an old (preferably 80s) Toyota Celica i just bought mine and want to know how you guys like yours because mine is f
    14·1 answer
  • Microsoft PowerPoint is an example of a(n) _____ application.
    15·2 answers
  • What Is The First Computer Brought In Nepal ? <br>​
    10·1 answer
  • Live footage refers to:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!