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 program texttriangle.py. in python This, too, is not a graphics program. Prompt the...
* Write a program texttriangle.py. in python This, too, is not a graphics program. Prompt the user for a small positive integer value, that I’ll call n. Then use a for-loop with a range function call to make a triangular arrangement of ‘#’characters, with n ‘#’ characters in the last line. Hint: [5] Then leave a blank line. Then make a similar triangle, except start with the line with n ‘#’ characters. To make the second triangle, you can use...
Write a java program: Write a program that creates a text file. Write to the file...
Write a java program: Write a program that creates a text file. Write to the file three lines each line having a person's name. In the same program Append to the file one line of  'Kean University'.  In the same program then Read the file and print the four lines without lines between.
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....
Sketch! This assignment is to write a Python program that makes use of the OpenGL graphics...
Sketch! This assignment is to write a Python program that makes use of the OpenGL graphics library to make an interactive sketching program that will allow the user to do line drawings. The user should be able to choose from a palette of colors displayed on the screen. When the user clicks the mouse in the color palette area, the drawing tool will switch to using the color selected, much like dipping a paint brush into a new color of...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT