Skip to content

Commit b1ceaf8

Browse files
Merge pull request #2703 from avinashkranjan/deepsource-transform-15f88397
format code with autopep8
2 parents 4ac1493 + 53ce4aa commit b1ceaf8

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

Pixel Art Generator/pixel_art_generator.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
import tkinter as tk
33
from tkinter import colorchooser, simpledialog, messagebox
44

5-
turtle.setup(width=800, height=600)
6-
turtle.speed(0)
7-
turtle.title("Pixel Art Generator")
5+
turtle.setup(width=800, height=600)
6+
turtle.speed(0)
7+
turtle.title("Pixel Art Generator")
8+
89

910
def draw_pixel(x, y, color, size):
1011
turtle.penup()
1112
turtle.goto(x - size // 2, y - size // 2)
1213
turtle.pendown()
1314
turtle.dot(size, color)
1415

16+
1517
def draw_square(x, y, color, size, fill=False):
1618
turtle.penup()
1719
turtle.goto(x - size // 2, y - size // 2)
@@ -25,6 +27,7 @@ def draw_square(x, y, color, size, fill=False):
2527
if fill:
2628
turtle.end_fill()
2729

30+
2831
def draw_circle(x, y, color, size, fill=False):
2932
turtle.penup()
3033
turtle.goto(x, y - size // 2)
@@ -36,6 +39,7 @@ def draw_circle(x, y, color, size, fill=False):
3639
if fill:
3740
turtle.end_fill()
3841

42+
3943
def draw_triangle(x, y, color, size, fill=False):
4044
turtle.penup()
4145
turtle.goto(x, y - size // 2)
@@ -49,6 +53,7 @@ def draw_triangle(x, y, color, size, fill=False):
4953
if fill:
5054
turtle.end_fill()
5155

56+
5257
def draw_diamond(x, y, color, size, fill=False):
5358
turtle.penup()
5459
turtle.goto(x, y - size // 2)
@@ -64,6 +69,7 @@ def draw_diamond(x, y, color, size, fill=False):
6469
if fill:
6570
turtle.end_fill()
6671

72+
6773
def draw_heart(x, y, color, size, fill=False):
6874
turtle.penup()
6975
turtle.goto(x, y - size // 2)
@@ -80,6 +86,7 @@ def draw_heart(x, y, color, size, fill=False):
8086
if fill:
8187
turtle.end_fill()
8288

89+
8390
def draw_polygon(x, y, color, size, sides, fill=False):
8491
turtle.penup()
8592
turtle.goto(x, y - size // 2)
@@ -94,6 +101,7 @@ def draw_polygon(x, y, color, size, sides, fill=False):
94101
if fill:
95102
turtle.end_fill()
96103

104+
97105
def draw_line(x, y, color, size, thickness):
98106
turtle.penup()
99107
turtle.goto(x - size // 2, y)
@@ -102,6 +110,7 @@ def draw_line(x, y, color, size, thickness):
102110
turtle.pencolor(color)
103111
turtle.forward(size)
104112

113+
105114
def draw_star(x, y, color, size, points, fill=False):
106115
turtle.penup()
107116
turtle.goto(x, y - size // 2)
@@ -115,6 +124,7 @@ def draw_star(x, y, color, size, points, fill=False):
115124
if fill:
116125
turtle.end_fill()
117126

127+
118128
def draw_spiral(x, y, color, size, loops):
119129
turtle.penup()
120130
turtle.goto(x, y - size // 2)
@@ -124,13 +134,16 @@ def draw_spiral(x, y, color, size, loops):
124134
turtle.forward(size / 20)
125135
turtle.right(10)
126136

137+
127138
def set_background_color():
128139
color = colorchooser.askcolor(title="Choose a background color")
129140
if color[1] is not None:
130141
turtle.bgcolor(color[1])
131142

143+
132144
def set_pen_style():
133-
pen_style = simpledialog.askstring("Pen Style", "Enter the pen style (solid/dashed/dotted):")
145+
pen_style = simpledialog.askstring(
146+
"Pen Style", "Enter the pen style (solid/dashed/dotted):")
134147
if pen_style in ['solid', 'dashed', 'dotted']:
135148
turtle.pensize(1)
136149
if pen_style == 'dashed':
@@ -140,25 +153,33 @@ def set_pen_style():
140153
turtle.pendown()
141154
turtle.pendown(1, 1)
142155

156+
143157
def get_color():
144158
color = colorchooser.askcolor(title="Choose a color")
145159
if color[1] is not None:
146160
return color[1]
147161
else:
148162
return None
149163

164+
150165
def get_size():
151-
size = simpledialog.askinteger("Size", "Enter the size (5-50):", minvalue=5, maxvalue=50)
166+
size = simpledialog.askinteger(
167+
"Size", "Enter the size (5-50):", minvalue=5, maxvalue=50)
152168
return size
153169

170+
154171
def get_thickness():
155-
thickness = simpledialog.askinteger("Thickness", "Enter the thickness (1-10):", minvalue=1, maxvalue=10)
172+
thickness = simpledialog.askinteger(
173+
"Thickness", "Enter the thickness (1-10):", minvalue=1, maxvalue=10)
156174
return thickness
157175

176+
158177
def get_sides():
159-
sides = simpledialog.askinteger("Sides", "Enter the number of sides (3-10):", minvalue=3, maxvalue=10)
178+
sides = simpledialog.askinteger(
179+
"Sides", "Enter the number of sides (3-10):", minvalue=3, maxvalue=10)
160180
return sides
161181

182+
162183
def main():
163184
turtle.speed(0)
164185
turtle.title("Pixel Art Generator")
@@ -168,7 +189,8 @@ def main():
168189
canvas.bgcolor("white")
169190

170191
while True:
171-
pattern = tk.simpledialog.askstring("Pattern", "Choose a pattern (square/circle/triangle/diamond/heart/polygon/line/star/spiral/clear/save/background/pen_style/exit):")
192+
pattern = tk.simpledialog.askstring(
193+
"Pattern", "Choose a pattern (square/circle/triangle/diamond/heart/polygon/line/star/spiral/clear/save/background/pen_style/exit):")
172194
if pattern == 'exit':
173195
break
174196

@@ -177,11 +199,13 @@ def main():
177199
canvas.update()
178200
continue
179201
elif pattern == 'save':
180-
file_path = tk.filedialog.asksaveasfilename(defaultextension=".png", filetypes=[("PNG files", "*.png")])
202+
file_path = tk.filedialog.asksaveasfilename(
203+
defaultextension=".png", filetypes=[("PNG files", "*.png")])
181204
if file_path:
182205
canvas.getcanvas().postscript(file=file_path + ".eps")
183206
canvas.update()
184-
messagebox.showinfo("Saved", f"Pixel art saved as {file_path}.png")
207+
messagebox.showinfo(
208+
"Saved", f"Pixel art saved as {file_path}.png")
185209
continue
186210
elif pattern == 'background':
187211
set_background_color()
@@ -224,26 +248,31 @@ def main():
224248
if not thickness:
225249
break
226250
draw_func = draw_line
227-
canvas.onclick(lambda x, y: draw_func(x, y, color, size, thickness))
251+
canvas.onclick(lambda x, y: draw_func(
252+
x, y, color, size, thickness))
228253
continue
229254
elif pattern == 'star':
230-
points = simpledialog.askinteger("Points", "Enter the number of points (5-20):", minvalue=5, maxvalue=20)
255+
points = simpledialog.askinteger(
256+
"Points", "Enter the number of points (5-20):", minvalue=5, maxvalue=20)
231257
if not points:
232258
break
233259
fill = messagebox.askyesno("Fill", "Fill the star with color?")
234260
draw_func = draw_star
235261
elif pattern == 'spiral':
236-
loops = simpledialog.askinteger("Loops", "Enter the number of loops (1-20):", minvalue=1, maxvalue=20)
262+
loops = simpledialog.askinteger(
263+
"Loops", "Enter the number of loops (1-20):", minvalue=1, maxvalue=20)
237264
if not loops:
238265
break
239266
draw_func = draw_spiral
240267

241268
if pattern != 'line' and pattern != 'star' and pattern != 'spiral':
242269
canvas.onclick(lambda x, y: draw_func(x, y, color, size, fill))
243270
else:
244-
canvas.onclick(lambda x, y: draw_func(x, y, color, size, points if pattern == 'star' else loops))
271+
canvas.onclick(lambda x, y: draw_func(
272+
x, y, color, size, points if pattern == 'star' else loops))
245273

246274
turtle.done()
247275

276+
248277
if __name__ == "__main__":
249278
main()

0 commit comments

Comments
 (0)