Draw images to terminal using a series of commands

Assignment Help C/C++ Programming
Reference no: EM132335255

Assignment - CS Paint

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 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.

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.

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.

Stage One

Stage One implements basic drawing functions, giving your program the ability to draw lines and rectangles.
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 two pixels: the start and end pixels of the line.

Each pixel consists of two numbers: the index of the row, and the index of the column.

For example, the command 1 10 3 10 10 tells your program to draw a line (1), starting at the pixel at row 10 and column 3, and ending at the pixel at row 10 and column 10.

When given the Draw Line command, your program should set the colour of the relevant elements 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).

Stage Two
In Stage 2, you will be extending the functionality of your Draw Line and Fill Rectangle 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.

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.

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 new shade that you will draw in all future commands, until the shade is changed again.

By default, your program should start with the shade BLACK.

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.

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 describe three pixels: start, end, and target.

The first two pixels, start and end describe the corners of a rectangle. This is the region that will be copied.

The third pixel, target describes the top-left pixel of the position on the canvas where that rectangle will be pasted.

Stage Four
In Stage 4, you will again be implementing more advanced commands.

Again, we strongly recommend that you finish Stage 1 and Stage 2 before attempting Stage 4.

Note that completing Stage 4 is not necessary to gain a passing mark in this assignment.

The Additive Brush command gives CS Paint access to a special brush for the Draw Line command.

In addition to the existing one-pixel brush, you now have access to a nine pixel brush. This brush will affect a 9 pixel square for every pixel that the original brush would have drawn.

The Additive Brush command takes nine arguments, which represent the additions that should be made to each of the 9 pixels under the brush:

The first argument describes the shade to be added to the pixel located diagonally above and to the left of the pixel currently being drawn on.

The second argument describes the shade to be added to the pixel directly above the pixel currently being drawn on.

The third argument describes the shade to be added to the pixel located diagonally above and to the right of the pixel currently being drawn on.

The third through fifth arguments describe the row below the first three including the pixel currently being drawn on, and the sixth through eighth describe the row below that.

This brush is additive, which means that instead of overwriting the shades on the canvas, it adds to (or removes) them. For every pixel that the brush touches, those pixels' values should change by the corresponding amount.

If this would cause any pixel to be outside of the valid range of shades, it should instead be changed to the closest valid shade (i.e. if a shade would cause a pixel to have value -2, that pixel should instead be given the value 0).

This correction should happen once for every pixel the brush touches (i.e. as the brush moves, you should ensure the canvas is never in an invalid space.)

This brush should be used until either the Change Shade command is used (to return to a one-pixel brush of a given shade), or the Additive Brush command is called again to specify a new nine-pixel brush. This means that if you are given, for example the Draw Line command, you should use the Additive Brush to draw that line, rather than the 1 pixel brush.

Attachment:- Assignment - CS Paint.rar

Reference no: EM132335255

Questions Cloud

Implement for mentoring new employees : What procedures or techniques will you develop and implement for mentoring new employees who are under performing?
Boundary issues and dual relationships : CNL-505-How would you determine if boundary-crossing or dual relationship is ethical and appropriate? What criteria would you consider when making your decision
Staying motivated in the doctorial program : Develop a plan for achieving my goals and staying motivated in the doctorial program
What did you think about the findings : Discuss your opinion of this article. What did you think about the findings? What were potential limitations? Integrate concepts within Chapter 4 of the.
Draw images to terminal using a series of commands : COMP1511 - Programming Fundamentals - University of New South Wales - write code so that it can read commands and make the correct changes in the canvas
Complaints handling process and apply : Explain each step of the 7-step customer complaints handling process and apply an example from your own workplace or personal experience
Workplace or personal experiences : Apply an example from your own workplace or personal experiences about how customer service can be improved, using each step of the Plan-Do-Check-Act process.
How does blumer view social interaction and society : What are the key ideas that Blumer (1969) draws from George Herbert Mead? How does Blumer view social interaction and society?
Demonstrate the decision-making process : As a counselor, you will be making decisions on how to select evidence-based treatments. In your essay, demonstrate the decision-making process that you will.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd