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...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels,...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels, filled with a random color at a random location on the screen. When you click the circle, it disappears and a new random color circle is displayed at another random location (see display below). After twenty circles are clicked, display the time spent in the pane. To detect whether a point is inside the circle, use the contains method defined in the Node class....
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...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
IN JAVA write a program that creates an array of strings with 8 people in it....
IN JAVA write a program that creates an array of strings with 8 people in it. Second,  Assign a random rank between 1 to 8 to each of the players. The rankings do not change throughout the tournament. Finally, Sort the players based on the rankings and print the data (show rankings of players, in square brackets, at every step after they are ranked). USING JAVA COLLECTIONS IS NOT ALLOWED
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT