Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved draw_coords function #78

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions notebooks/nb1_matplotlib_and_numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
},
"outputs": [],
"source": [
"def draw_coords(coords, ax, params={}):\n",
"def draw_coords(ax, coords, **params):\n",
" \"\"\"\n",
" Takes a list of coordinates and draws them as scatter elements onto a pyplot ax object\n",
"\n",
" Input:\n",
" - coords: list of tuples of x,y coordinates\n",
" - ax: a pyplot ax object\n",
" - coords: list of tuples of x,y coordinates\n",
" - params: parameters to be passed to the scatter function (e.g. shape, size, color, etc.)\n",
" Returns:\n",
" - ax: a pyplot ax object\n",
Expand Down Expand Up @@ -104,7 +104,7 @@
" - bot : pelita bot object\n",
" - ax : a pyplot axis object\n",
" Returns:\n",
" -ax : a pyplot axis object\n",
" - ax : a pyplot axis object\n",
" \"\"\"\n",
" # Depending which team we are, we need to color the board appropriately\n",
" if bot.is_blue:\n",
Expand All @@ -124,13 +124,13 @@
"\n",
" # Then we call the draw_coords function for each type of element we want to draw.\n",
" # Each can be customized with whichever color, shape and size you want.\n",
" ax = draw_coords([bot.position], ax, {\"c\": col_home_b1, \"marker\": \"*\", \"s\": 400})\n",
" ax = draw_coords(bot.walls, ax, {\"c\": \"black\", \"marker\": \"s\", \"s\": 250})\n",
" ax = draw_coords([bot.other.position], ax, {\"c\": col_home_b2, \"marker\": \"*\", \"s\": 400})\n",
" ax = draw_coords(bot.food, ax, {\"c\": col_home_food, \"s\": 100})\n",
" ax = draw_coords(bot.enemy[0].food, ax, {\"c\": col_enemy_food, \"s\": 100})\n",
" ax = draw_coords([bot.enemy[0].position], ax, {\"c\": col_enemy_b1, \"marker\": \"*\", \"s\": 400})\n",
" ax = draw_coords([bot.enemy[1].position], ax, {\"c\": col_enemy_b2, \"marker\": \"*\", \"s\": 400})\n",
" ax = draw_coords(ax, [bot.position], c=col_home_b1, marker=\"*\", s=400)\n",
" ax = draw_coords(ax, bot.walls, c=\"black\", marker=\"s\", s=250)\n",
" ax = draw_coords(ax, [bot.other.position], c=col_home_b2, marker=\"*\", s=400)\n",
" ax = draw_coords(ax, bot.food, c=col_home_food, s=100)\n",
" ax = draw_coords(ax, bot.enemy[0].food, c=col_enemy_food, s=100)\n",
" ax = draw_coords(ax, [bot.enemy[0].position], c=col_enemy_b1, marker=\"*\", s=400)\n",
" ax = draw_coords(ax, [bot.enemy[1].position], c=col_enemy_b2, marker=\"*\", s=400)\n",
" ax.axvline(np.sum(ax.get_xlim()) / 2, c=\"black\")\n",
" # This is to get the coordinate system to have it's origin in the top left\n",
" yd, yu = ax.get_ylim()\n",
Expand Down
Loading