联系方式

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

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

日期:2019-03-09 10:51

ASSIGNMENT 3: Loops and String and char

DEPARTMENT AND COURSE NUMBER: COMP 1010

COURSE TITLE: Introduction to Computer Science 1

TERM: Winter 2019

Assignment 3

DUE DATE: Friday March 8th, 2019 at 4:30 pm.

This assignment covers the topics chars and Strings and loops.

Notes

Name your sketch using your name, the assignment number, and the question number, exactly as in this

example: LastnameFirstnameA3Q1.

Your program must run upon download to receive any marks.

Submit one PDE file for each question, or each part, as specified. Do not submit any other types of files.

Assignments must follow the programming standards document published on the course website on UM Learn.

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

Question 1: Printing in a Circle

Write an Active Processing program that prints a quotation

in a circle; see the example on the right.

Choose a very short quote — a long quote does not

fit easily in a circle in a 600 × 600 canvas. Here are some

examples — you can choose from them or find your own:

Hope is a waking dream. — Aristotle

I can, therefore I am. — Simone Weil

Everything you can imagine is real. — Pablo Picasso

Short cuts make long delays. — J.R.R. Tolkien

The art is long, life is short. — Hippocrates

Anger is a short madness. — Horace

Whatever you are, be a good one. — Abraham

Lincoln

1

The quote is stored as a String. In each frame, the quote is printed in a circle around a center point. In each

frame, the entire quote is printed one letter at a time at gradually increasing angles around a center point so that

the quote is printed in a circle. The starting angle (of the first letter) and the center point of the circle are different

for each frame, but each frame shows the entire quote.

Here is what should happen in each frame:

1. Start with a fresh canvas.

2. Choose a random radius for the circle. It can’t be too small or the letters will be packed too tightly together

to read the quote. The radius also can’t be too big or the letters will not all fit on the screen.

3. Choose a random center point for the circle, such that all the letters in the quote will be visible in the canvas

using the radius you just generated in the previous step.

4. Choose a random angle for the starting angle at which the first character of the quote will be printed.

5. Then write a loop to print the characters of the quote one-by-one, at equally-spaced increasing angles around

the center point, starting with the first character of the quote at the starting angle. Use a for-loop, and make

it count through the positions of the characters in the quote. Inside the loop, after each character is printed,

increase the angle so that the next character is printed a bit further around the circle. Use the charAt()

function to pick out one character of the String to print.

Use a canvas size of 600 × 600. Use 30 pixels as the size of the letters. Make sure the background and letter colours

contrast sufficiently that the quote is easy to read. Compute an angle speed so that the characters in the String

are equally-spaced around the circle by dividing TWO PI by the length of the String. Slow the frame rate down to

something like 0.5 — using command frameRate(0.5); so that the marker has time to read the quote during a

frame before it is redrawn in the next frame.

Question 2: Printing in a Spiral

This question changes your program so that instead

of printing a quote in a circle, it is printed in a spiral; see

the example on the right.

Choose a longer quote than you used in Question 1 so

that you get at least a couple of rotations to the spiral.

The example uses the first line from “Pride and Prejudice”

by Jane Austen. You can use that quote or choose

another of a similar length.

Notice that the first character of the quote is on the

outside of the spiral and the last character of the quote

is on the inside of the spiral.

The quote must be printed from the inside of the spiral

to the outside. So the last character of the quote must

be the first letter you print in a frame, and the first character

of the quote must be the last letter printed in the

frame. So the String is printed in backwards order, one

character at a time.

Save a copy of your original Question 1 program. You

must hand in the original circle version, as well as this

modified spiral version. Rename this copy so that it ends

with A3Q2.

Here is what should happen in each frame:

1. Start with a fresh canvas.

2. In this question, always use the center of the canvas

as the center of the spiral (not a random center).

2

3. Choose a random radius for the beginning of the spiral in the interior of the spiral. This starting radius can’t

be too small or the letters will be packed too tightly together to read in the interior of the spiral. The radius

also can’t be too big or the entire quote will not fit on the screen.

4. Choose a random angle to be angle at which the interior of the spiral begins.

5. Now you must write a for-loop that will print the entire quote in this frame:

Print the characters of the quote one-by-one in the loop — do this by making the for-loop count through

the positions of the characters in the quote.

The loop must print the last character in the quote (the rightmost character) FIRST.

The loop must print the first character of the quote (the leftmost character) LAST.

That is, your loop must work backwards through the string (from right to left) — it is counting DOWN,

not up.

The last character of the quote is printed at the starting point in the interior of the spiral.

Each subsequent character printed is printed at a slightly larger angle and a slightly larger radius than

the previously-printed character.

In other words, inside the loop, after you print each character, you must increase the angle slightly and

also increase the radius slightly.

Choose the angle speed and the radius speed so that the characters in the quote are readable (not printed on

top of each other).

Remember that, in each frame, the entire quote is printed.

Use a canvas size of 600 × 600. Use 30 pixels as the size of the letters. Make sure the background and letter

colours contrast sufficiently that the quote is easy to read. Experiment with different radius and angle speeds until

you find values so that make the characters in the String easily readable. Slow the frame rate down to something

like 0.1 — using command frameRate(0.1); so that the marker has time to read this longer quote during a frame

before it is redrawn in the next frame.

What information needs to be remembered from frame to frame in this question — that is, what global / state

variables do you need? Hint: few, if any!

Question 3: Letters coming out a Spiral

In this question, you will rewrite your program so that the long quote comes out in the spiral gradually, over many

frames. For example, the pictures below show some snapshots of the execution of the sample solution; the left picture

below shows the second frame drawn by the program, the middle picture shows the seventh frame, and the right

picture shows the 13th frame.

3

When the program begins, you should choose a random angle and a random radius for the start of the spiral in

its interior.

In the first frame, only one character of the quote (the very first character) is printed, at the starting point of

the spiral in its interior.

In the second frame, two characters of the quote (the first and second characters) are printed, with the second

one at the starting point in the spiral’s interior and the first on a bit further out along the spiral. (This is what

the left picture shows in the above example.)

In the third frame, three characters of the quote (the first, second, and third) are printed, with the third one

at the starting point in the interior and the second and first successively further out along the spiral.

And so on, until the entire quotation is printed many frames later, with the last character at the starting point

in the interior and the first character at the farthest point out along the spiral.

When the entire quote has been printed, start the whole process over again with a new random angle and new

random radius for the interior starting point, printing just one character of the quote at the new starting point in

the next frame.

So, in each frame, you are printing a part of the quote in a spiral — and printing that part backwards (last

character first), just as you did in Question 2. The part of the quote to be printed increases by one character from

frame to frame.

In this question, you need some global / state variables to remember the radius and angle of the starting point

from frame to frame, and also to remember how many characters were printed in the previous frame, so that you

can print one more character in the next frame.

You need to alter the loop that prints in a spiral so that it prints the correct number of characters in each frame,

not the whole quote in every frame.

When you increase the number of characters to be printed in the next frame, you should check to see if that

number has become larger than the number of characters in the quote. If it has, then you should reset it to 1, and

generate a new random start angle and a new random start radius.

Use a canvas size of 600 × 600. Use 30 pixels as the size of the letters. Make sure the background and letter

colours contrast sufficiently that the quote is easy to read. Experiment with different radius and angle speeds until

you find values so that make the characters in the String easily readable. Slow the frame rate down to something

like 1 — using command frameRate(1); —, so that the text is coming out of the starting point slowly enough to

be read.


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

python代写
微信客服:codinghelp