Assignment 3 Solution

$30.00 $24.00

Notes: Name your sketches using your name, and the question number and assignment number, exactly as in this example: LastnameFirstnameA3Q1. Your programs must run upon download to receive any marks. Submit two pde files only. Do not submit any other types of files. Assignments must follow the programming standards document published on the course website…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Notes:

  • Name your sketches using your name, and the question number and assignment number, exactly as in this example: LastnameFirstnameA3Q1.

  • Your programs must run upon download to receive any marks.

  • Submit two pde files only. Do not submit any other types of files.

  • Assignments must follow the programming standards document published on the course website on UMLearn.

  • After the due date and time assignments may be submitted but will lose 2% of marks per hour late or portion thereof. The date and time of the last file submitted controls the mark for the entire assignment.

  • You may submit your program multiple times, but only the most recent version will be marked.

  • These assignments are your chance to learn the material for the exams. Code your assignments independently. We use software to compare all submitted assignments to each other, and pursue academic dishonestly vigorously.

Q1: Swarm of Invaders

Write a program that will cause a swarm of “invaders” to move back and forth across the canvas, descend toward the bottom, and grow in size, as shown on the right. (This is roughly similar to the classic Space Invaders game.) You can download and run SampleA3Q1.zip to see how it should look. (This is a Windows 64 application which will work in all the U of M computer labs.)

Here are the specifications which you must follow:

  • There should be NUM_ROWS rows of invaders. (In the example, there are 3 rows.)

  • There should be ROW_SIZE invaders in each row. (In the example, there are 5 invaders per row.)

  • The invaders should be fixed distances apart in the x and y directions, controlled by X_SPACING and

Y_SPACING.

  • At the start of the program, the top left invader should be in the top left corner of the canvas. Use the centre of an invader to control its position. (An invader could go halfway off the canvas. That’s OK.)

  • They should move from left to right until the invaders on the right reach the right edge of the canvas. Then they should all suddenly jump down one row (Y_SPACING), and start moving right to left. When the

invaders on the left reach the left edge of the canvas, they should again jump down one row and move left to right again. This process should repeat.

  • Each invader should be drawn as a set of concentric circles, so that the outer edge is a different colour than the middle, as shown in the images. You can choose your own

1

ASSIGNMENT 2

DEPARTMENT AND COURSE NUMBER: COMP 1010

colours. The colours of the circles should change gradually from the outside to the inside. Use the command noStroke(); so that the circles will not have any outlines drawn around them, which would spoil the effect.

  • When the invaders are at the top, they should be very small, using only a few concentric circles. Each time they jump down a row, another circle should be added, so that they grow larger, until they reach some maximum number of circles. The difference in diameter from one circle to the next should be some constant value.

  • When the maximum number of circles is exceeded, the invaders should go back up to the top left corner, and start again as small ones.

  • Provide constants to control the speed of motion of the invaders, the minimum and maximum number of circles used to draw them, and the amount that they grow each time.

  • Adjust your constants so that there is always at least one row of invaders visible in the canvas. (Some of the rows can disappear off the bottom of the canvas.)

  • Write a function drawAllInvaders() which will draw all of the rows of invaders. It should call a function drawRowOfInvaders() which will draw one row of invaders. That function should call drawOneInvader() which will just draw one invader.

  • Use appropriate state variables and split up your program into other small functions with well-defined jobs, as described in their comments.

  • You do not have to adapt to changing canvas sizes. You can assume that the canvas will always be one fixed size, and use simple numbers for your constants.

Q2: Label Maker

Write a program which will allow you to type a message at the bottom of the canvas, in a very awkward way. There will be a ring of characters (letters, blanks, punctuation marks, etc.) that rotates continuously. The top of the ring should be marked somehow (in the example, there is a small vertical line). Whenever the user clicks the mouse in the canvas (anywhere), whichever character is closest to the top of the ring should be added to the message at the bottom of the canvas (in the example, it would be ‘F’).

You can download and run SampleA3Q2.zip to see how it should look. (This is a Windows 64 application which will work in all the U of M computer labs.)

Here are the specifications which you must follow:

  • Use a String constant (right at the top of your program) to control the characters which will appear around the ring. You (or the marker) should be able to change this String, and it should still work. Include letters, a blank, and some punctuation marks. You could add digits, if you like.

  • There should be a rectangle of a contrasting colour at the bottom of the canvas, in which the message will appear, as shown. The ring of characters should be centred in the upper part of the canvas.

  • The characters should be drawn, one at a time, in a ring, as shown. The ring should rotate at a constant speed. It could rotate in either direction, but clockwise is probably easier to program.

2

ASSIGNMENT 2

DEPARTMENT AND COURSE NUMBER: COMP 1010

  • Draw some sort of mark to indicate the top of the ring. It could be a simple line, or a hollow box, or a V shape, or whatever you like.

  • Write a mouseClicked() function. This is a special function that will automatically be called by Processing whenever the user clicks the mouse in the canvas. Another character (whichever one is closest to the top) should be added to the message at the bottom of the canvas whenever this happens. The message should be empty when the program starts.

  • Use appropriate constants, state variables, and functions to write your code.

Hand In:

Hand in two pde files only. Each file must run without errors, or you will lose all of the marks for that question.

Make sure your files are named exactly as specified in the instructions at the beginning of the assignment.

The marker will run your programs, and may change the canvas size and the constants specified in the assignment. It should still work if any constants are changed in a reasonable way.

3

Assignment 3 Solution
$30.00 $24.00