Skip to main content
留学咨询

新南威尔士大学 COMP1511 Assignment1 课业解析

By May 15, 2020No Comments

新南威尔士大学 COMP1511 Assignment1 课业解析题意:使用C语言开发一款画图软件,允许用户在终端输入一串命令在画布上画画,输出一个存储像素信息的数组解析:  用一个int型2维数组代表画布,每个元素代表电子画布的像素,二维数组初始化时值为4(4代表white,3代表light,2代表grey,1代表dark,0代表black);程序读取用户指令(一串int型数字,Ctrl+D结束输入),处理并输出数组的值。如指令draw
line——画一条线段,用户输入1
5 5 5 180代表画一条线段,1代表画线段,起始点是(5,5),方向向下,长度为5个像素。  第一阶段要求实现画线段(水平和竖直方向)和正方形功能,画正方形例如2 6 6 4 0,2表示填充一个正方形,以(6,6)为起始点沿向上方向延伸4个像素为正方形对角线,填充该正方形区域;第二阶段要求实现绘制对角线方向的线段以及改变像素点颜色;第三阶段要求实现复制粘贴选定正方形区域的像素内容并粘贴到目标区域,例如4
0 0 3 135 0 10,4代表复制粘贴命令,从(0,0)开始,沿右下方延伸3个像素点,复制以此为对角线的正方形区域像素,并粘贴到以(0,10)为起始点的正方形区域上。第三、四阶段要求实现绘制椭圆,例如0
0 0 3 3 5.5 1,0表示绘制椭圆,第一个焦点是(0,0),第二个焦点是(3,3),动点P到两焦点的距离和为2*5.5=11,绘制动点P的运动轨迹形成的椭圆,1表示填充椭圆内部所有像素,若为0则只画轮廓。涉及知识点:数组、类、while更多可加微信讨论微信号yzr5211234
pdf
2019/10/9 Assignment 1 – CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 1/30COMP1511 19T3 Assignment 1 – CS Paint COMP1511 19T3version: 1.1 last updated: 2019-10-09 14:00CS Paint²The year is 1985 . . . Microsoft has just released Windows 1.0 and packaged with it is a beautiful program called Paint, later referred toas MS Paint. For many people, this program is the beginning of a wonderful journey into the world of digital art.In this assignment, you will be implementing CS Paint, COMP1511’s answer to the venerable drawing program. CS Paint is a programthat allows us to draw images to our terminal using a series of commands. The commands are made up of integers (and in later stages,doubles) and are typed directly into our program. Each command will make some change to a digital canvas, a space for drawing.CS Paint is already capable of setting up and drawing its canvas, it will be up to you to write code so that it can read commands andmake the correct changes in the canvas.Note: At time of release of this assignment (end of Week 3), COMP1511 has not yet covered all of the techniques and topics necessaryto complete this assignment. At the end of Week 3, the course has covered enough content to be able to read in a single command andprocess its integers, but not enough to work with two dimensional arrays like the canvas or be able to handle multiple commandsending in End-of-Input (Ctrl-D). We will be covering these topics in the lectures, tutorials and labs of Week 4.2019/10/9 Assignment 1 – CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 2/30The CanvasThe canvas is a two dimensional array (an array of arrays) of integers that represents the space we will be drawing in. We will bereferring to individual elements of these arrays as pixels on the canvas.The canvas is a fixed size and has N_ROWS rows, and N_COLS columns. Both of these are defined constants.Both the rows and columns start at 0, not at 1.The top left corner of the canvas is (0, 0) and the bottom right corner of the canvas is (N_ROWS – 1, N_COLS – 1). Note that weare using rows as the first coordinate in pairs of coordinates.For example, if we are given an input coordinate 5 10, we will use that to find a particular cell in our canvas by accessing the individualelement in the array: canvas[5][10]The integers in the pixels represent colours between black (which we call 0) and white (which we call 4). We will be starting with awhite canvas and drawing black onto it, but as we progress, we will also be using shades of grey (not 50 of them, just a few). Note thatthese colours assume you have white text on a black background.For reference, the shades are:Black (0):Dark (1): ░░Grey (2): ▒▒Light (3): ▓▓White (4): ██An empty canvas is shown below. In this documentation, we will always show you two versions of the output. In the “Output” you cansee the version that your program is expected to produce (numbers between 0 and 4).In the “Output (Stylized)” tab you can see a more readable version with the numbers converted to shades.Note that you are not expected to produce this stylized output – we have tools that will convert it for you. Your program only needs toprint the grid of numbers, as shown in the “Output” tab.2019/10/9 Assignment 1 – CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 3/30Empty CanvasOutput Output (stylized)$ dcc -o cs_paint paint.c$ ./cs_paint < /web/cs1511/19T3/cs_paint/demos/empty_canvas.in4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 42019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 4/30The CommandsEach command given to the program will be a series of integers (or in the later stages, integers and doubles).The first input will always be an integer representing the type of command, e.g. 1 means Draw Line.Depending on what command the first integer specifies, you will then scan in some number of "arguments" (additionalintegers/doubles) that have a specific meaning for that command.For example:Command Meaning1 5 5 5 180 DRAW LINE STARTING AT (row 5, col 5) WHICH IS 5 PIXELS ACROSS, AT 180 DEGREES.(see below for more details on this and other commands).Your Task: ImplementationYour task for this assignment is to write a program that reads in one or more commands and outputs a canvas that shows the result ofthe commands.Your program will be given commands as a series of integers on standard input. Your program will need to scan in these integers andthen make the necessary changes in the canvas.Initial tests will be with a single command per run of the program, but more advanced tests will expect the program to be able to scanand run multiple commands.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 5/30Allowed C FeaturesIn this assignment, there are no restrictions on C Features, except for those in the Style Guide.We strongly encourage you to complete the assessment using only features taught in lectures up to and including Week 4. The only Cfeatures you will need to get full marks in the assignment are:int and double variables.if statements, including all relational and logical operators.while loops.int arrays.printf and scanf.functions.For Stage 4, you may need the sqrt function from math.hUsing any other features will not increase your marks (and will make it more likely you make style mistakes that cost you marks).Particularly, you do not need to use any pointers (or malloc) to gain full marks. They will only complicate the assignment. You also donot need to use for loops, and they are strongly discouraged.If you choose to disregard this advice, you must still follow the Style Guide. You also may be unable to get help from course staff ifyou use features not taught in COMP1511.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 6/30Starter CodeYou should download the above files to start the assignment.paint.c is the starting point for your CS Paint program. We've provided you with some starter code to construct a canvas and todisplay it on the screen; you'll be completing the rest of the program.tests.zip is a collection of test files that you can use to test your program. Each test file contains a series of commands that yourprogram can use to draw images on the canvas.Download the starter code (paint.c) here or download it to your CSE account using the following command:$ wget https://cgi.cse.unsw.edu.au/~cs1511/19T3/activities//cs_paint/paint.c .Download the test files (tests.zip) here or download it to your CSE account using the following command:$ wget https://cgi.cse.unsw.edu.au/~cs1511/19T3/activities//cs_paint/tests.zip .2019/10/9 Assignment 1 - CS Pai nthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 7/30Input CommandsInput to your program will be via standard input (similar to typing into a terminal).You can assume that the input will always be integers (or doubles, where specified) and that you will always receive the correct numberof arguments for a command.You can assume that input will always finish with the "End of Input" signal (Ctrl-D in the terminal).Details on each command that your program must implement are shown below.There will be tests involving a large amount of commands, and you should not store all of your input in an array. You should processeach command as you read it.Stage OneStage One implements basic drawing functions, giving your program the ability to draw lines and squares.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 8/30Line DrawingIn Stage 1, you will be implementing the Draw Line command to draw horizontal and vertical lines.The Draw Line command is given four additional integers, which describe a starting pixel, a length, and a direction.The starting pixel consists of two numbers: the index of the row, and the index of the column.The length is a non-negative number which specifies the length of the line. A line of length 0 should not show anything. A line of length1 is one pixel. In general, a line's length is the number of pixels in it. The canvas begins as being filled with fours, and you should (untilyou're told otherwise, later in the spec) draw 0's.The direction is a positive number in degrees, starting from 0 degrees being north (i.e. drawing upwards), and rotating clockwise.In Stage 1 you will only be drawing vertical or horizontal lines, which means the direction will always be a multiple of 90:0 degrees is "up" - a vertical line, where the row you end in (the "end row") will be above the row you started in (the "startrow").90 degrees is "right" - a horizontal line, where the end column will be to the right of the start column.180 degrees is "down" - a vertical line, where the end row will be below the start row.270 degrees is "left" - a horizontal line, where the end column will be to the left of the start column.Degrees greater than or equal to 360 are valid, and should be treated as being modulo 360 (e.g. 450 degrees would beequivalent to 90 degrees).For example, the command 1 10 3 7 180 tells your program to draw a line (1), starting at the pixel at (row 10 and column 3),moving down 7 pixels at a 180 degree angle.When given the Draw Line command, your program should set the colour of the relevant elements (pixels) in the canvas array,starting at the provided start pixel location, and continuing along the horizontal or vertical line until it reaches the end pixel location(including both the start and end pixels themselves). In the beginning, you will set the colour to 0, but later in the assignment you willneed to use more colors.HintsIf length == 0, your program should draw nothing.If length == 1, your program should draw a single pixel, at the location (start_row, start_col).If direction is greater than or equal to 360 (for instance 720), you should treat it as with any angle - 720 is the same as 360which is the same as 0.Until you're told otherwise, you should use the colour '0' to colour your lines.Line Drawing: SummaryCommand "Draw Line"Instruction 1Inputs start_row start_col length directionExamplesCommand Meaning1 10 3 8 180 DRAW LINE STARTING AT (row 10, col 3) WHICH IS 8 PIXELS ACROSS, AT 180 DEGREES.1 1 1 9 90 DRAW LINE STARTING AT (row 1, col 1) WHICH IS 9 PIXELS ACROSS, AT 90 DEGREES.1 9 1 9 0 DRAW LINE STARTING AT (row 9, col 1) WHICH IS 9 PIXELS ACROSS, AT 0 DEGREES.1 2 2 1 0 DRAW LINE STARTING AT (row 2, col 2) WHICH IS 1 PIXELS ACROSS, AT 0 DEGREES.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 9/30Handling Invalid InputIf the given start pixel, length and direction would cause a line to be drawn outside of the canvas (either partially or entirely),your program should ignore that Draw Line command and do nothing.For this stage, if the given direction would not give an entirely horizontal or vertical line, your program should ignore that DrawLine command and do nothing.You can assume you will never receive a negative direction (a degree less than 0).ExamplesShow Test-Case: Horizontal LineShow Test-Case: Vertical LineShow Test-Case: Empty LineShow Test-Case: BoxShow Test-Case: Invalid Lines2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 10/30Square DrawingFor the second part of Stage 1, you will be implementing the Fill Square function, to draw squares. The Fill Square command is givenfour additional integers, which describe a starting pixel, a length, and a direction.The starting pixel consists of two numbers: the index of the row, and the index of the column.The length is a non-negative number which specifies the length of the square's diagonal. A line of length 0 means no square will beproduced. A diagonal of length 1 creates a square with 1 pixel. In general, a square will have (length) * (length) pixels coloured.The direction is a positive number in degrees, starting from 45 degrees being up-and-right, moving clockwise.0, 90, 180, 270 degrees - this command should act the same as the Draw Line command.45 degrees - the starting pixel is on the bottom left and moves to the top right.135 degrees - the starting pixel is on the top left and moves to the bottom right.225 degrees - the starting pixel is on the top right and moves to the bottom left.315 degrees - the starting pixel is on the bottom right and moves to the top right.Degrees that are not diagonal (those listed above) should cause no line to be drawn.Degrees greater than 360 are valid, and should be treated as being modulo 360.For example, the command 2 5 5 5 135 tells your program to draw a square, starting at row 5 and column 5, that has a diagonal of5 pixels in a down-and-right direction (135 degrees).Square Drawing: SummaryCommand "Fill Square"Instruction 2Inputs start_row start_col length directionExamplesCommand Meaning2 0 0 10 45FILL SQUARE STARTING AT (row 0, col 0) WHICH IS 10 PIXELS DIAGONALLY, AT 45DEGREES.2 6 6 4 0 FILL SQUARE STARTING AT (row 6, col 6) WHICH IS 4 PIXELS DIAGONALLY, AT 0 DEGREES.2 6 6 2 225FILL SQUARE STARTING AT (row 6, col 6) WHICH IS 2 PIXELS DIAGONALLY, AT 225DEGREES.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 11/30When given the Fill Square command, your program should build a square. It does this by first finding a diagonal line using a startingpixel, a length and a direction. The pixels at either end of this line define the outer limits of a square. It must then draw all the pixels ofthat square. You can assume that the edges of the square are either vertical or horizontal, there are no rotated squares.HintsIf length == 0, your program should draw nothing.Invalid InputIf the given start pixel, length and direction would cause a square to be drawn outside of the canvas (either partially or entirely),your program should ignore that Fill Square command and draw nothing.ExamplesStage TwoIn Stage 2, you will be extending the functionality of your Draw Line and Fill Square commands from Stage 1.We strongly recommend that you finish Stage 1 before attempting Stage 2, as it would be very hard to test whether Stage 2 is workingwithout Stage 1.Note that completing Stage 2 is not necessary to gain a passing mark in this assignment.Show Test-Case: Small SquareShow Test-Case: Big SquareShow Test-Case: Little Pixel Boxes2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 12/30DiagonalsFor the first part of Stage 2, you will be modifying your Draw Line command to be able to draw diagonal lines.Your program must still be able to draw horizontal and vertical lines as specified in Stage 1.Your program will only be required to draw diagonal lines that are on a 45 degree angle (see the diagram of angles in the SquareDrawing section).ExamplesLine Drawing: Diagonals : SummaryCommand "Draw Line"Instruction 1Inputs start_row start_col length directionExamplesCommand Meaning1 0 0 9 135 DRAW LINE STARTING AT (row 0, col 0) WHICH IS 9 PIXELS ACROSS, AT 135 DEGREES.1 3 3 2 315 DRAW LINE STARTING AT (row 3, col 3) WHICH IS 2 PIXELS ACROSS, AT 315 DEGREES.Show Test-Case: NegativesShow Test-Case: Multiple Diagonal LinesShow Test-Case: Other Angled Lines2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 13/30Negative DistancesYour program should now also handle negative lengths, in both the Draw Line and Fill Square. A negative length is the same asgoing a positive length in the other direction.For instance, travelling a length of -3 at 45 degrees is the same as travelling a length of 3 at 225 degrees.This should not otherwise change the behaviour of the commands.ExamplesShow Test-Case: Negative LinesShow Test-Case: Negative Squares2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 14/30ShadeFor the second part of Stage 2, you will be implementing the Change Shade command, which gives you access to both an eraser anddifferent shades of grey.In CS Paint there are a total of five shades, which we call {BLACK, DARK, GREY, LIGHT, WHITE}. They are each represented by anumber between 0 (for BLACK) and 4 (for WHITE).The Change Shade command is given one additional integer: the difference between the current shade and the new shade. Forinstance, to change from WHITE to BLACK you should enter -4By default, your program should start with the shade BLACK.HintsPainting over any other colours in the canvas replaces them with whatever colour the current shade is.The new shade should be used for both the Draw Line and Fill Square commands.Handling Invalid InputIf the given shade difference is invalid (if it would cause the shade to be negative, or to be greater than 4), ignore that ChangeShade command and do nothing.ExamplesStage ThreeIn Stage 3 and 4, you will be implementing more advanced commands.Again, we strongly recommend that you finish Stage 1 and Stage 2 before attempting Stage 3.Note that completing Stage 3 is not necessary to gain a passing mark in this assignment.Shades: SummaryCommand "Change Shade"Instruction 3Inputs new_shadeExamplesCommand Meaning3 2 CHANGE COLOUR, ADDING 2 TO THE CURRENT COLOUR.3 1 CHANGE COLOUR, ADDING 1 TO THE CURRENT COLOUR.Show Test-Case: Coloured LinesShow Test-Case: Coloured Boxes2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 15/30Copy and PasteFor Stage 3, you will be implementing the Copy Paste command, which allows you to copy a certain section of the canvas, and paste itelsewhere on the canvas.The Copy Paste command is given six additional integers, which describes a start pixel, a length and direction, and a target pixel.The first four values define a square, in the same way that Draw Square does. This is the region that will be copied. The last twovalues define a target pixel, which is the corner of another square (defined by the target pixel, and the previous integers describinglength and direction).In other words, you are given six integers:start_row: The starting row of the square being copied fromstart_col: The starting column of the square being copied fromlength: The length of the diagonal of the copied square.direction: The direction (in degrees) the diagonal is drawn.target_row: The starting row of the square being copied totarget_col: The starting column of the square being copied toThis command should copy every pixel in the square starting at (start_row, start_col), with length * length pixels atdirection degrees. It should copy those pixels to a square starting at (target_row, target_col), with the same area, also goingat direction degrees.The diagram below describes what these points are:Copy and Paste: SummaryCommand "Copy Paste"Instruction 4Inputs start_row start_col length direction target_row target_colExamplesCommand Meaning4 0 0 3 135 0 10COPY SQUARE STARTING AT (row 0, col 0) WHICH IS 3 PIXELS ACROSS, AT 135 DEGREESPASTE STARTING AT (row 0, col 10).2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 16/30After calling the Copy Paste command, every pixel in the rectangle bounded by start and end should be copied to a rectangle of thesame size that has target as its top left pixel.HintsThe pixels should be copied exactly, the current shade setting has no effect on the pixels being copied.Invalid InputIf any of the given pixels would cause any part of the copying or pasting to go outside of the canvas, your program should ignorethat Copy Paste command and do nothing.For this stage, you may ignore the possibility that two regions will overlap.ExamplesShow Test-Case: Copy Paste Line Colours2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 17/30Ellipse DrawingIn Stage 3, you will also be implementing the Draw Ellipse command to colour in the shape of an ellipse on the canvas.The Draw Ellipse command is given six additional integers, which describes two focus pixels, a length (which will be a double), and anadditional integer that for the purposes of this stage will always be non-zero (this will later be used to decide whether to fill the ellipse).The definition of an ellipse is a shape consisting of all points where the sum of the distances to the two focus points is equal to twicethe given length. You should colour all points that lie on or inside the ellipse.In other words, you are given six integers:focus1_row: The row in which the first focus lies.focus1_col: The column in which the first focus lies.focus2_row: The row in which the second focus lies.focus2_col: The column in which the second focus lies.length: The length that defines the size of the ellipse, as described below. This will be a double, not an integer.fill: If this is non-zero, fill in the ellipse, otherwise, only draw the outline of the ellipse.This command should colour in all of the pixels on the canvas where:distance(focus1, pixel) + distance(pixel, focus2) ≤ 2 * length.The diagram below describes what these points are:HintsEllipse Drawing: SummaryCommand "Draw Ellipse"Instruction 0Inputs focus_1_row focus_1_col focus_2_row focus_2_col length fillExamplesCommand Meaning0 0 0 3 3 5.51; WITH FOCAL POINTS (row 0, col 0) AND (row 3, col 3) WITH RADIUS 2 * 5.5, FILLEDIN..2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 18/30You may notice that there's a function in the provided code called double distance(int row1, int col1, int row2, intcol2)This code is provided as a function that you can use to calculate the distance between two pixels. You will not have to edit this functionbut you will need to call this function to be able to draw an ellipse.Invalid InputUnlike previous commands, if part of the ellipse would be off the canvas your program should not ignore the command, andshould instead fill in all of the relevant pixels that are on the canvas.ExamplesStage FourIn Stage 4, you will again be implementing more advanced commands.Again, we strongly recommend that you finish Stage 1, 2 and 3 before attempting Stage 4.Note that completing Stage 4 is not necessary to gain a passing mark in this assignment.Show Test-Case: Circles are EllipseShow Test-Case: Ellipse2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 19/30Overlapping Copy PasteFor Stage 4, you should ensure your program can deal with overlapping copies and pastes, that is, you can no longer assume thatwhere you are copying from will not be pasted within.The behaviour of the Copy Paste command should otherwise remain the same as described.ExamplesShow Test-Case: Overlapping Copy Paste2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 20/30Hollow Ellipse DrawingFor Stage 4, you should modify your program such that when the last integer in the Draw Ellipse command is zero, you create a'hollow' ellipse.The definition of a 'hollow' e llipse is the same definition as a normal ellipse, but it excludes all pixels that are not directly above, belowor to the side of a pixel that would not be in the theoretical ellipse. Those pixels should remain unchanged.When provided with input as described in the previous section, the command's behaviour should remain unchanged.ExamplesHall of Fame ChallengesIf you have completed the assignment and are looking for further challenges, we have compiled a list of interesting ideas that couldextend CS Paint. We call these "Hall of Fame" challenges and for anyone who completes them, we will publicise your work on thecourse website! You can feel free to invent your own challenges as well (and if they are at least as interesting as the ones below, wewill list you on the Hall of Fame).Before starting these, you should have completed the assignment, and be passing all autotests. If you have questions about the Hall ofFame, ask your tutor, or post a query on the course forum.These challenges have no autotests, but completing them will result in your name being immortalised in the Hall of Fame for theassignment. They are, however, not worth any marks.To submit a Hall of Fame attempt for testing, you should send it to [email protected] with the subject line "Hall ofFame Submission z5555555". Your email body should include a description of the challenge exercise, and a guide to how to run andtest your solution. You should attach your paint.c (and any other) files.There are five challenges available:1. Use the command 9 to mean "fill".It should take one pair of coordinates, and a new shade. Then, find all the pixels of the same colour that directly connect to thatpixel (in this case, that means that they share an edge with that pixel - pixels that are only diagonally connected do not count).Those pixels should all become the new shade mentioned in the command.Hollow Ellipse Drawing: SummaryCommand "Draw Ellipse"Instruction 0Inputs focus_1_row focus_1_col focus_2_row focus_2_col length fillExamplesCommand Meaning0 0 0 3 3 5.50; WITH FOCAL POINTS (row 0, col 0) AND (row 3, col 3) WITH RADIUS 2 * 5.5, NOTFILLED..Show Test-Case: (Hollow) Circles are (Hollow) EllipsesShow Test-Case: Hollow Ellipse2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 21/30It should operate similar to the paint-bucket in MS Paint.2. Use the command 8 to mean "undo".The undo command should restore the state of the canvas before the most recent command.Solutions should not just save the entire previous board state - the more "intelligent" your solution (that can undo the board withless information), the better.3. Write a program (not necessarily in C) that takes an output canvas and converts it to a set of instructions that prints a greyscaleversion of that image (without knowing what the input commands were).Programs that produce shorter sequences of commands will be rewarded with adulation in the hall of fame. Your program shouldnot just print out pixel by pixel.4. Write a program (not necessarily in C) that takes some image (in a format of your choice) and converts it to a set of instructionsthat prints a greyscale version of that image.Again, the shorter output, the better (and it must not just print out pixel by pixel).5. Write a program that performs the same actions as CS Paint, that would be worth of entry into the IOCCCThese challenges are open to interpretation. If you have a question about how to complete it, ask on the course forum, or askyourself "What would be cooler". Submitting an entry isn't a guarantee that you will make the hall of fame (but we will let youknow if it does not make it, and why we have rejected it).TestingIt is important to test your code to make sure that your program can perform all the tasks necessary to become CS Paint!There are a few different ways to test (that are described in detail below):Typing in your own commands. You can use the commands shown above as examples, or work out your own.Testing from a series of commands written in a file. We have provided a set of test files that cover nearly all possiblesituations and commands that CS Paint should implement.Download the test files for the assignment here.Using autotests to run through all the test files at once.Running a Reference Implementation that we have created for you to compare against.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 22/30Testing your codeIf you are testing with your own commands or commands written in a file, you can either use numerical output or our canvasoutput.Getting raw numeric outputIf you are debugging, or want to see the raw numbers as output, you can compile and run your program as follows:$ lspaint.c tests/$ dcc -o cs_paint paint.c$ ./cs_paint[type in your commands here, then type Control+D][your canvas will print out]If you have an input file you want to run, you can specify them like this.$ lspaint.c test_file1.in test_file2.in$ dcc -o cs_paint paint.c$ ./cs_paint < test_file1.in[the output of running the commands in test_file1.in]This approach is limited to one input file at a time.Coloured Blocks using 1511 canvasYou can run the command 1511 canvas on CSE computers (including via VLAB) along with the name of your C file, and we willcompile it and show you the stylized output similar to in our examples in the Stages above.$ 1511 canvas paint.cYou have run canvas without specifying any tests.You may quit this program with Control + CYou can type lines below, and then press Control + D to see what output thoselines produce.[type in your commands here, then press Control + D]If you have input files you want to run, you can specify them like this.$ lspaint.c test_file1.in test_file2.in$ 1511 canvas paint.c test_file1.in test_file2.in==> test_file1.in <==[the output of running the commands in test_file1.in]==> test_file2.in <==[the output of running the commands in test_file2.in]If you have many files you want to run, you can use the asterisk (*) instead of a name to mean "every".2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 23/30$ ls tests/paint.c directory1 directory2$ ls directory1/tests/test_file1.in test_file2.in$ ls directory2/other_test1.in other_test2.in$ 1511 canvas paint.c */*==> directory1/test_file1.in <==[the output of running the commands in directory1/test_file1.in]==> directory1/test_file2.in <==[the output of running the commands in directory1/test_file2.in]==> directory2/test_file1.in <==[the output of running the commands in directory2/test_file1.in]==> directory2/test_file2.in <==[the output of running the commands in directory2/test_file2.in]$ 1511 canvas paint.c directory2/*==> directory2/test_file1.in <==[the output of running the commands in directory2/test_file1.in]==> directory2/test_file2.in <==[the output of running the commands in directory2/test_file2.in]2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 24/30Automated TestingOn CSE computers (including via VLAB), the input files we have provided can all be checked at once using the command:$ 1511 autotest cs_paint paint.c2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 25/30Reference ImplementationIf you have questions about what behaviour your program should exhibit, we have provided a sample solution for you to use.You can use it by replacing the name of your C file with the word solution like so (on CSE Computers or via VLAB):$ lstest_file1.in test_file2.in$ 1511 canvas solution test_file1.in test_file2.in==> test_file1.in <==[the output of running the commands in test_file1.in]==> test_file2.in <==[the output of running the commands in test_file2.in]Assessment2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 26/30Attribution of WorkThis is an individual assignment. The work you submit must be your own work and only your work apart from exceptions below.Joint work is not permitted.You may use small amounts (< 10 lines) of general purpose cod e (not specific to the assignment) obtained from site such asStack Overflow or other publically available resources. You should attribute clearly the source of this code in a comment with it.You are not permitted to request help with the assignment apart from in the course forum, help sessions or from course lecturersor tutors.Do not provide or show your assignment work to any other person (including by posting it on the forum) apart from the teachingstaff of COMP1511.The work you submit must otherwise be entirely your own work. Submission of work partially or completely derived from anyother person or jointly written with any other person is not permitted. The penalties for such an offence may include negativemarks, automatic failure of the course and possibly other academic discipline. Assignment submissions will be examined bothautomatically and manually for such submissions.Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or othermisconduct. If you knowingly provide or show your assignment work to another person for any reason, and work derived from itis submitted you may be penalized, even if the work was submitted without your knowledge or consent. This may apply even ifyour work is submitted by a third party unknown to you.Note, you will not be penalized if your work is taken without your consent or knowledge.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 27/30Submission of WorkYou are required to submit intermediate versions of your assignment.Every time you work on the assignment and make some progress you should copy your work to your CSE account and submit itusing the give command below.It is fine if intermediate versions do not compile or otherwise fail submission tests.Only the final submitted version of your assignment will be marked.All these intermediate versions of your work will be placed in a git repo and made available to you via a web interface at this URL,replace z5555555 with your zID:https://gitlab.cse.unsw.edu.au/z5555555/19T3-comp1511-ass1_cs_paint/commits/masterThis will allow you to retrieve earlier versions of your code if needed.You submit your work like this:$ give cs1511 ass1_cs_paint paint.c2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 28/30AssessmentThis assignment will contribute 13% to your final mark.80% of the marks for this assignment will be based on the performance of the code you write in paint.c20% of the marks for this assignment will come from hand marking of the readability of the C you have written. These marks willbe awarded on the basis of clarity, commenting, elegance and style. In other words, your tutor will assess how easy it is for ahuman to read and understand your program.Here is an indicative marking scheme.HD (85-100%) Successfully implements all of Stages One, Two and Three, with beautiful C code.Higher-grade High Distinctions will be awarded for the correctness and style of Stage Four.DN (75+%) Successfully implements all of Stages One and Two, with readable C code.Solutions that partially implement Stage Three with stylistic C code will be awarded higher-gradeDistinctions.CR (65+%) Successfully implements all of Stage One with readable C code.Solutions that partially implement Stage 2 will be awarded higher-grade Credits.PS (50+%) Reasonably readable C code that can draw vertical and horizontal lines correctly.Solutions that reject invalid input and do Square Drawing will be awarded higher-grade Passes.40-50% A substantial attempt at part of Stage 1, that is mostly able to draw horizontal and vertical lines.-70% Knowingly providing your work to anyone and it is subsequently submitted (by anyone).-70% Submitting any other person's work. This includes joint work.0 FL forCOMP1511Paying another person to complete work. Submitting another person's work without their consent.The lecturer may vary the assessment scheme after inspecting the assignment submissions but it will remain broadly similar tothe description above.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 29/30Due DateThis assignment is due Sunday 27 October 18:00If your assignment is submitted after this date, each hour it is late reduces the maximum mark it can achieve by 2%. Forexample if an assignment worth 74% was submitted 10 hours late, the late submission would have no effect. If the sameassignment was submitted 15 hours late it would be awarded 70%, the maximum mark it can achieve at that time.2019/10/9 Assignment 1 - CS Painthttps://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 30/30COMP1511 19T3: Programming Fundamentals is brought to you bythe School of Computer Science and Engineeringat the University of New South Wales, Sydney.For all enquiries, please email the class account at [email protected] Provider 00098GChange LogVersion 0.9(2019-10-07 01:00)Pre-release draft.Version 1.0(2019-10-07 02:00)Make assignment publicVersion 1.1(2019-10-09 14:00)Clarify you're supposed to set the lines to 0 in stage 1.  

admin

Author admin

More posts by admin