Transcribed TextTranscribed Text

The primary objective of this assignment is to reinforce the concepts of image processing. Before starting the assignment, you should create a few comments at the top of your Python script that include the assignment number, your name, and your student number. An example outline for the assignment is provided below. # Assignment 3 # <name> (<student number>) def assign3(): ... #code goes here def drawHouse(canvas): ... #code goes here def addCircles(canvas, num): ... #code goes here def addAlice(canvas): ... #code goes here Drawing the Scene [20 marks] Your task is to create a scene, as described below, using a program. The main execution of the program will be in a function named assign3(). However, you will need to create a few helper functions as well. The assignment task can be broken into steps as follows: 1. Create a blank 600x600 canvas to draw on. 2. Draw a house on the canvas using a function drawHouse. A house can be thought of as a square with a triangle on top. This function will take the canvas as a parameter and draw directly on it. Some useful information about the house: • The top left corner of the square is at position (200, 450). • The square portion of the house is 150 units wide and 150 units tall. • The top of the triangular portion of the house is at position (275, 350). 3. Add random circles to the canvas using a function addCircles. Each circle is at a random location on the top half of the scene and is filled with a random colour. Remember that a colour is defined as a combination of a red, green, and blue channel, with each channel taking a value between 0 and 255. Also, recall that the function makeColor(r,g,b) will create a colour given the values for the page 1 of 3 red, green, and blue channels. The height and width of the circles is fixed at 15. The user should be able to produce any number of circles they wish (I’ve used 100). This function will take the canvas as a parameter and draw directly on it. 4. Copy Alice from Alice.png to your scene using a function addAlice. To copy only Alice, and not the background, you’ll need to copy only the pixels that are not green (similar to a backwards green screen). You should use the distance(...) function to determine whether to copy a pixel or not. To make this more efficient, we’ll examine only a selected region of pixels from Alice.png. Some useful information about this process: • The top left corner to consider in Alice.png is (200, 100). The region we’ll consider has width 75 and height 210. • Any pixel that is part of the ‘background’ in Alice.png is fully green (0,255,0). In JES, green is a predefined colour with value (0,255,0). • The top left corner of where Alice will be placed in our scene is (450, 390). • You can load Alice.png however you want (e.g., pickAFile, setMediaPath, etc.) 5. Return the scene. You should be able to display your scene with the following command: >>>show(assign3()) However, you’ll want to store the resulting scene in a variable such that you can save the image produced for submission. Figure 1: Example output page 2 of 3 To better illustrate some of the useful information from above, here are a few diagrams. (a) Scene (b) Alice.png Figure 2: Diagram of useful information page 3 of 3

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import random
def assign3():
    #code goes here
    canvas = makeEmptyPicture(600, 600)
    addCircles(canvas, 100)
    return canvas

def drawHouse(canvas):
    #code goes here
    addRect(canvas, 200, 450, 150, 150)
    points = [200, 450, 275, 350, 350, 450, 200, 450]
    addLine(canvas, 200, 450, 275, 350)
    addLine(canvas, 275, 350, 350, 450)

def addCircles(canvas, num):
    #code goes here
    for i in range(num):
       pos_x = random.randint(15, 580)
       pos_y = random.randint(15, 300)
       c = makeColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
       addOvalFilled(canvas, pos_x, pos_y, 15, 15, c)

def addAlice(canvas):
    #code goes here
    file = pickAFile...

By purchasing this solution you'll be able to access the following files: and Solution.docx.

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats