Skip to content

Instantly share code, notes, and snippets.

@oshea00
Created November 9, 2019 19:44
Show Gist options
  • Save oshea00/2c02257959c54be6368d25aa0214efd6 to your computer and use it in GitHub Desktop.
Save oshea00/2c02257959c54be6368d25aa0214efd6 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import random\n",
"from ipycanvas import Canvas"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"canvas = Canvas(size=(200,200))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"canvas.clear()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "384d0cbdea79453f91f0e3285fa25c4f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(layout=Layout(height='200px', width='200px'), size=(200, 200))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"canvas.fill_rect(25, 25, 100, 100)\n",
"canvas.clear_rect(45, 45, 60, 60)\n",
"canvas.stroke_rect(50, 50, 50, 50)\n",
"\n",
"canvas\n"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"def crosses(s,lines):\n",
" for l in lines:\n",
" if s[0][0] > s[1][0]:\n",
" s[0], s[1] = s[1], s[0]\n",
" if s[0][0] <= l and s[1][0] >= l:\n",
" return True\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"crosses([(125,80),(150,90)],[100,200])"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"random.seed()\n",
"random.randint(1,399)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment