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

新南威尔士大学 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 1/30
COMP1511 19T3 Assignment 1 - CS Paint COMP1511 19T3
version: 1.1 last updated: 2019-10-09 14:00
CS Paint²
The year is 1985 . . . Microsoft has just released Windows 1.0 and packaged with it is a beautiful program called Paint, later referred to
as 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 program
that 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 and
make 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 necessary
to complete this assignment. At the end of Week 3, the course has covered enough content to be able to read in a single command and
process its integers, but not enough to work with two dimensional arrays like the canvas or be able to handle multiple commands
ending 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 2/30
The Canvas
The canvas is a two dimensional array (an array of arrays) of integers that represents the space we will be drawing in. We will be
referring 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 we
are 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 individual
element 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 a
white 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 that
these 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 can
see 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 to
print the grid of numbers, as shown in the "Output" tab.
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 3/30
Empty Canvas

Output Output (stylized)


$ dcc -o cs_paint paint.c
$ ./cs_paint < /web/cs1511/19T3/cs_paint/demos/empty_canvas.in
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
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 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 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 4 4 4 4 4 4
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 4/30
The Commands
Each 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" (additional
integers/doubles) that have a specific meaning for that command.
For example:
Command Meaning
1 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: Implementation
Your task for this assignment is to write a program that reads in one or more commands and outputs a canvas that shows the result of
the commands.
Your program will be given commands as a series of integers on standard input. Your program will need to scan in these integers and
then 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 scan
and run multiple commands.
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 5/30
Allowed C Features
In 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 C
features 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.h
Using 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 do
not 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 if
you use features not taught in COMP1511.
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 6/30
Starter Code
You 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 to
display 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 your
program 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 7/30
Input Commands
Input 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 number
of 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 process
each command as you read it.
Stage One
Stage One implements basic drawing functions, giving your program the ability to draw lines and squares.
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 8/30
Line Drawing
In 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 length
1 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 (until
you'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 "start
row").
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 be
equivalent 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 will
need to use more colors.
Hints
If 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 360
which is the same as 0.
Until you're told otherwise, you should use the colour '0' to colour your lines.
Line Drawing: Summary
Command "Draw Line"
Instruction 1
Inputs start_row start_col length direction
Examples
Command Meaning
1 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 9/30
Handling Invalid Input
If 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 Draw
Line command and do nothing.
You can assume you will never receive a negative direction (a degree less than 0).
Examples
Show Test-Case: Horizontal Line
Show Test-Case: Vertical Line
Show Test-Case: Empty Line
Show Test-Case: Box
Show Test-Case: Invalid Lines
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 10/30
Square Drawing
For the second part of Stage 1, you will be implementing the Fill Square function, to draw squares. The Fill Square 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 square's diagonal. A line of length 0 means no square will be
produced. 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 of
5 pixels in a down-and-right direction (135 degrees).
Square Drawing: Summary
Command "Fill Square"
Instruction 2
Inputs start_row start_col length direction
Examples
Command Meaning
2 0 0 10 4
5
FILL SQUARE STARTING AT (row 0, col 0) WHICH IS 10 PIXELS DIAGONALLY, AT 45
DEGREES.
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 22
5
FILL SQUARE STARTING AT (row 6, col 6) WHICH IS 2 PIXELS DIAGONALLY, AT 225
DEGREES.
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 11/30
When given the Fill Square command, your program should build a square. It does this by first finding a diagonal line using a starting
pixel, 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 of
that square. You can assume that the edges of the square are either vertical or horizontal, there are no rotated squares.
Hints
If length == 0, your program should draw nothing.
Invalid Input
If 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.
Examples
Stage Two
In 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 working
without Stage 1.
Note that completing Stage 2 is not necessary to gain a passing mark in this assignment.
Show Test-Case: Small Square
Show Test-Case: Big Square
Show Test-Case: Little Pixel Boxes
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 12/30
Diagonals
For 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 Square
Drawing section).
Examples
Line Drawing: Diagonals: Summary
Command "Draw Line"
Instruction 1
Inputs start_row start_col length direction
Examples
Command Meaning
1 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: Negatives
Show Test-Case: Multiple Diagonal Lines
Show Test-Case: Other Angled Lines
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 13/30
Negative Distances
Your program should now also handle negative lengths, in both the Draw Line and Fill Square. A negative length is the same as
going 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.
Examples
Show Test-Case: Negative Lines
Show Test-Case: Negative Squares
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 14/30
Shade
For the second part of Stage 2, you will be implementing the Change Shade command, which gives you access to both an eraser and
different 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 a
number 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. For
instance, to change from WHITE to BLACK you should enter -4
By default, your program should start with the shade BLACK.
Hints
Painting 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 Input
If the given shade difference is invalid (if it would cause the shade to be negative, or to be greater than 4), ignore that Change
Shade command and do nothing.
Examples
Stage Three
In 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: Summary
Command "Change Shade"
Instruction 3
Inputs new_shade
Examples
Command Meaning
3 2 CHANGE COLOUR, ADDING 2 TO THE CURRENT COLOUR.
3 1 CHANGE COLOUR, ADDING 1 TO THE CURRENT COLOUR.
Show Test-Case: Coloured Lines
Show Test-Case: Coloured Boxes
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 15/30
Copy and Paste
For Stage 3, you will be implementing the Copy Paste command, which allows you to copy a certain section of the canvas, and paste it
elsewhere 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 two
values define a target pixel, which is the corner of another square (defined by the target pixel, and the previous integers describing
length and direction).
In other words, you are given six integers:
start_row: The starting row of the square being copied from
start_col: The starting column of the square being copied from
length: 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 to
target_col: The starting column of the square being copied to
This command should copy every pixel in the square starting at (start_row, start_col), with length * length pixels at
direction degrees. It should copy those pixels to a square starting at (target_row, target_col), with the same area, also going
at direction degrees.
The diagram below describes what these points are:
Copy and Paste: Summary
Command "Copy Paste"
Instruction 4
Inputs start_row start_col length direction target_row target_col
Examples
Command Meaning
4 0 0 3 1
35 0 10
COPY SQUARE STARTING AT (row 0, col 0) WHICH IS 3 PIXELS ACROSS, AT 135 DEGREES
PASTE STARTING AT (row 0, col 10).
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 16/30
After calling the Copy Paste command, every pixel in the rectangle bounded by start and end should be copied to a rectangle of the
same size that has target as its top left pixel.
Hints
The pixels should be copied exactly, the current shade setting has no effect on the pixels being copied.
Invalid Input
If any of the given pixels would cause any part of the copying or pasting to go outside of the canvas, your program should ignore
that Copy Paste command and do nothing.
For this stage, you may ignore the possibility that two regions will overlap.
Examples
Show Test-Case: Copy Paste Line Colours
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 17/30
Ellipse Drawing
In 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 an
additional 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 twice
the 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:
Hints
Ellipse Drawing: Summary
Command "Draw Ellipse"
Instruction 0
Inputs focus_1_row focus_1_col focus_2_row focus_2_col length fill
Examples
Command Meaning
0 0 0 3 3 5.5
1
; WITH FOCAL POINTS (row 0, col 0) AND (row 3, col 3) WITH RADIUS 2 * 5.5, FILLED
IN..
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 18/30
You may notice that there's a function in the provided code called double distance(int row1, int col1, int row2, int
col2)
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 function
but you will need to call this function to be able to draw an ellipse.
Invalid Input
Unlike previous commands, if part of the ellipse would be off the canvas your program should not ignore the command, and
should instead fill in all of the relevant pixels that are on the canvas.
Examples
Stage Four
In 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 Ellipse
Show Test-Case: Ellipse
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 19/30
Overlapping Copy Paste
For Stage 4, you should ensure your program can deal with overlapping copies and pastes, that is, you can no longer assume that
where you are copying from will not be pasted within.
The behaviour of the Copy Paste command should otherwise remain the same as described.
Examples
Show Test-Case: Overlapping Copy Paste
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 20/30
Hollow Ellipse Drawing
For 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' ellipse is the same definition as a normal ellipse, but it excludes all pixels that are not directly above, below
or 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.
Examples
Hall of Fame Challenges
If you have completed the assignment and are looking for further challenges, we have compiled a list of interesting ideas that could
extend CS Paint. We call these "Hall of Fame" challenges and for anyone who completes them, we will publicise your work on the
course website! You can feel free to invent your own challenges as well (and if they are at least as interesting as the ones below, we
will 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 of
Fame, 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 the
assignment. They are, however, not worth any marks.
To submit a Hall of Fame attempt for testing, you should send it to cs1511.challenge@cse.unsw.edu.au with the subject line "Hall of
Fame Submission z5555555". Your email body should include a description of the challenge exercise, and a guide to how to run and
test 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 that
pixel (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: Summary
Command "Draw Ellipse"
Instruction 0
Inputs focus_1_row focus_1_col focus_2_row focus_2_col length fill
Examples
Command Meaning
0 0 0 3 3 5.5
0
; WITH FOCAL POINTS (row 0, col 0) AND (row 3, col 3) WITH RADIUS 2 * 5.5, NOT
FILLED..
Show Test-Case: (Hollow) Circles are (Hollow) Ellipses
Show Test-Case: Hollow Ellipse
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 21/30
It 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 with
less 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 greyscale
version 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 should
not 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 instructions
that 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 IOCCC
These challenges are open to interpretation. If you have a question about how to complete it, ask on the course forum, or ask
yourself "What would be cooler". Submitting an entry isn't a guarantee that you will make the hall of fame (but we will let you
know if it does not make it, and why we have rejected it).
Testing
It 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 possible
situations 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 22/30
Testing your code
If you are testing with your own commands or commands written in a file, you can either use numerical output or our canvas
output.
Getting raw numeric output
If you are debugging, or want to see the raw numbers as output, you can compile and run your program as follows:
$ ls

paint.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.
$ ls
paint.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 canvas
You can run the command 1511 canvas on CSE computers (including via VLAB) along with the name of your C file, and we will
compile it and show you the stylized output similar to in our examples in the Stages above.
$ 1511 canvas paint.c
You have run canvas without specifying any tests.
You may quit this program with Control + C
You can type lines below, and then press Control + D to see what outpu
t those
lines 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.
$ ls
paint.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 Paint
https://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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 24/30
Automated Testing
On 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.c
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 25/30
Reference Implementation
If 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):
$ ls

test_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]


Assessment
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 26/30
Attribution of Work
This 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 code (not specific to the assignment) obtained from site such as
Stack 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 lecturers
or tutors.
Do not provide or show your assignment work to any other person (including by posting it on the forum) apart from the teaching
staff of COMP1511.
The work you submit must otherwise be entirely your own work. Submission of work partially or completely derived from any
other person or jointly written with any other person is not permitted. The penalties for such an offence may include negative
marks, automatic failure of the course and possibly other academic discipline. Assignment submissions will be examined both
automatically and manually for such submissions.
Relevant scholarship authorities will be informed if students holding scholarships are involved in an incident of plagiarism or other
misconduct. If you knowingly provide or show your assignment work to another person for any reason, and work derived from it
is submitted you may be penalized, even if the work was submitted without your knowledge or consent. This may apply even if
your 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 27/30
Submission of Work
You 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 it
using 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/master
This will allow you to retrieve earlier versions of your code if needed.
You submit your work like this:
$ give cs1511 ass1_cs_paint paint.c
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 28/30
Assessment
This 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.c
20% of the marks for this assignment will come from hand marking of the readability of the C you have written. These marks will
be awarded on the basis of clarity, commenting, elegance and style. In other words, your tutor will assess how easy it is for a
human 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-grade
Distinctions.
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 for
COMP1511
Paying 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 to
the description above.
2019/10/9 Assignment 1 - CS Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 29/30
Due Date
This assignment is due Sunday 27 October 18:00
If your assignment is submitted after this date, each hour it is late reduces the maximum mark it can achieve by 2%. For
example if an assignment worth 74% was submitted 10 hours late, the late submission would have no effect. If the same
assignment 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 Paint
https://cgi.cse.unsw.edu.au/~cs1511/19T3/assignments/ass1/index.html 30/30
COMP1511 19T3: Programming Fundamentals is brought to you by
the School of Computer Science and Engineering
at the University of New South Wales, Sydney.
For all enquiries, please email the class account at cs1511@cse.unsw.edu.au
CRICOS Provider 00098G
Change Log
Version 0.9
(2019-10-07 01:00)
Pre-release draft.
Version 1.0
(2019-10-07 02:00)
Make assignment public
Version 1.1
(2019-10-09 14:00)
Clarify you're supposed to set the lines to 0 in stage 1.  

51作业君 51作业君

扫码添加客服微信

添加客服微信: IT_51zuoyejun