Before submitting the file project4.py, check carefully that the header above is correctly completed:

Similar documents
Before submitting the file project5.py, check carefully that the header above is correctly completed:

the drawcurve() function code comments aimed at helping you in writing the code for the TODOs defined later.

CMSC 201 Fall 2016 Homework 6 Functions

Computer Science 173 Fall, Project 3: Lindenmayer Systems Due in class on Monday, September 28

CS 315 Data Structures Fall Figure 1

Control Flow: Loop Statements

CS1110 Lab 5: Practice for A4 (Mar 8-9, 2016) First Name: Last Name: NetID:

Programming Assignment 1: CS11TurtleGraphics

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

Lab 7: Python Loops and Images 1

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

CS 463 Project 1 Imperative/OOP Fractals

Measures of Dispersion

AREA Judo Math Inc.

CSE115 Lab 4 Fall 2016

CMPSCI 119 LAB #2 Anime Eyes Professor William T. Verts

CS 4300 Computer Graphics. Prof. Harriet Fell Fall 2012 Lecture 28 November 8, 2012

CS195H Homework 1 Grid homotopies and free groups. Due: February 5, 2015, before class

CSE 167: Lecture #17: Procedural Modeling. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Programming Assignment 2 ( 100 Points )

CMSC 201 Spring 2018 Project 2 Battleship

CS 051 Homework Laboratory #2

CSE 167: Lecture #15: Procedural Modeling. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

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

Spring CS Homework 3 p. 1. CS Homework 3

Title: Perimeter Playground

Lab 2: Booleans, Strings, Random Numbers, Recursion, Variables, Input function

Programming Assignment 8 ( 100 Points )

Mathematics 350 Section 6.3 Introduction to Fractals


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

Homework 1: Getting Started with WebGL and Transformations EE267 Virtual Reality 2018

AVAL 6.6. User Manual Maps

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)

+. n is the function parameter and the function returns the sum.

Fractals and L- Systems

There s already a ton of code written called libraries that we can use by importing. One that we use often is random

CMSC 201 Spring 2016 Homework 7 Strings and File I/O

CISC 1600 Lecture 3.1 Introduction to Processing

CS Homework 2 p. 1. CS Homework 2

NOTE: Your grade will be based on the correctness, efficiency and clarity.

Koch-Like Fractal Images

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

Programming Assignment 2 (PA2) - DraggingEmoji & ShortLongWords

CHAPTER 3: FUNCTIONS IN 3-D

CHAPTER 3: FUNCTIONS IN 3-D

Programming Assignment 2 ( 100 Points ) Due: Thursday, October 12 by 11:59pm

SPH3U1 Lesson 09 Kinematics

CS143: Introduction to Computer Vision Homework Assignment 3

Polygons in the Coordinate Plane

1 Check it out! : Fundamentals of Programming and Computer Science, Fall Homework 3 Programming: Image Processing

Hacettepe University Department Of Computer Engineering Bil203 Programming Laboratory Experiment 2

CMPSCI 119 LAB #2 Greebles / Anime Eyes Professor William T. Verts

Problem J1: Squares. Sample Session 1 Program Output: Number of tiles? User Input: 9 Program Output: The largest square has side length 3.

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL

CSE 142, Autumn 2018 Programming Assignment #9: Critters (20 points) Due Tuesday, December 4th, 9:00 PM

CMSC 201 Spring 2018 Project 3 Minesweeper

CSF Omaha Requalification Application Instructions

CS 101 Computer Science I Fall Instructor Muller. stddraw API. (DRAFT of 1/15/2013)

Rotated earth or when your fantasy world goes up side down

Assignment 2 Ray Tracing

The exam begins at 2:40pm and ends at 4:00pm. You must turn your exam in when time is announced or risk not having it accepted.

Lecture 15. For-Loops

AP Computer Science Unit 3. Programs

Midterm Exam CS 184: Foundations of Computer Graphics page 1 of 11

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

We will start our journey into Processing with creating static images using commands available in Processing:

CMPE 655 Fall 2016 Assignment 2: Parallel Implementation of a Ray Tracer

SPH3U1 Lesson 05 Kinematics

Math 5593 Linear Programming Final Exam

Computer Science Foundations of Computer Graphics

3.7. Vertex and tangent

Escape-Time Fractals

Department of Electrical Engineering and Computer Sciences Fall 2000 Instructor: Dan Garcia CS 3 Final Exam

CpSc 101, Fall 2015 Lab7: Image File Creation

CS 1803 Pair Homework 4 Greedy Scheduler (Part I) Due: Wednesday, September 29th, before 6 PM Out of 100 points

Use lists. Use loops. Use conditionals. Define and use functions. Create and use code modules

Unit 5 Test 2 MCC5.G.1 StudyGuide/Homework Sheet

CS 2704 Project 1 Spring 2001

Mandatory Exercise 1 INF3110


Object-Oriented Programming in Processing

I-Carver CNC Project Computer Directions. Rob MacIlreith Last Update Oct 2017

Effective Programming in C and UNIX Lab 6 Image Manipulation with BMP Images Due Date: Sunday April 3rd, 2011 by 11:59pm

15-110: Principles of Computing, Spring 2018

Read every line of the exam sheet before programming!

cd h: mkdir -p CS101 cd CS101 curl -O unzip zipfile cd CS101_Exam4

Problem Set 1 Due: 11:59pm Wednesday, February 7

AP Calculus AB Summer Assignment 2018

CS39N The Beauty and Joy of Computing

1. Complete these exercises to practice creating user functions in small sketches.

CSE 231 Summer 2018 Computer Project #4

CS 373: Combinatorial Algorithms, Fall Name: Net ID: Alias: U 3 / 4 1

DEPARTMENT OF MATHEMATICS AND STATISTICS QUEEN S UNIVERSITY AT KINGSTON MATH 121/124 - APR 2014 A. Ableson, T. Day, A. Hoefel

Model Solutions. COMP 102: Test 1. 6 April, 2016

Circle inversion fractals are based on the geometric operation of inversion of a point with respect to a circle, shown schematically in Fig. 1.

CS 130 Final. Fall 2015

How to create a realistic looking turtle - Modeling part 1

CompSci 105 S2 C - ASSIGNMENT TWO -

Transcription:

1 of 7 8/26/2013 12:43 PM Due date: November 7th, 23:59PM This is a team project. The project is worth 100 points. All the team members will get an equal grade. ONLY the team leader must turn-in the project. VERY IMPORTANT!!! You MUST specify the following information at the beginning of the project4 file: Team leader: Last name, First name, Purdue account Team member 1: Last name, First name, Purdue account Team member 2: Last name, First name, Purdue account Before submitting the file project4.py, check carefully that the header above is correctly completed: If the file project4.py does not contain the header above, only the student submitting the file will receive the grade. This will apply also in the case that the team was registered. Only the team members listed in the header of project4.py file will receive the grade. In this project you will use the PIL functions to render a 2D curve encoded by a text string. The text string consists of a sequence of N, S, W, and E characters. N,S,W,E mean respectively: go forward in the north direction, go forward in the south direction, go forward in the west direction go forward in the east direction You can think of the curve as describing the movement of a turtle (or the movement of a car, or the movement of a person). When dealing with movements in the 2D plane, we need to specify the initial position and the initial orientation of the moving subject, as well as the length of the movement. To simplify the problem, you can assume that the initial orientation of the turtle is toward north and parallel to the Y axis of the 2D plane, and that each movement has the same length (10 units). The initial position of the turtle will be at the center of a window. The dimensions (width and height) of this window will be given to you in a file. The curve described by the character string is known as the Dragon curve. The Dragon curve is a member of a family of so-called self-similar fractal curves, which can be approximated by recursive methods (you will learn about recursion later in the course). As you can easily guess, there is some math involved to understand how they work. If you are interested, you can read

2 of 7 8/26/2013 12:43 PM the wiki page here: http://en.wikipedia.org/wiki/dragon_curve [http://en.wikipedia.org/wiki/dragon_curve]. Self-similar fractal curves produce beautiful images. But the striking facts are that i) a number of natural phenomena exhibit fractal features (see http://en.wikipedia.org/wiki/fractalnatural_phenomena_with_fractal_features [http://en.wikipedia.org/wiki/fractalnatural_phenomena_with_fractal_features]); ii) these phenomena, such as the growth of a plant, can be described by (relatively) simple mathematical models. The Dragon curve, for example, is the graphical representation of the Lindenmayer system (or L-system). A L-system provides a formal description of the development of simple multi-cellular organisms (see http://en.wikipedia.org/wiki/lindenmayer_system [http://en.wikipedia.org /wiki/lindenmayer_system]). For simplicity we have provided a text file that contains a dragon curve as a string of cardinal directions (NSEW) and the dimensions of the window over which you must draw. Your job will be to take this string as input and draw the corresponding curve in a 2D window. To draw the segment corresponding to the movement, you have to set the color of the pixels corresponding to the movement to a given color. Your program will ask to the user the color to be used (see TODO 4). This project will use the Python libraries, PIL Image, and random You will need to use the random library to generate a random integer for the project. This can be done using the following function: random.randint(a,b). This function will return a random integer N such that a <= N <= b Create a folder project4 under your folder CS177. Download there the file :dragon_inputs.zip. It contains the files for the Test Cases. filename project4-sk.py CS177 Fall 2012 - Project4 IMPORTANT: The following information MUST be filled!!! Team leader: Last name, First name, Purdue account Team member 1: Last name, First name, Purdue account Team member 2: Last name, First name, Purdue account TODO1 write function colorpixel TODO2 write function flipaxis TODO3 write function checkbounds

3 of 7 8/26/2013 12:43 PM TODO4 write drawline function TODO5 write main function ask user for file to open convert the color string to (r,g,b) color The input file(s) provided to you (dragon_txt, dragon_txt, and dragon_txt) have the following format: NOTES one or more character strings. Each string consists of a combination of 'N', 'S', 'E', or 'W' and is terminated by the <newline> character. the width of image, followed by <newline> the height of image followed by <newline> <newline> represents the '\n' character which encodes a new line in a text document. the input file may contain the encoding of more than one curve; in that case you have to draw all curves Look at the files dragon_txt, dragon_txt and dragon_txt, provided to you in the dragon_inputs.zip file, to see how a curve is encoded. Look at the output of the test cases in the section Test Cases of this document to get an idea of the curve that must be drawn. The directions for curve creation are given in the form of cardinal directions (NSEW) To make things easier for a novice user (and harder for you!), we want to use a standard coordinate system with the origin (0,0) in the bottom left corner of the image. If the program detects the input 'N' then the image should draw a line North(upwards) from the current position Write the function colorpixel. This function will take in three input arguments, position, color, and myimage, where: position is the 2D coordinate of the current position, that is, a couple of integers x and y, where x is the x-axis position, and y is the y-axis position color is a triple (r,g,b) containing the color to be used when drawing the pixel myimage is the PIL image we are editing

4 of 7 8/26/2013 12:43 PM The function must take the pixel at position and set its color to the color specified as input argument Write the function flipaxis. This function will have two arguments, position and bounds: position is the 2D coordinate of the current position, that is, a couple of integers x and y, where x is the x-axis position, and y is the y-axis position bounds is a couple of (maxx,maxy), which is the width and height of the current image. This function will translate the position from that of a standard coordinate system - that is, one where the origin (0,0) is in the bottom left corner -, to one which PIL understands. Since we want the origin (0,0) to be in the bottom left corner of the image and PIL images have the origin in the top left corner, we need to convert between the two. When drawing the segment corresponding the encoded movement, it may be possible that the segment exceeds the width/height of the image. In this case you do not generate an error and terminate the drawing. Rather, you must write a function checkbounds that : checks the current position, that is the position of the last pixel of the segment corresponding to the last movement generated. If the position is outside the bounds of the image, it must be reset to the position of the nearest edge. If the position is within the bounds, it will simply return the current position. This function will take two input arguments, position and bounds: position is a tuple of (x,y) where x is the x position, and y is the y position of the last pixel of the last movement bounds is a tuple of (maxx,maxy), which is the width and height of the current image. it will return the updated tuple for position Write the function drawline. This function will draw a line of length 10 pixels in the direction specified by the direction input argument. HINTS This function will take in four input arguments, position, direction, color, and myimage: position is the 2D coordinate of the current position, that is, a couple of integers x and y, where x is the x-axis position, and y is the y-axis position direction is a single character ('N', 'S', 'E', or 'W') that determines the direction of the line color is a triple (r,g,b) which will be the desired color of the line myimage is the PIL image we are editing This function will return the x,y coordinate of the pixel corresponding to the ending point of the drawn line segment Start the line by setting the pixels' color at the current position to the specified color. Move one pixel at a time in the appropriate direction and set the pixels' color to the specified color. Be sure you check the pixel position by calling the checkbounds function after each move of the current position.

5 of 7 8/26/2013 12:43 PM 4. If the required color is random, you need to create a random color. Remember that a color has three color channels and that each of them is an integer >=0 and < 255 (See TODO 5) Write the function main. This function has no arguments. HINTS The function must do the following things: ask the user for the name of the input file, and store it in a variable. ask the user for the color, and store it in a variable. convert the color string to (r,g,b) representation. 4. open the input file. 5. read the input data from the file. Its contents were described above under section InputFile. 6. use the acquired data to generate the dragon curve(s) as necessary. a. as you are drawing the curve, after each move save the ending line segment position into a list. 7. save the image when you are finished. The saved file must have the name dragon_image_.jpeg where can be incremented if the input file has multiple dragon curves. For example, if the input file contains two curves, you must save the two images you generated in the files named dragon_image_jpeg and dragon_image_jpeg 8. save the movement list to a text file. The file should have the name dragon_moves_.txt where can be incremented if the input file has multiple dragon curves. Begin by converting the input color to an (r,g,b) representation of the input color. a. 'red', 'green', 'blue', or 'random' are the only options to the used for color b. if the color is 'random', use the function random.randint described above to generate a random value for r, g, and b I. when the color is 'random' you must generate a new color for each move! This means the output curve will be multi-colored. c. if the user does not input a color, or inputs an invalid color, set the color to black When drawing a dragon curve always set the initial position to the center of the blank image. To draw the dragon curve you will need to execute each movement (NSEW). After each movement has been drawn save the updated position tuple in a list. After the curve is completely drawn output that list to the save file. The prompts should look like the following ones: Please input file to open: Please input color (red, green, blue, or random): Thank you come again TestCase1 a. file:dragon_txt b. color: orange c. output: dragon_moves_txt

6 of 7 8/26/2013 12:43 PM d. TestCase2 a. file:dragon_txt b. color: red c. output: dragon_moves_txt d. TestCase3 a. file:dragon_txt b. color: random c. output: dragon_moves_txt I. Same as TestCase1 but in random color II. Same as TestCase2 but in random color

7 of 7 8/26/2013 12:43 PM III. 4. TestFiles:dragon_inputs.zip TODO Points TODO1 10 TODO2 10 TODO3 20 TODO4 30 TODO5 30 TOTAL 100 Login into your UNIX CS account. Then go to your project4 folder using the following commands: $cd CS177 $cd project4 Then launch the following command AS IS: $turnin -v -c cs177=common -p project4 *.py cs17700/projects/project4.txt Last modified: 2012/11/09 14:10 by rglasser