Question

Write a program that creates an image of green and white horizontal stripes. Your program should...

Write a program that creates an image of green and white horizontal stripes. Your program should ask the user for the size of your image, the name of the output file, and create a .png file of stripes. For example, if the user enters 10, your program should create a 10x10 image, alternating between green and white stripes.

A sample run of the program:

  Enter the size: 10
  Enter output file: 10stripes.png
  


Another sample run of the program:

  Enter the size: 50
  Enter output file: 50stripes.png
  


To create an image from scratch:

1 Import the libraries.

import matplotlib.pyplot as plt

import numpy as np

2 Create the image–

easy to set all color 1 to 0% (black): img = np.zeros( (num,num,3) )

2 to 100% (white): img = np.ones( (num,num,3) )

3 Do stuff to the pixels to make your image

4 You can display your image:

plt.imshow(img)

plt.show()

5 And save your image:

plt.imsave(’myImage.png’, img)

Homework Answers

Answer #1

Python code:

import matplotlib.pyplot as plt

import numpy as np

size = int(input("Enter the size: "))

fname = str(input("Enter output file: "))

#Initialize Image as white color with value 1 in all the pixel

img = np.ones( (size,size,3) )

for i in range(1,size,2):

for j in range(size):

img[i][j][1] = 1

img[i][j][0] = 0

img[i][j][2] = 0

plt.imsave(fname, img)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In this lab, you will write a program that creates a binary search tree based on...
In this lab, you will write a program that creates a binary search tree based on user input. Then, the user will indicate what order to print the values in. **Please write in C code** Start with the bst.h and bst.c base code provided to you. You will need to modify the source and header file to complete this lab. bst.h: #ifndef BST_H #define BST_H typedef struct BSTNode { int value; struct BSTNode* left; struct BSTNode* right; } BSTNode; BSTNode*...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following commands do: dd, y3, p, :set cindent (1 pt) VIM exercises These exercises on the computer need to be repeated by each student in the pair. This is to ensure that both students understand how to get around in Linux!!! For this part of the lab, you will create a .vimrc file that will help you develop your C++ programs using VIM. First, we...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
Question 1 of 15 Which of the following is not a recommended starting point to enter...
Question 1 of 15 Which of the following is not a recommended starting point to enter sales of products/services? A. Quick Create > Invoice B. Register > New transaction C. Quick Create > Sales Receipt D. Customer detail page > New transaction E. Transactions > Sales > New transaction Question 2 of 15 Which of the following statements accurately describes bank rules? A. Bank rules are imported from the Bank's website into the For Review tab in the Banking Center...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT