To write a program that draws a stoplight with a gray rectangle and three circles, you can use a programming language that supports graphical drawing, such as Python with the turtle module. Here's a step-by-step guide on how to accomplish this:
1. Set up a programming environment with Python and the turtle module installed.
2. Import the turtle module and initialize the turtle object.
```python
import turtle
# Initialize turtle
my_turtle = turtle.Turtle()
my_turtle.speed(0)
```
3. Define the necessary variables for the stoplight layout, such as the dimensions of the rectangle and the offset value.
```python
# Dimensions of the rectangle
rect_width = 200
rect_height = 400
# Offset value for red and green lights
buffer = 100
```
4. Draw the gray rectangle centered on the screen.
```python
def draw_rectangle(width, height):
my_turtle.penup()
my_turtle.goto(-width / 2, -height / 2)
my_turtle.pendown()
my_turtle.color("gray")
my_turtle.begin_fill()
for _ in range(2):
my_turtle.forward(width)
my_turtle.left(90)
my_turtle.forward(height)
my_turtle.left(90)
my_turtle.end_fill()
draw_rectangle(rect_width, rect_height)
```
5. Define a function to draw a circle with a given position and color.
```python
def draw_circle(x, y, radius, color):
my_turtle.penup()
my_turtle.goto(x, y)
my_turtle.pendown()
my_turtle.color(color)
my_turtle.begin_fill()
my_turtle.circle(radius)
my_turtle.end_fill()
# Calculate the x and y positions for the circles
yellow_x = 0
yellow_y = 0
red_x = yellow_x - buffer
red_y = yellow_y
green_x = yellow_x + buffer
green_y = yellow_y
# Define the radius of the circles
circle_radius = 80
# Draw the circles
draw_circle(red_x, red_y, circle_radius, "red")
draw_circle(yellow_x, yellow_y, circle_radius, "yellow")
draw_circle(green_x, green_y, circle_radius, "green")
```
6. Finally, call the main turtle module functions to display the stoplight.
```python
# Hide the turtle cursor
my_turtle.hideturtle()
# Keep the window open until closed manually
turtle.done()
```
That's it! When you run the program, it will draw a stoplight with a gray rectangle and three circles (red, yellow, and green) on the screen. The yellow light will be centered, while the red and green lights will be offset by the specified BUFFER amount.