Assignment-1 Solution

$30.00 $24.00

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

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Notes:

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

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

  • Submit one pde file for each question. 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 a question 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: Simple Spaceship

You should be able to do this question after Week 2 in the course.

Write a non-active Processing program (containing no setup() or draw() functions) which will draw a simple spaceship of your own design in the canvas. Keep it simple and abstract. Do not copy the sample image on the right. Make up a design of your own. Be creative. The rules are:

  • It must contain from 6 to 12 shapes (lines, ellipses, rectangles, or other shapes). The sample shown here uses 6 shapes: 1 rectangle, 3 ellipses, and 2 lines.

  • It must contain at least one line, at least one ellipse or circle, and at least one square, rectangle, triangle, or quadrilateral (quad).

  • It should contain several different colours or shades of grey. Use any background colour you like (but of course space is usually black).

  • It should use strokeWeight to adjust the thickness of the line(s).

  • Don’t make it too complex. Stick to the limit of 12 shapes. That will make the remaining questions easier.

You must follow the rules below in your program

  • At the top of your program, define three constants SIZE, X_CENTRE, and Y_CENTRE which will control the size of the spaceship, and its position in the canvas.

o The SIZE can be its length, width, or any other suitable dimension that you like. o The coordinates X_CENTRE and Y_CENTRE should control the position of the

spaceship in the canvas, by defining some central point like the middle of the main shape. It doesn’t have to be the exact centre.

1

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

  • Define suitable constants for all other dimensions and coordinates needed to draw the spaceship, such as heights, widths, diameters, stroke weights, and the coordinates of corners or the endpoints of lines. All of these constants must be calculated from some combination of SIZE, X_CENTRE, and Y_CENTRE ! They cannot be simple numbers! For example:

final int DOME_HEIGHT = SIZE/10;

final int LEFT_EDGE = X_CENTRE-DOME_HEIGHT/2;

  • You do not need to use constants to define colours.

  • Use the constants you have defined to draw the spaceship. You should be able to change the size of the canvas, or SIZE, X_CENTRE, or Y_CENTRE, and the spaceship should still be drawn correctly at any size and in any location.

  • You can use some arithmetic and small constants like 1 or 2 in your drawing commands. For example, a formula like X_CENTRE+BODY_DIAM/2 could be used for an X coordinate. This will reduce the number of constants needed.

Q2: Active Spaceship

This question requires material from Week 3.

Convert your program from Question 1 into an Active Processing program, with the mouse controlling both the size and position of your spaceship.

  • Save a copy of your original Question 1 program. You must hand in the original static version, as well as this modified active version.

Rename this one so that it ends with “A1Q2”.

  • All of the constants defined in Question 1 must now be changed into variables since they will now be changed by the mouse. [The Find… command in the Edit menu contains a Replace All button which will be very useful to change the names.]

  • Create the usual setup()and draw() functions.

  • Write a setSizeXandY() function which will use the mouse position to set the three variables that control the size and position of your spaceship. The centre of your spaceship should always be at the mouse position. The size of your spaceship should be controlled by mouseY. The spaceship should have a size of MIN_SIZE when the mouse is at the top of the canvas, and MAX_SIZE when the mouse is at the bottom of the canvas, and it should change size smoothly in between. Define these two new constants at the top of your program.

  • Write a calcDimensions() function which will calculate all of the variables that control the drawing of your spaceship (the ones that used to be constants but are now variables). The code should be almost the same as the constant declarations you used in Question 1 (except for the names of the variables).

  • Write a drawSpaceship() function which will draw your spaceship. All of the drawing code should be moved into this function. You shouldn’t have to change any of this code

(except for the names of the variables).

  • Call these functions appropriately from setup() and draw().

  • Your spaceship should follow the mouse around the canvas, and grow or shrink. It should work for any size canvas, and any reasonable values of MIN_SIZE and MAX_SIZE.

2

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

Q3: Flying Spaceship

Convert your program from Question 2 so that your spaceship flies across the canvas all by itself, without being controlled by the mouse.

Make the following changes and additions to your Question 2 program.

  • Save a copy of your original Question 2 program. You must hand in that version, as well as this new version. Rename this one so that it ends with “A1Q3”.

  • Delete the MIN_SIZE and MAX_SIZE constants, which will no longer be used.

  • Define the following 7 constants which will control the actions of your spaceship (now you’re the movie director):

    1. The spaceship should move along a line from the point (X_START, Y_START) to the point (X_END, Y_END). Define these 4 constants so that it moves along a diagonal line. The starting and ending points can even be off the canvas, which is a good effect, allowing the spaceship to appear from one side and disappear off another side.

    1. The spaceship’s size should start at SIZE_START and end at SIZE_END. Define two different values so that the ship appears to fly away from the viewer, getting smaller, or toward the viewer, getting larger.

    1. Define a constant SPEED_FACTOR which will control the speed of the spaceship along the line. All three values (x, y, and size) should move 1/SPEED_FACTOR of the way from their current values to the ending values in every frame. For example, if the spaceship is currently at x=400, and X_END is 100, a difference of 300, then if SPEED_FACTOR is 30 the spaceship should move 1/30 of the difference (10 pixels) in the x direction. [If int variables and constants are used, this may result in some uneven motion near the end. If you use float variables and constants instead it will work more smoothly. That’s OK.]

  • Define the special void mouseClicked() function, which Processing will run automatically every time the mouse is clicked anywhere in the canvas. Do not call this function yourself! Whenever the mouse is clicked, the spaceship should reset to the starting position and size, and then, in the frames that follow, it should fly across the canvas.

  • Modify the setSizeXandY() function so that the spaceship moves and changes size as defined above.

  • You should not have to make any changes at all to the other functions (setup, draw, calcDimensions, or drawSpaceship).

Q3 addition: Special FX

Add some sort of repeating animation to your spaceship. Some part of your spaceship could move, grow, shrink, change colour, etc.

  • Write a doAnimation() function which will change one or more of your variables to cause a repeating animation or effect of some kind. Define any additional variables or constants that are needed to control the animation. Use the % operation to cause the repetition.

  • Small changes may need to be made to drawSpaceship() to implement the animation. It’s OK to add a few additional shapes, as well.

3

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

Hand In:

Hand in three pde files, one each for Questions 1, 2, and 3. Your Question 3 program may be animated, or not. (It will be worth a few more marks if it’s animated.)

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.

4

Assignment-1 Solution
$30.00 $24.00