Homework 1

Homework 1 gathers homeworks from code-1-introduction.html

count 7 : code-1-ex1 code-1-ex2 code-1-ex3 code-1-ex4 code-2-ex1 code-2-ex2 code-2-ex3

```
(code appears here)

```

Due 11:59pm ending monday Jan 23rd (oops, said 16th here originally). Details for turning in to follow on Thu.

Problem 1

Write code that prints the following with your name.

```Hello, my name is Alice
Alice is in this class
Without a doubt Alice is working on this homework
```

Rather than mentioning your name directly, assign a variable to hold your name (i.e. name = ... ; ), then use that name variable within the print statements to insert your name. It should be possible to assign a different string to the variable, "Bob" or "Abby" or whatever, and then that name will appear in the printout when run.

Problem 2

Write code that changes the flowers.jpg as follows: for every pixel, set the red value to 0 and the green and blue values to 255. Print the resulting image.

hw1-ex2

 image = new SimpleImage("flowers.jpg"); for (pixel: image) { // your code here } print(image);

Problem 3

This is a 10-20-30 puzzle. Write code to recover and print the original image from the image 10-20-30-2.png.

 image = new SimpleImage("10-20-30-2.png"); for (pixel: image) { // your code here } print(image); hw1-ex3

4. Iron Image Puzzle

I must say, I really like this code puzzle as a way of getting a computing principles. This is a puzzle. You are given an image of something famous. However the image has been messed up: the real data is in the red channel, however the red channel values have all been divided by 10, so they are too small by a factor of 10. The blue and green channels are just meaningless random values ("noise") added to obscure the real image. You must undo all these steps to recover the real image.

 image = new SimpleImage("iron-puzzle.png"); for (pixel: image) { // Your code here } print(image); hw1-ex4-iron

5. Copper Image Puzzle

This is an image puzzle -- an image of something famous is hidden in the image "copper-puzzle.png". The real image is in the blue and green channels, however the blue and green values have all been divided by 20, so the values are very small. The red channel is just noise added on top to obscure things. Undo these obscuring factors to recover the original image.

 image = new SimpleImage("copper-puzzle.png"); for (pixel: image) { // Your code here } print(image); hw1-ex5-copper

6. California State Flower

Change the code below to make all of the following changes to the "flowers.jp g" image and print the result.

• Increase the red channel by multiplying each value by 1.1
• Decrease the green channel by dividing each value by 2
• Set the blue channel to 0 (not much change here, as the blue was very low a nyway)
• The overall effect should be to roughly transform the flowers to look more like the California state flower .. the poppy.

 image = new SimpleImage("flowers.jpg"); for (pixel: image) { // Your code here } print(image); hw1-ex6

Submission instructions: 1. On this page, click the button below to collect the code answers to all the questions as one block of text. Copy that text.
2. Now navigate to Coursework ---> Assignments --> Homework 1. There should be one question in Homework 1, where you will paste in the text of all your answers.
3. Submit the assignment in Coursework and you're done!

Retrieve Code

Retrieves locally stored exercise code for this page from the 'Run' button:

(code appears here)