| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -69,18 +69,6 @@ Karma Phy - Looks better spelt with a K | |||
| 69 | 69 | ||
| 70 | 70 | Karma Pi - Phy for physics, pi for math. | |
| 71 | 71 | ||
| 72 | - # Install | ||
| 73 | - | ||
| 74 | - To install from source: | ||
| 75 | - | ||
| 76 | - python setup.py install | ||
| 77 | - | ||
| 78 | - | ||
| 79 | - To install in development mode: | ||
| 80 | - | ||
| 81 | - python setup.py develop --user | ||
| 82 | - | ||
| 83 | - | ||
| 84 | 72 | ## Ubuntu on Pi | |
| 85 | 73 | ||
| 86 | 74 | ||
@@ -140,15 +128,62 @@ Docs need a fair bit of work, but better docstrings in the code turn into pretty | |||
| 140 | 128 | ||
| 141 | 129 | ## Release | |
| 142 | 130 | ||
| 131 | + pip3.x install karmapi | ||
| 132 | + | ||
| 133 | + x = 5 or 6, may be just 3.6 soon. | ||
| 134 | + | ||
| 135 | + ### Making a new release | ||
| 136 | + | ||
| 137 | + Install some stuff needed to help with building releases: | ||
| 138 | + | ||
| 139 | + pip3.6 install twine wheel | ||
| 140 | + | ||
| 141 | + Build a source releas (this just creates a tarball in the dists/ subfolder): | ||
| 142 | + | ||
| 143 | + python setup.py sdist | ||
| 144 | + | ||
| 145 | + Build a binary release as a wheel (: | ||
| 146 | + | ||
| 147 | + python setup.py bdist_wheel | ||
| 148 | + | ||
| 149 | + Upload to PyPi with twine (you will need a username and password that | ||
| 150 | + has access to the project you are trying to update): | ||
| 151 | + | ||
| 152 | + twine upload dist/* | ||
| 143 | 153 | ||
| 144 | 154 | ## Develop | |
| 145 | 155 | ||
| 146 | 156 | git clone https://github.com/openbermuda/karmapi | |
| 147 | 157 | ||
| 148 | 158 | cd karmapi | |
| 149 | 159 | ||
| 150 | - python3 setup.py develop --user | ||
| 160 | + pip3.6 -e , | ||
| 161 | + | ||
| 162 | + ## Python3.6 on Ubuntu 16.04 | ||
| 163 | + | ||
| 164 | + git clone https://github.com/python/cpython | ||
| 165 | + | ||
| 166 | + checkout 3.6 branch, then: | ||
| 167 | + | ||
| 168 | + ./configure | ||
| 169 | + make | ||
| 170 | + make install | ||
| 171 | + | ||
| 172 | + Note: python3.6 can be installed (from universe) with apt on Ubuntu >= 16.10. | ||
| 173 | + | ||
| 174 | + ### Things to do first | ||
| 175 | + | ||
| 176 | + Some dev libraries need installing into Ubuntu for certain features to be built into the python. | ||
| 177 | + | ||
| 178 | + tkinter is one part you need to make sure *tk-8.6-dev* is installed before ./configure. | ||
| 179 | + | ||
| 180 | + The good news is that after the intitial build it all runs pretty fast. | ||
| 181 | + | ||
| 182 | + * tk-8.6-dev -- for tkinter | ||
| 183 | + | ||
| 184 | + * libbz2-dev -- compression library | ||
| 151 | 185 | ||
| 186 | + * libssl-dev -- for ssl support required for pip3.6 to work. | ||
| 152 | 187 | ||
| 153 | 188 | ## TODO | |
| 154 | 189 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,49 @@ | |||
| 1 | + =========== | ||
| 2 | + Eric Idle | ||
| 3 | + =========== | ||
| 4 | + | ||
| 5 | + Eric Idle was a python. | ||
| 6 | + | ||
| 7 | + So when Guido needed a simple development environment to show people | ||
| 8 | + python, IDLE was born, | ||
| 9 | + | ||
| 10 | + | ||
| 11 | + IDLE gives you a python prompt and a simple editor that knows a little | ||
| 12 | + about python, | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + Python Console | ||
| 16 | + ============== | ||
| 17 | + | ||
| 18 | + Since *currie* is currently running using tkinter and *currie* could | ||
| 19 | + do with a console, time to take a look at IDLE. | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + Editor | ||
| 23 | + ====== | ||
| 24 | + | ||
| 25 | + An editor might be handy too, | ||
| 26 | + | ||
| 27 | + It might be easy to get these working in a *PigFarm*. | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + idlelib | ||
| 31 | + ======= | ||
| 32 | + | ||
| 33 | + The code for IDLE comes with python, you can import it with *idlelib*. | ||
| 34 | + | ||
| 35 | + A quick look at the code and pig farm integration does not look too | ||
| 36 | + hard. | ||
| 37 | + | ||
| 38 | + The main obstacle is that *idlelib* had solved a lot of what *PigFarm* | ||
| 39 | + and *piglets* are doing here. | ||
| 40 | + | ||
| 41 | + Who knew that a library called *idlelib* written 20 years ago might | ||
| 42 | + have saved some work? | ||
| 43 | + | ||
| 44 | + async idle | ||
| 45 | + ========== | ||
| 46 | + | ||
| 47 | + On a PigFarm the eventloop will be run by *curio*. | ||
| 48 | + | ||
| 49 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,14 @@ Astro pi | |||
| 49 | 49 | astro_pi | |
| 50 | 50 | ||
| 51 | 51 | ||
| 52 | + Eric | ||
| 53 | + ==== | ||
| 54 | + | ||
| 55 | + .. toctree:: | ||
| 56 | + | ||
| 57 | + eric | ||
| 58 | + | ||
| 59 | + | ||
| 52 | 60 | Indices and tables | |
| 53 | 61 | ================== | |
| 54 | 62 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ | |||
| 15 | 15 | """ | |
| 16 | 16 | from collections import deque | |
| 17 | 17 | import curio | |
| 18 | + from pathlib import Path | ||
| 18 | 19 | ||
| 19 | 20 | from karmapi import hush | |
| 20 | 21 | ||
@@ -249,7 +250,7 @@ def main(): | |||
| 249 | 250 | ||
| 250 | 251 | parser.add_argument('--monitor', action='store_true') | |
| 251 | 252 | parser.add_argument('--nomon', action='store_false', default=True) | |
| 252 | - | ||
| 253 | + parser.add_argument('--words', default='diceware.wordlist.asc') | ||
| 253 | 254 | ||
| 254 | 255 | args = parser.parse_args() | |
| 255 | 256 | ||
@@ -302,12 +303,19 @@ def main(): | |||
| 302 | 303 | im_info.update(im) | |
| 303 | 304 | farm.add(piglet.Image, im_info.copy()) | |
| 304 | 305 | ||
| 306 | + | ||
| 307 | + words = Path(args.words) | ||
| 308 | + if words.exists(): | ||
| 309 | + words = words.open() | ||
| 310 | + else: | ||
| 311 | + words = None | ||
| 312 | + | ||
| 305 | 313 | farm.add(talk.Talk) | |
| 306 | - farm.add(dice.StingingBats) | ||
| 314 | + farm.add(dice.StingingBats, dict(words=words)) | ||
| 307 | 315 | farm.add(StingingBats) | |
| 308 | 316 | ||
| 309 | 317 | farm.add(TankRain) | |
| 310 | - farm.add(sunny.Sunspot) | ||
| 318 | + #farm.add(sunny.Sunspot) | ||
| 311 | 319 | farm.add(sonogram.SonoGram) | |
| 312 | 320 | farm.add(piglet.XKCD) | |
| 313 | 321 | farm.add(widgets.InfinitySlalom) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,14 +14,25 @@ | |||
| 14 | 14 | import random | |
| 15 | 15 | import math | |
| 16 | 16 | ||
| 17 | + BIGLY = 'helvetica 20 bold' | ||
| 17 | 18 | ||
| 18 | 19 | class StingingBats(pig.Canvas): | |
| 19 | 20 | ||
| 20 | - def __init__(self, parent): | ||
| 21 | + def __init__(self, parent, words=None): | ||
| 21 | 22 | ||
| 22 | 23 | super().__init__(parent) | |
| 23 | 24 | ||
| 24 | 25 | self.width = self.height = 200 | |
| 26 | + | ||
| 27 | + if words: | ||
| 28 | + self.words = load_words(words) | ||
| 29 | + else: | ||
| 30 | + self.words = None | ||
| 31 | + | ||
| 32 | + self.size = 5 | ||
| 33 | + self.sides = 6 | ||
| 34 | + self.canvas_text = None | ||
| 35 | + | ||
| 25 | 36 | self.minswarms = 20 | |
| 26 | 37 | self.maxswarms = 50 | |
| 27 | 38 | self.themes = [] | |
@@ -44,7 +55,21 @@ def create_event_map(self): | |||
| 44 | 55 | self.add_event_map('k', self.more) | |
| 45 | 56 | self.add_event_map('f', self.fast) | |
| 46 | 57 | self.add_event_map('s', self.slow) | |
| 58 | + self.add_event_map('r', self.roll) | ||
| 47 | 59 | self.add_event_map('t', self.next_theme) | |
| 60 | + self.add_event_map('u', self.up) | ||
| 61 | + self.add_event_map('d', self.down) | ||
| 62 | + | ||
| 63 | + async def up(self): | ||
| 64 | + """ Increase the number of dice """ | ||
| 65 | + | ||
| 66 | + self.size += 1 | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + async def down(self): | ||
| 70 | + """ Decrease the number of dice """ | ||
| 71 | + | ||
| 72 | + self.size -= 1 | ||
| 48 | 73 | ||
| 49 | 74 | ||
| 50 | 75 | async def next_theme(self): | |
@@ -77,9 +102,24 @@ async def slow(self): | |||
| 77 | 102 | ||
| 78 | 103 | self.sleep += 0.05 | |
| 79 | 104 | ||
| 105 | + async def roll(self): | ||
| 106 | + ''' roll the dice ''' | ||
| 107 | + | ||
| 108 | + self.data = [random.randint(1, self.sides) for die in range(self.size)] | ||
| 109 | + | ||
| 110 | + total = 0 | ||
| 111 | + for die in self.data: | ||
| 112 | + total += (total * self.size) + die | ||
| 113 | + | ||
| 114 | + self.total = total | ||
| 115 | + | ||
| 116 | + print(f'{self.data} {total}') | ||
| 117 | + | ||
| 118 | + self.canvas_text = f'{self.data} {total} {self.sides ** self.size}' | ||
| 119 | + | ||
| 120 | + | ||
| 80 | 121 | def create_swarms(self): | |
| 81 | 122 | ||
| 82 | - print('new swarms') | ||
| 83 | 123 | self.swarms = [Swarm() | |
| 84 | 124 | for x in range(random.randint(self.minswarms, self.maxswarms))] | |
| 85 | 125 | ||
@@ -95,6 +135,80 @@ def recalc(self, width, height): | |||
| 95 | 135 | self.canvas.configure(scrollregion=(0, 0, width, height)) | |
| 96 | 136 | ||
| 97 | 137 | ||
| 138 | + def draw_digit(self, x, y, size, die): | ||
| 139 | + """ Draw a digit like a die """ | ||
| 140 | + digits = { | ||
| 141 | + 1: ((0,0,0), (0,1,0), (0,0,0)), | ||
| 142 | + 2: ((1,0,0), (0,0,0), (0,0,1)), | ||
| 143 | + 3: ((1,0,0), (0,1,0), (0,0,1)), | ||
| 144 | + 4: ((1,0,1), (0,0,0), (1,0,1)), | ||
| 145 | + 5: ((1,0,1), (0,1,0), (1,0,1)), | ||
| 146 | + 6: ((1,0,1), (1,0,1), (1,0,1))} | ||
| 147 | + | ||
| 148 | + | ||
| 149 | + self.draw_pixel(digits[die], x, y, size, size, 10) | ||
| 150 | + | ||
| 151 | + def draw_pixel(self, data, x, y, width, height, size, colour=None): | ||
| 152 | + | ||
| 153 | + #colour = 'red' | ||
| 154 | + colour = colour or self.random_colour() | ||
| 155 | + | ||
| 156 | + for ix, row in enumerate(data): | ||
| 157 | + for jx, col in enumerate(row): | ||
| 158 | + | ||
| 159 | + xx = (ix * width) + x | ||
| 160 | + | ||
| 161 | + yy = (jx * height) + x | ||
| 162 | + | ||
| 163 | + #print(f'zzzz {xx} {yy} {size}, {colour}') | ||
| 164 | + | ||
| 165 | + if col: | ||
| 166 | + self.canvas.create_arc(xx-size, yy-size, xx+size, yy+size, | ||
| 167 | + start=0, extent=180, fill=colour) | ||
| 168 | + | ||
| 169 | + def random_colour(self): | ||
| 170 | + | ||
| 171 | + colours = self.theme.colours | ||
| 172 | + | ||
| 173 | + return colours[random.randint(0, len(colours) - 1)] | ||
| 174 | + | ||
| 175 | + | ||
| 176 | + def dice_ware_text(self): | ||
| 177 | + """ Return password for current data """ | ||
| 178 | + | ||
| 179 | + # FIXME get a diceware list of words | ||
| 180 | + # Also, remind me to write a bit about why real dice are better | ||
| 181 | + | ||
| 182 | + try: | ||
| 183 | + return self.words[tuple(self.data)] | ||
| 184 | + except: | ||
| 185 | + return "no dice" | ||
| 186 | + | ||
| 187 | + def draw_dice(self): | ||
| 188 | + """ Draw the dice """ | ||
| 189 | + | ||
| 190 | + #FIXME make the tkinter part async | ||
| 191 | + totsize = min(self.width, self.height) | ||
| 192 | + | ||
| 193 | + gap = totsize / (1 + self.size) | ||
| 194 | + | ||
| 195 | + xx = gap / 2 | ||
| 196 | + yy = gap / 2 | ||
| 197 | + | ||
| 198 | + ygap = (self.height / 3) / (self.size - 1) | ||
| 199 | + | ||
| 200 | + text = self.dice_ware_text() | ||
| 201 | + self.canvas.create_text(totsize - (2 * gap), yy, fill=self.random_colour(), | ||
| 202 | + text=text, font=BIGLY) | ||
| 203 | + | ||
| 204 | + for die in self.data: | ||
| 205 | + self.draw_digit(xx, yy, gap * 0.4, die) | ||
| 206 | + | ||
| 207 | + xx += gap | ||
| 208 | + yy += gap | ||
| 209 | + | ||
| 210 | + | ||
| 211 | + | ||
| 98 | 212 | async def run(self): | |
| 99 | 213 | self.sleep = 0.1 | |
| 100 | 214 | ||
@@ -112,6 +226,13 @@ async def run(self): | |||
| 112 | 226 | ray.draw(self.canvas, self.width, self.height, | |
| 113 | 227 | self.theme.colours) | |
| 114 | 228 | ||
| 229 | + if self.canvas_text: | ||
| 230 | + self.canvas.create_text((self.width * 0.3, self.height * 0.9), | ||
| 231 | + text=self.canvas_text, fill='yellow', | ||
| 232 | + font=BIGLY) | ||
| 233 | + self.draw_dice() | ||
| 234 | + | ||
| 235 | + | ||
| 115 | 236 | await curio.sleep(self.sleep) | |
| 116 | 237 | ||
| 117 | 238 | ||
@@ -132,7 +253,6 @@ def __init__(self): | |||
| 132 | 253 | self.step = 0 | |
| 133 | 254 | self.this_step = random.randint(40, 100) | |
| 134 | 255 | ||
| 135 | - | ||
| 136 | 256 | def draw(self, canvas, width, height, colours): | |
| 137 | 257 | ||
| 138 | 258 | ||
@@ -176,3 +296,18 @@ def draw(self, canvas, width, height, colours): | |||
| 176 | 296 | self.this_step = random.randint(40, 100) | |
| 177 | 297 | ||
| 178 | 298 | # FIXME: draw tail -- sine wave angle of dangle based on dx, dy | |
| 299 | + | ||
| 300 | + | ||
| 301 | + def load_words(infile): | ||
| 302 | + | ||
| 303 | + words = {} | ||
| 304 | + six = set([str(x) for x in range(1, 7)]) | ||
| 305 | + for row in infile: | ||
| 306 | + if row[0] in six: | ||
| 307 | + | ||
| 308 | + fields = row.split() | ||
| 309 | + key = tuple(int(x) for x in fields[0]) | ||
| 310 | + | ||
| 311 | + words[key] = fields[-1] | ||
| 312 | + | ||
| 313 | + return words | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments