-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.txt
408 lines (328 loc) · 13.8 KB
/
prompt.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
Write Python code to create a scene layout based on the shapes defined in the API below.
To write the code, you should refer to the following API:
"""
Scene Setup:
- Axes: x (left to right), y (top to bottom).
- Dimensions: Configured upon scene initialization with width and height.
- Colors: Background color is set during scene initialization.
Create scene with scene = Scene(size=(WIDTH, HEIGHT), bg_color='COLOR'). Manage objects by their shape types such as 'circle1', 'rectangle2', etc.
API for Adding Shapes:
- scene.add_shape(shape): Add shapes to the scene. Supported shapes include Circle, Rectangle, Triangle.
Shape Classes and Initialization:
- Circle(radius, color='black'): Initialize a circle with radius, color.
- Rectangle(width, height, color='black'): Initialize a rectangle with width, height, color.
- Triangle(size, color='black'): Initialize a triangle with side size, color.
Shape Positioning:
- shape.place_shape_global(position): Set global position of the shape.
- shape.place_shape_local(reference_shape, position, offset): Position the shape relative to another shape (position can be 'left', 'right', 'above', 'below', 'center').
Rendering and Visual Setup:
- scene.render(filename='scene.png'): Renders the entire scene to an image file with specified filename.
- Draw functions for each shape are internal methods used during the rendering process to depict shapes on the canvas.
Object Access and Manipulation:
- Direct scene.shapes for accessing list of shapes.
- Properties for shapes include color, position.
- Methods for moving is provided to adjust their positions and orientations within the scene.
The general structure of the program is as follows:
1. Initialize scene with dimensions.
2. Add shapes (circles, rectangles, triangles)
3. Place objects in the scene.
Note: Make sure you follow the above APIs, and structure of the program and add necessary amount of objects to make it look full.
"""
Here is the full implementation of the API for your reference:
from PIL import Image, ImageDraw
from utils.Shape import Circle, Rectangle, Triangle
class Scene:
"""
This class represents a scene where shapes can be added, removed, and rendered into an image.
Attributes:
size (tuple): The size of the scene as a tuple of width and height.
bg_color (str): The background color of the scene.
shapes (list): A list of shapes added to the scene.
"""
def __init__(self, size=(800, 600), bg_color="white"):
"""
This is a constructor for the Scene class.
Parameters:
size (tuple, optional): The size of the scene as a tuple of width and height. Defaults to (800, 600).
bg_color (str, optional): The background color of the scene. Defaults to 'white'.
"""
self.size = size
self.bg_color = bg_color
self.shapes = []
def add_shape(self, shape):
"""
This method adds a shape to the scene.
Parameters:
shape (Shape): The shape to be added to the scene.
Returns:
None
"""
self.shapes.append(shape)
def render(self, filename="scene.png"):
"""
This method renders the scene into an image file.
Parameters:
filename (str, optional): The name of the image file. Defaults to 'scene.png'.
Returns:
None
"""
image = Image.new("RGB", self.size, self.bg_color)
draw = ImageDraw.Draw(image)
for shape in self.shapes:
if isinstance(shape, Circle):
self.draw_circle(draw, shape)
elif isinstance(shape, Rectangle):
self.draw_rectangle(draw, shape)
elif isinstance(shape, Triangle):
self.draw_triangle(draw, shape)
image.save(filename)
def draw_circle(self, draw, circle):
"""
This method draws a circle on the scene.
Parameters:
draw (ImageDraw.Draw): The drawing context.
circle (Circle): The circle to be drawn.
Returns:
None
"""
left_up = (
circle.position[0] - circle.radius,
circle.position[1] - circle.radius,
)
right_down = (
circle.position[0] + circle.radius,
circle.position[1] + circle.radius,
)
draw.ellipse([left_up, right_down], outline=circle.color, fill=circle.color)
def draw_rectangle(self, draw, rectangle):
"""
This method draws a rectangle on the scene.
Parameters:
draw (ImageDraw.Draw): The drawing context.
rectangle (Rectangle): The rectangle to be drawn.
Returns:
None
"""
cx, cy = rectangle.position
width, height = rectangle.width, rectangle.height
# Calculate half of the width and height
half_width, half_height = width / 2, height / 2
# Calculate the coordinates of the rectangle from the center
coords = [
cx - half_width,
cy - half_height, # Top-left
cx + half_width,
cy - half_height, # Top-right
cx + half_width,
cy + half_height, # Bottom-right
cx - half_width,
cy + half_height, # Bottom-left
]
draw.polygon(coords, outline=rectangle.color, fill=rectangle.color)
def draw_triangle(self, draw, triangle):
cx, cy = triangle.position
size = triangle.size
# Assuming an equilateral triangle, calculate the initial coordinates
height = size * (3**0.5) / 2 # Height of equilateral triangle
coords = [
(cx, cy - 2 / 3 * height), # Top vertex
(cx - size / 2, cy + 1 / 3 * height), # Bottom left vertex
(cx + size / 2, cy + 1 / 3 * height), # Bottom right vertex
]
# Draw the triangle using the polygon method with three points
draw.polygon(coords, outline=triangle.color, fill=triangle.color)class Shape:
def __init__(self, color="black"):
self.position = (0, 0)
self.color = color
def place_shape_global(self, position):
"""
This method places the shape at a global position specified by the 'position' parameter.
Parameters:
position (tuple): A tuple containing the x and y coordinates where the shape will be placed.
Returns:
None
"""
self.position = position
return None
def place_shape_local(self, reference_shape, position, offset=(0, 0)):
"""
Place the shape adjacent to a reference shape.
Parameters:
reference_shape : Shape
The shape to use as the reference for positioning.
position : str
The desired position adjacent to the reference shape. Can only be one of: "left", "right", "above", "below", "center".
offset : tuple of int, optional
A tuple (x_offset, y_offset) that specifies additional offset to apply to the final position.
A positive x value moves the shape to the right, a negative x value moves the shape to the left.
A positive y value moves the shape down, a negative y value moves the shape up.
Returns:
None
"""
ref_x, ref_y = reference_shape.position
self_dim = self.dimension
ref_dim = reference_shape.dimension
# TODO: replace with simpler code
if self.__class__.__name__ == "Triangle":
if position == "above":
self_dim = (self_dim[0], self_dim[1]/(3**0.5))
elif position == "below":
self_dim = (self_dim[0], 2*self_dim[1]/(3**0.5))
if reference_shape.__class__.__name__ == "Triangle":
if position == "above":
ref_dim = (ref_dim[0], 2*ref_dim[1]/(3**0.5))
elif position == "below":
ref_dim = (ref_dim[0], ref_dim[1]/(3**0.5))
offset_x = (self_dim[0] + ref_dim[0]) // 2
offset_y = (self_dim[1] + ref_dim[1]) // 2
if position == "left":
new_x = ref_x - offset_x
new_y = ref_y
elif position == "right":
new_x = ref_x + offset_x
new_y = ref_y
elif position == "above":
new_y = ref_y - offset_y
new_x = ref_x
elif position == "below":
new_y = ref_y + offset_y
new_x = ref_x
elif position == "center":
new_x = ref_x
new_y = ref_y
new_x += offset[0]
new_y += offset[1]
self.place_shape_global((new_x, new_y))
class Circle(Shape):
def __init__(self, radius, color="black"):
"""
This is a constructor for the Circle class which inherits from the Shape class.
Parameters:
radius (float): The radius of the circle.
color (str, optional): The color of the circle. Defaults to 'black'.
"""
super().__init__(color)
self.radius = radius
self.dimension = (radius * 2, radius * 2)
class Rectangle(Shape):
def __init__(self, width, height, color="black"):
"""
This is a constructor for the Rectangle class which inherits from the Shape class.
Parameters:
width (float): The width of the rectangle.
height (float): The height of the rectangle.
color (str, optional): The color of the rectangle. Defaults to 'black'.
"""
super().__init__(color)
self.width = width
self.height = height
self.dimension = (width, height)
class Triangle(Shape):
def __init__(self, size, color="black"):
"""
This is a constructor for the Triangle class which inherits from the Shape class.
Parameters:
size (float): The size of the triangle, which is used as the length of its sides.
color (str, optional): The color of the triangle. Defaults to 'black'.
rotation (int, optional): The rotation of the triangle in degrees. Defaults to 0.
"""
super().__init__(color)
self.size = size
self.dimension = (size, size)
Following are a few simple examples of how to write code in your response:
from utils.Shape import Circle, Rectangle
from utils.Scene import Scene
# Initialize the scene
scene = Scene(size=(800, 600), bg_color='lightblue')
# Create the sun
sun_radius = 150
sun = Circle(radius=sun_radius, color='yellow')
sun.place_shape_global((400, 150))
scene.add_shape(sun)
# Create the clouds
cloud_radius_1 = 100
cloud_1 = Circle(radius=cloud_radius_1, color='white')
cloud_1.place_shape_global((600, 250))
scene.add_shape(cloud_1)
cloud_radius_2 = 80
cloud_2 = Circle(radius=cloud_radius_2, color='white')
cloud_2.place_shape_local(cloud_1, 'left', offset=(-50, 50))
scene.add_shape(cloud_2)
cloud_radius_3 = 90
cloud_3 = Circle(radius=cloud_radius_3, color='white')
cloud_3.place_shape_local(cloud_1, 'right', offset=(50, 30))
scene.add_shape(cloud_3)
cloud_radius_4 = 70
cloud_4 = Circle(radius=cloud_radius_4, color='white')
cloud_4.place_shape_local(cloud_1, 'above', offset=(0, -50))
scene.add_shape(cloud_4)
cloud_radius_5 = 60
cloud_5 = Circle(radius=cloud_radius_5, color='white')
cloud_5.place_shape_local(cloud_4, 'right', offset=(50, 0))
scene.add_shape(cloud_5)
# Create the ground
ground = Rectangle(width=800, height=200, color='green')
ground.place_shape_global((400, 500))
scene.add_shape(ground)
# Render the scene
scene.render('sky_with_clouds_and_sun.png')
scene.render(filename='output.png')
from utils.Shape import Circle, Rectangle, Triangle
from utils.Scene import Scene
# Initialize the scene
scene = Scene(size=(800, 600), bg_color='lightblue')
# Create the lake
lake = Rectangle(width=800, height=400, color='blue')
lake.place_shape_global((400, 400))
scene.add_shape(lake)
# Create the sky
sky = Rectangle(width=800, height=200, color='lightblue')
sky.place_shape_global((400, 100))
scene.add_shape(sky)
# Create the fish
fish_size = 50
fish1 = Triangle(size=fish_size, color='orange')
fish1.place_shape_global((200, 500))
scene.add_shape(fish1)
fish2 = Triangle(size=fish_size, color='orange')
fish2.place_shape_global((300, 500))
scene.add_shape(fish2)
fish3 = Triangle(size=fish_size, color='orange')
fish3.place_shape_global((400, 500))
scene.add_shape(fish3)
fish4 = Triangle(size=fish_size, color='orange')
fish4.place_shape_global((500, 550))
scene.add_shape(fish4)
fish5 = Triangle(size=fish_size, color='orange')
fish5.place_shape_global((600, 550))
scene.add_shape(fish5)
# Create the tree
tree_width = 100
tree_height = 200
tree_trunk = Rectangle(width=50, height=tree_height, color='brown')
tree_trunk.place_shape_global((700, 400))
scene.add_shape(tree_trunk)
tree_canopy = Rectangle(width=tree_width, height=tree_height, color='green')
tree_canopy.place_shape_local(tree_trunk, 'above')
scene.add_shape(tree_canopy)
# Create the sun
sun = Circle(radius=50, color='yellow')
sun.place_shape_global((100, 100))
scene.add_shape(sun)
# Render the scene
scene.render('lake_with_fish.png')
scene.render(filename='output.png')
Now write code to Create a scene with a sailing boat on the sea in a sunny day.
You should follow these drawing steps:
Here are the drawing steps for the scene with a sailing boat on the sea in a sunny day:
1. A large blue rectangle is placed in the bottom of the scene (sea).
2. A light blue rectangle is placed in the top half of the scene (sky).
3. A yellow circle is placed in the top right corner of the sky (sun).
4. A white rectangle is placed in the center of the sea (sailing boat body).
5. A white triangle is placed at the top of the boat body (sail).
6. Two small black rectangles are placed at the bottom of the boat body (boat keel).
7. A small brown rectangle is placed at the center of the boat body (mast).
8. Two small white triangles are placed on either side of the mast (sails).
9. A small white rectangle is placed at the front of the boat body (bow).
10. A small white rectangle is placed at the rear of the boat body (stern).
Write your code within <code> tags.