Question

In: Computer Science

Write a graphics program that creates a graphics window that is 500 pixels wide and 300 pixels high.

IN PYTHON

Write a graphics program that creates a graphics window that is 500 pixels wide and 300 pixels high. Then draw a blue circle with radius 25 at (x,y) = (100,150). Then have the ‘ball’ (ie the circle) move horizontally to the right by 5 pixel steps, until it reaches x = 200. Then have it change color to red and move back to the starting point.

Solutions

Expert Solution

Here is the solutioin,

i providing two program one with for loop and other with while loop

program 1

# import of graphics module
# please install the module with the command
# pip install graphics

from graphics import *
from time import sleep

# window with width 500 and height 300
win = GraphWin('Radar', width=500, height=300)

# circle at position 100, 150 and radius 25
circle = Circle(Point(100, 150), 25)
circle.setFill("blue")
circle.draw(win)

# while loop works on condition
# continues the loop till the condition is true
while circle.getCenter().getX() <= 200:
    # to move the circle by 5 points horizontally
    circle.move(5, 0)
    # for delay
    sleep(0.05)

# change of colour to red
circle.setFill("red")

while circle.getCenter().getX() >= 100:
    # to move the circle by 5 points horizontally
    circle.move(-5, 0)
    # for delay
    sleep(0.05)


win.getMouse()
win.close()

program 2:

# import of graphics module
# please install the module with the command
# pip install graphics

from graphics import *
from time import sleep

# window with width 500 and height 300
win = GraphWin('Radar', width=500, height=300)

# circle at position 100, 150 and radius 25
circle = Circle(Point(100, 150), 25)
circle.setFill("blue")
circle.draw(win)

# basically i have divided 100/5 = 20
# this will take the circle till 200 position
for i in range(20):
    # to move the circle by 5 points horizontally
    circle.move(5, 0)
    # for delay
    sleep(0.05)

# change of colour to red
circle.setFill("red")
# basically i have divided 100/5 = 20
# this will take the circle till 200 position
for i in range(20):
    # to move the circle by 5 points horizontally
    circle.move(-5, 0)
    # for delay
    sleep(0.05)


win.getMouse()
win.close()

here is the sample output(final stage):-


Related Solutions

Write a Python graphics program that draws the following shapes: • window size: 250 x 250...
Write a Python graphics program that draws the following shapes: • window size: 250 x 250 pixels with window title with your name • big circle, 50 pixels radius with center at (125, 125) • two green circles, 10 pixels radius; first one centered at (113, 113) and second centered at (137, 113) • one red line, from (100, 150) to (150, 150) Then answer this, what do you see? (make this a comment in your code)
You will design and implement a graphics program that draws four concentric rectangles in a window,...
You will design and implement a graphics program that draws four concentric rectangles in a window, using four different colors of your choice, meeting the following specifications. • The size of the window is determined by the user of the program. To be specific, you should prompt the user for both the width and height of the window (in pixels), and then you should set the size of the window using these values. (Hint: use the setup() method of the...
Without using the graphics module, write a program to simulate an archery score tracker. Your program...
Without using the graphics module, write a program to simulate an archery score tracker. Your program should use a Tkinter canvas to draw a target. Your program should allow the user to click the target to mark where their arrow landed on the target (or off). When the user clicks the target, the program should draw a dot at that location and compute the score. Scores for each ring are as follows: yellow 5, red 4, blue 3, black 2,...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Write a program that creates a Singleton class to connect to two databases. The program must...
Write a program that creates a Singleton class to connect to two databases. The program must provide two instances of this class. One instance for connecting to MySQL database and the other for connecting to Oracle database.
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
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...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
Write a C program that creates a toy scheduler for the child processes in part A....
Write a C program that creates a toy scheduler for the child processes in part A. This program takes as input the number of processes, and all of the PIDs that are being echoed. HINT: Look up redirecting echo output. The program will schedule the ”processes” (note that these are not true processes, this is a toy system. You are effectively only scheduling echo statements). The result of the scheduler will be to echo the PID and current system time...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT