联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2019-10-02 10:04

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

COURSE TITLE: Introduction to Computer Science 1

TERM: Fall 2019

1

Assignment 1

DUE DATE OCTOBER 4 2019 AT 11:59PM

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.

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

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

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

2

Q1: An Animal

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 some sort of animal in the canvas. It can be anything

you like: a tiger, a dog, a mouse, any animal. Be creative. The rules are:

• It must contain from 6 to 16 shapes (lines, ellipses, rectangles, or other

shapes). The sample mouse shown here uses 11 shapes (2 rectangles, 5

ellipses, and 4 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.

• It can be a very abstract animal, like the one shown. You don’t have to be a great artist.

• Don’t make it too complex. Stick to the limit of 16 shapes. That will make the

remaining questions easier.

• You must use a 500 x 500 canvas for this question.

• The animal must fill the canvas, either horizontally (as the mouse does), or vertically.

• It should be roughly centred in the window.

In Questions 2 and 3, your animal will grow, shrink, and move. As soon as any program is

“finished”, you usually have to start making changes to it, and that will happen with this

program, too. To make that easier to do, you must do the following things:

• All X coordinates, Y coordinates, heights, widths, and colours, must be defined by

constants. You will probably need at least 10, and perhaps as many as 30 if you choose to

do a very complex animal. There is no limit on the number of constants you use.

• The X and Y coordinates should be specified relative to the centre of the window. This

will make the following questions much easier. Heights and widths will be in pixels. For

example, this constant is used to define part of the example mouse.

final int BODY_WIDTH=width/2; //total width of body section

• All of your drawing commands should use your constants, the built-in height and

width variables, and perhaps simple numbers like 1 or 2. No other numbers. For

example, the ellipse that forms the main body of the mouse was drawn with the statement

below.

ellipse(width/2, height/2, width/2 , height/2 - bodyWidth);

• If some calculation is needed many times in many statements, do it only once and store

the result in a variable. Then use that variable many times. For example, a better version

of the above statement would be the one below, where MOUSE_BODY_WIDTH and

MOUSE_BODY_X were pre-calculated, since those values were needed many times to draw

the entire animal. (Hint: It would be a really good idea to pre-calculate the coordinates of

the centre of the canvas.)

ellipse(MOUSE_BODY_X, MOUSE_BODY_Y, MOUSE_BODY_WIDTH, MOUSE_BODY_HEIGHT);

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

3

Q2: A Moving Animal

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 the

animal. Make the following changes and additions to your

Question 1 program.

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

2. Add five variables to your program, which control the

animal’s size and position. There should be an X

coordinate, a Y coordinate, size, and a MIN_SIZE and MAX_SIZE value. The X and Y

coordinates should specify the position of the approximate centre of the animal (the same

spot that used to be at the centre of the canvas, but could now be anywhere). The size

variables should give the minimum size the animal should reach when near the top of the

canvas and the maximum size the animal should reach when nearing the bottom.

3. Create the usual setup()and draw() functions. Create a drawAnimal() function (or

call it drawCat () or drawMouse(), or whatever name is appropriate for you). Create

a moveAnimal() function (or use a similar name).

4. Move all your existing code from Q1 into the appropriate place in these new functions.

All of the code that draws your animal should go into the drawAnimal() function, not

into the draw() function directly. The functions should call each other as needed.

5. The moveAnimal() function should use the mouse position to set the X, and Y, and size

values for your animal (the ones described in point 2). The X and Y values should exactly

match the mouse position. The size variable can be calculated by using the MIN_SIZE,

MAX_SIZE and mouseY such that, when the mouse is at the top of the screen, the animal

is at it’s MIN_SIZE, and when it’s at the bottom, it will be at it’s MAX_SIZE. This will

be a very short function.

6. Now you need to change all of the commands that draw your animal, so that they take

into account its position and size. If you took the hint in Question 1, controlling the

position should be very easy. To control the size, you will have to “scale” almost all of

the constants from Question 1, using the animal’s current size, and its original size (500).

For example, BODY_HEIGHT used to control the height of the example animal’s body.

Now it must be BODY_HEIGHT*animalSize/ORIGINAL_SIZE.

7. When using int values, be careful. BODY_HEIGHT*animalSize/ORIGINAL_SIZE

works but animalSize/ORIGINAL_SIZE*BODY_HEIGHT will usually just give you 0.

Always do the multiplication first. And don’t try to store

animalSize/ORIGINAL_SIZE in an int variable, as nice as that would be. You’ll just

get 0.

8. Now change the size of the canvas to 1000 by 1000 pixels, or to any other size. If you’ve

written your program well, everything should still work, with no modification. Did it?

9. Optional: If you want to use float, from Week 4 material, go ahead. It would make

things somewhat simpler. But it’s not required.

ASSIGNMENT 1

DEPARTMENT AND COURSE NUMBER: COMP 1010

4

Q3: A Self-propelled Animal

Convert your program from Question 2 so that your animal will move across the canvas, and

change size, all by itself. Here’s how it should work: When you click the mouse in the canvas,

your animal should slowly and smoothly move to that position (or close to it).

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

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

2. Add a mouseClicked() function (void mouseClicked()). This is a special

function, like setup() and draw(), which is automatically called every time there is a

mouse click in the canvas. The mouseX and mouseY variables give the location of the

click. The location of the last mouse click should be stored in appropriately-named state

variables.

3. Change your moveAnimal() function (or whatever you have chosen to name it) so that

your animal will now move slowly and steadily toward the location of the most recent

mouse click. Use a constant to control your animal’s speed. In each frame, it should move

1/Nth of the way from its current position to the location of the mouse click. (But don’t

call the constant N – use a better name.) Note: When the animal gets close to the desired

location, it will reach a point where its position will change by less than 1 pixel per

frame. Since you are using int variables, you will get a change of 0 pixels per frame,

and your animal will stop a bit too soon. This is OK. (If you wish to use float variables

to solve this problem, go ahead.)

4. The size of your animal should depend on the Y coordinate of its current location in the

canvas, not on the location of the last mouse click, or on the current position of the

mouse. Its size should change slowly and smoothly, just as its position does.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp