Your program must first ask the user for the name of the background image file.
ID: 3722057 • Letter: Y
Question
Your program must first ask the user for the name of the background image file. Several sample background images are provided on cuLearn, but please note that your program should work on images of any size. Your program must then ask the user how many ninjas should be added. The user must specify a number between 1 and 8 (inclusive), and if the user does not provide a valid number your program must continue to ask until they do. Eight ninja image files have been made available on cuLearn, and these files are numbered so the number of ninjas requested by the user will specify which ninjas to add. To clarify, if the user asks to add only 3 ninjas, then your program will need to add "ninja_image_01.bmp", "ninja_image_02.bmp", and "ninja_image_03.bmp". The user does not get to specify which ninjas are included in any other way. Once your program has the number of ninjas and the name of the background image file, it must create a pygame window that is the exact same size as the background image and use it to display the background image to the user. Then you must use a counter-controlled loop to repeatedly get the x and y co-ordinates at which you must center each ninja. You must ask for these values through the terminal and you must update the window after each new x and y co-ordinate is specified (i.e., first it will show the background image + ninja 1, then it will show the background image + ninja 1 + ninja 2, etc.). The x and y co-ordinates you receive from the user must not be outside the background image (i.e., the x value, for instance, cannot be less than 0 or greater than the width of the background image). If the user gives you invalid x or y co-ordinates, you must loop back and ask the user to enter the co-ordinate(s) again. If you have valid co-ordinates, then you must use nested loops to check each of the pixels from the ninja image and see if that pixel is green or not. If the pixel is not a green pixel, then you will copy that pixel from the ninja image onto the background image, at the correct location. Your solution must use nested loops to process each pixel in the ninja image and do the copying onto the background. You will be severely penalized if you use any of the pygame colorkey or alpha functions. Please also note that the user could conceivably provide co-ordinates that result in part of the ninja image appearing offscreen. If, for example, the user wants to center the first ninja at (0, 0), then only the bottom-right quadrant of that ninja image will actually be visible.
Explanation / Answer
<!doctype html>
<html>
<head>
<title>TextBox with Search Icon in HTML and CSS - Tutorial from www.codeofaninja.com</title>
</head>
<body>
</body>
</html>
<input type='text' placeholder='Search...' id='search-text-input' />
<div id='button-holder'>
<img src="magnifying_glass.png" />
</div>
<style>
#search-text-input{
border-top:thin solid #e5e5e5;
border-right:thin solid #e5e5e5;
border-bottom:0;
border-left:thin solid #e5e5e5;
box-shadow:0px 1px 1px 1px #e5e5e5;
float:left;
height:17px;
margin:.8em 0 0 .5em;
outline:0;
padding:.4em 0 .4em .6em;
width:183px;
}
#button-holder{
background-color:#f1f1f1;
border-top:thin solid #e5e5e5;
box-shadow:1px 1px 1px 1px #e5e5e5;
cursor:pointer;
float:left;
height:27px;
margin:11px 0 0 0;
text-align:center;
width:50px;
}
#button-holder img{
margin:4px;
width:20px;
}
</style>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.