dingrui17 commited on
Commit
a5cf0bb
·
1 Parent(s): 789a8ab

Initialized code.

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image, ImageDraw
3
+
4
+ # Initial game state
5
+ player_pos = [50, 50]
6
+ canvas_size = (200, 200)
7
+ step_size = 10
8
+
9
+ def update_frame(action):
10
+ global player_pos
11
+
12
+ # Move player based on action
13
+ if action == "w":
14
+ player_pos[1] -= step_size
15
+ elif action == "s":
16
+ player_pos[1] += step_size
17
+ elif action == "a":
18
+ player_pos[0] -= step_size
19
+ elif action == "d":
20
+ player_pos[0] += step_size
21
+
22
+ # Keep player inside bounds
23
+ player_pos[0] = max(0, min(canvas_size[0], player_pos[0]))
24
+ player_pos[1] = max(0, min(canvas_size[1], player_pos[1]))
25
+
26
+ # Draw frame
27
+ img = Image.new("RGB", canvas_size, color="white")
28
+ draw = ImageDraw.Draw(img)
29
+ draw.ellipse((player_pos[0]-5, player_pos[1]-5,
30
+ player_pos[0]+5, player_pos[1]+5),
31
+ fill="blue")
32
+ return img
33
+
34
+ iface = gr.Interface(
35
+ fn=update_frame,
36
+ inputs=gr.Dropdown(["w", "a", "s", "d"], label="Action"),
37
+ outputs=gr.Image(type="pil"),
38
+ live=False,
39
+ title="Simple WASD Game",
40
+ description="Move the blue dot using WASD!"
41
+ )
42
+
43
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ Pillow