Created
December 22, 2025 10:40
-
-
Save codepediair/7dc4e828283784cf35624c5f459cef39 to your computer and use it in GitHub Desktop.
mincraft watermelon in python and turtle library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import turtle | |
| # --- Config --- | |
| PIXEL = 30 | |
| RED = "#e34234" | |
| LIGHT_RED ="#ff6666" | |
| SEED = "#000000" | |
| LIGHT_GREEN = "#55d455" | |
| DARK_GREEN = "#0f8a0f" | |
| BG = "#ffffff" | |
| # --- Setup --- | |
| screen = turtle.Screen() | |
| screen.title("Minecraft Watermelon Slice") | |
| screen.bgcolor(BG) | |
| t = turtle.Turtle() | |
| t.speed(0) | |
| t.hideturtle() | |
| # --- Helpers --- | |
| def draw_square(x, y, size, color): | |
| """Draw a filled square block at (x,y) with given size and color.""" | |
| t.penup() | |
| t.goto(x, y) | |
| t.pendown() | |
| if color == "#ffffff": | |
| t.pencolor(color) # border same as fill | |
| else: | |
| t.pencolor("black") | |
| t.fillcolor(color) | |
| t.begin_fill() | |
| for _ in range(4): | |
| t.forward(size) | |
| t.right(90) | |
| t.end_fill() | |
| def draw_pattern(pattern, pixel, colors): | |
| """Draw a grid pattern centered on screen.""" | |
| rows = len(pattern) | |
| cols = max(len(r) for r in pattern) | |
| start_x = -(cols * pixel) // 2 | |
| start_y = (rows * pixel) // 2 | |
| for row in range(rows): | |
| for col in range(len(pattern[row])): | |
| symbol = pattern[row][col] | |
| color = colors[symbol] | |
| x = start_x + col * pixel | |
| y = start_y - row * pixel | |
| draw_square(x, y, pixel, color) | |
| # --- Pattern --- | |
| pattern = [ | |
| ["W", "W", "W", "W", "W", "W", "W", "W", "W", "LG", "DG", "W", "W"], | |
| ["W", "W", "W", "W", "W", "W", "W", "W", "R", "LR", "LG", "DG", "W"], | |
| ["W", "W", "W", "W", "W", "W", "W", "R", "R", "R", "LR", "LG", "DG"], | |
| ["W", "W", "W", "W", "W", "W", "R", "R", "R", "S", "LR", "LG", "DG"], | |
| ["W", "W", "W", "W", "W", "R", "R", "R", "R", "R", "LR", "LG", "DG"], | |
| ["W", "W", "W", "W", "R", "R", "R", "S", "R", "R", "LR", "LG", "DG"], | |
| ["W", "W", "W", "R", "R", "R", "R", "R", "R", "R", "LR", "LG", "DG"], | |
| ["W", "W", "R", "R", "R", "S", "R", "R", "R", "R", "LR", "LG", "DG"], | |
| ["W", "R", "R", "R", "R", "R", "R", "R", "R", "LR", "LG", "DG", "DG"], | |
| ["DG", "LG", "LR", "S", "R", "R", "R", "R", "LR", "LG", "DG", "DG", "W"], | |
| ["DG", "DG", "LG", "LR", "LR", "LR", "LR", "LR", "LR", "LG", "DG", "W", "W"], | |
| ["W", "DG", "LG", "LG", "LG", "LG", "LG", "LG", "LG", "DG", "W", "W", "W"], | |
| ["W", "W", "DG", "DG", "DG", "DG", "DG", "DG", "DG", "W", "W", "W", "W"], | |
| ] | |
| colors = { | |
| "R": RED, | |
| "LR": LIGHT_RED, | |
| "S": SEED, | |
| "LG": LIGHT_GREEN, | |
| "DG": DARK_GREEN, | |
| "W": BG | |
| } | |
| # --- Draw --- | |
| draw_pattern(pattern, PIXEL, colors) | |
| turtle.done() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment