Computer Science AP/X CSCI-140/242 Polygons Lab 2 8/30/2018

Similar documents
What you get When you install Python for your computer, you get a number of features:

Problem 1.1 (3 pts) :Python uses atomic data types and builds up from there. Give an example of: a. an int b. a double c. a string

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

CSCI 204 Introduction to Computer Science II

CS150 - Sample Final

Flow Control: Branches and loops

SCRATCH MODULE 3: NUMBER CONVERSIONS

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

STEAM Clown Productions. Python lab. Binary Register. STEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1

2018 Pummill Relay problem statement

n! = 1 * 2 * 3 * 4 * * (n-1) * n

CS150 Sample Final. Name: Section: A / B

Late Penalty: Late assignments will not be accepted.

Lab 1 Implementing a Simon Says Game

CS150 - Assignment 5 Data For Everyone Due: Wednesday Oct. 16, at the beginning of class

CSC 101: Lab Manual#11 Programming Turtle Graphics in Python Lab due date: 5:00pm, day after lab session

Problem Solving with Python Challenges 2 Scratch to Python

LO: To recreate Matisse s Snail in Python

Programming Assignment 8 ( 100 Points )

Course Outline - COMP150. Lectures and Labs

CPSC 217 Assignment 4

Desire2Learn: Assignments

Art, Nature, and Patterns Introduction

Computer and Programming: Lab 1

CS106 Lab 1: Getting started with Python, Linux, and Canopy. A. Using the interpreter as a fancy calculator

COMPSCI 372 S2 C - Assignment 2 Due Date: Monday 22nd September 2008, 9.30pm

Lab 8 - Vectors, and Debugging. Directions

CCSI 3161 Project Flight Simulator

Basic Input and Output

CpSc 1111 Lab 5 Formatting and Flow Control

Python Programming Exercises 3

Lab 1 Implementing a Simon Says Game

CS195H Homework 5. Due:March 12th, 2015

Introduction to Recursion

The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion - Python version

CS Problem Solving and Object-Oriented Programming

PLC Papers Created For:

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

The Beauty and Joy of Computing 1 Lab Exercise 1: Introduction to Scratch/BYOB - Animations and Communication

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Day 1: Introduction to MATLAB and Colorizing Images CURIE Academy 2015: Computational Photography Sign-Off Sheet

EE 352 Lab 3 The Search Is On

Python, Part 2 CS 8: Introduction to Computer Science Lecture #4

2010Fa CS10 Online Final Answers Section 1

1 Getting started with Processing

CS150 Sample Final Solution

Create Turtles with Python

Objectives: To create a Flash motion tween using the timeline and keyframes, and using pivot points to define object movement.

CS2223: Algorithms D- Term, Homework I. Teams: To be done individually. Due date: 03/27/2015 (1:50 PM) Submission: Electronic submission only

Modules and Programs 1 / 14

CSCI 3155: Homework Assignment 3

CS2110 Fall 2015 Assignment A5: Treemaps 1

COMP 412, Fall 2018 Lab 1: A Front End for ILOC

Creating and using Moodle Rubrics

How to Create and Submit a Continuing Review Form (Progress Report) in INSPIR II

Grade Center Features

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

CMSC 201 Fall 2016 Homework 6 Functions

Lab 4: On Lists and Light Sabers

Grade 8 - geometry investigation - Rene Rix *

CS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM

Assignment: 2. CS 135 Winter 2018 Graham, Nijjar

Arrays in C++ Instructor: Andy Abreu

CS61BL: Data Structures & Programming Methodology Summer Project 1: Dots!

Hacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018

Programming Project 1

Lab 4: NetLogo Experiments in the Random Walk and Wiggle Walk

Polyhedron Nets. National Standards (NCTM) 21 st Century Skills. Middle School

Map-colouring with Polydron

CMPT 354 Database Systems. Simon Fraser University Fall Instructor: Oliver Schulte

CSCI 135 Programming Exam #1 Fundamentals of Computer Science I Fall 2014

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

CS1110. Lecture 6: Function calls

COS 116 The Computational Universe Laboratory 10: Computer Graphics

nostarch.com/pfk For bulk orders, please contact us at

CS 051 Homework Laboratory #2

Introduction to Dropbox Management Add a Category Add a Folder Set Availability for Dropbox Folders Add Special Access...

CS211 Programming Practicum Fall 2017

Review Response Submission Form for Continuing Review Form

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

CSE Theory of Computing Fall 2017 Project 3: K-tape Turing Machine

Geometry. Name. Use AngLegs to model each set of shapes. Complete each statement with the phrase "is" or "is not." Triangle 1 congruent to Triangle 2.

CPSC 217 Assignment 3

CSC 110 Lab 12 Graphics and Objects. Names:

Top Down Breaking a Problem Down

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

What s New in Blackboard Faculty Tutorial

Geometry Lesson Polyhedron Nets. National Standards

Animations that make decisions

AP Computer Science Principles: Submitting Python Code to Web-CAT

Fundamentals of Programming (Python) Getting Started with Programming

CPSC 217 Midterm (Python 3 version)

Mirage. Language Reference Manual. Image drawn using Mirage 1.1. Columbia University COMS W4115 Programming Languages and Translators Fall 2006

Animation Part 2: MoveableShape interface & Multithreading

CpSc 1111 Lab 9 2-D Arrays

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4500/8506 Operating Systems Summer 2016 Programming Assignment 1 Introduction The purpose of this

[ 8 marks ] Demonstration of Programming Concepts

Repetition Through Recursion

Ascii Art. CS 1301 Individual Homework 7 Ascii Art Due: Monday April 4 th, before 11:55pm Out of 100 points

Problem Score 1 / 27 2 / 19 3 / 16 4 / 14 code check off 5 / 22 /2 Total /100

Transcription:

Computer Science AP/X CSCI-140/242 Polygons Lab 2 8/30/2018 1 Implementation You will now implement a program that handles the general case of drawing polygons of decreasing sides, recursively. 1.1 Program Your program should be named polygons.py. When it is run on the command line it requires two arguments (in order): 1. # sides: The number of sides of the main polygon (an integer). This value is guaranteed to be between 3 and 8, inclusively. 2. [fill unfill ]: If the string fill is specified, the polygons will be filled when drawn. Otherwise it is assumed the polygon will be unfilled and just a line drawing. If the correct number of command line arguments is not supplied, a usage message should be displayed and the program should exit: $ python3 polygons.py #_sides [fill unfill] 1.2 General Requirements When the program is run, the main polygon that is drawn should be the number of sides supplied at run time. As the sides of the main polygon are drawn, recursion should be used to draw smaller polygons of decreasing size until the shape is a triangle. 1

When the programming finishes, the total length of all the sides of the polygons drawn should be displayed to standard output. Here is an example of a potential image you might make if the program was run as (using 200 as the side length of the main polygon, and 50% as the reduction size for each sub-polygon) $ python3 polygons.py 5 fill Sum: 60000 Here is an example of an 8 sided unfilled polygon (using same constants as the previous): Usage: $ python3 polygons.py 8 unfill Sum: 276000.0 We are encouraging you to be creative with this lab and make something that looks interesting using recursion and polygons. Make sure that your name/s are displayed on the screen (using the turtle.write) command to write a string at a location in the window. The program should pause when it is finished drawing so that we may admire your artistic masterpiece. Closing the window should end the program. 2

1.3 Code Specifics 1.4 Magic Numbers Instead of hardcoding numbers everywhere you use them, we suggest you make global constant variables. Of course Python doesn t have the notion of constants. As long as you do all your work in functions, and you don t use the global keyword, they will not be changeable. For example, the instructor solution uses the following. Feel free to add others. This helps to reduce the amount of arguments you need to pass to your function/s. # "constants" for the color used at each depth, e.g. depth=1 is red COLORS = red, orange, yellow, green, blue, blueviolet, violet # window dimensions WINDOW_LENGTH = 800 SIDE_LENGTH = 200 # pen sizes to use for filled and unfilled polygons FILL_PEN_WIDTH = 2 UNFILL_PEN_WIDTH = 8 1.5 Functions Minimally you should have the following functions: A main function. It should be responsible for handling the command line arguments, usage message, invoking the recursive drawing function, and displaying the total side lengths. A function to initial turtle, e.g. init. This should set up the window, coordinate system and draw the team names. A recursive function to draw the polygons. You may find it useful to have other helper functions that the recursive one uses. Outside of the globals mentioned above, you should only have arguments for handling the polygon side counting, the length of the side of the polygon, and the fill state. You are not allowed to use a global variable to count the total length drawn, It must be done recursively. 1.6 Command Line To specify the command line arguments using PyCharm, you will first need to run your program so you get a run configuration. Once you do this, the program will show up next to the green arrow and you can click/edit it. The field you want to change is called Script parameters. Here you should put the number of sides and fill state. To read these in Python, you need to use the sys module. Inside there is a Python list called argv which will contain the script parameters. The catch is the first entry in argv contains your program name (full path). The script parameters will come as strings in the second and third entry, e.g.: 3

import sys # imagine the program was run as: $ python3 polygons.py 5 fill print(sys.argv) # [.../polygons.py, 5, fill] len(sys.argv) # 3 sides = int(sys.argv[1]) # sides = 5 1.7 Color The turtle.color() method takes a string to use for the drawing color. Most of the basic colors are supported. 1.8 Filling Polygons To fill a polygon, the format of the code should be: turtle.begin_fill() # draw shape turtle.end_fill() 1.9 Speeding Up Drawing Turtle can be very slow to animate. It is useful when you are developing and debugging, but eventually once you know things work you will want it to run faster. To turn off animation, use the command: turtle.tracer(0,0) Your program should end with the following two statements to update the drawing window and enter the main loop: turtle.update() turtle.mainloop() 2 Grading This assignment will be graded using the following rubric: (15%) Problem Solving (10%) Design: Functions are used to break up the problem. Magic numbers are avoided. There is no use of the global keyword. The total length of all sides drawn is computed recursively. (65%) Functionality: 5% Command line argument handling. 4

10% Polygons are drawn and their sides count down recursively to a triangle. 15% Program can handle filling in polygons. 15% Program can handle unfilled polygons. 10% How interesting are the final images drawn? 10% Sum of all sides drawn is computed/displayed correctly. Version Control: 5% Code Style and Documentation: 5% 3 Submission The try command to submit is: try csapx-grd lab2-1 polygons.py log.txt Recall that to verify your latest submission has been saved successfully, you can run try with the query option, -q: try -q csapx-grd lab2-1 5