Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
lehrkraefte:blc:math:oxocard [2019/04/04 22:16] Ivo Blöchliger created |
lehrkraefte:blc:math:oxocard [2019/04/05 10:08] (current) Ivo Blöchliger |
||
---|---|---|---|
Line 2: | Line 2: | ||
* [[https:// | * [[https:// | ||
+ | |||
+ | |||
+ | <code python oxocolors.py> | ||
+ | from oxocard import * | ||
+ | from random import randint | ||
+ | |||
+ | num = 3 | ||
+ | |||
+ | points = [[randint(0, | ||
+ | vecs = [[0.005*randint(20, | ||
+ | |||
+ | |||
+ | def glocke(p1, | ||
+ | d2 = (p1[0]-p2[0])**2+(p1[1]-p2[1])**2 | ||
+ | return int(255.0/ | ||
+ | | ||
+ | |||
+ | enableRepaint(False) | ||
+ | while True: | ||
+ | for i in range(8): | ||
+ | for k in range(8): | ||
+ | rgb = [glocke(points[c], | ||
+ | dot(i, k, rgb) | ||
+ | for c in range(num): | ||
+ | for i in range(2): | ||
+ | points[c][i]+=vecs[c][i] | ||
+ | if (points[c][i]< | ||
+ | vecs[c][i]=-vecs[c][i] | ||
+ | points[c][i]+=vecs[c][i] | ||
+ | | ||
+ | repaint() | ||
+ | </ | ||
+ | |||
+ | |||
+ | <code python accelerodemo.py> | ||
+ | from oxocard import * | ||
+ | from random import randint | ||
+ | from oxoaccelerometer import * | ||
+ | |||
+ | |||
+ | acc = Accelerometer.create() | ||
+ | |||
+ | num = 12 | ||
+ | |||
+ | points = [[randint(0, | ||
+ | colors = [] | ||
+ | for i in range(num): | ||
+ | colors.append([randint(50, | ||
+ | | ||
+ | grid = [[False for i in range(8)] for j in range(8)] | ||
+ | |||
+ | for p in points: | ||
+ | grid[p[0]][p[1]]=True | ||
+ | | ||
+ | |||
+ | def getDir(p): | ||
+ | if p<1: | ||
+ | return -1 | ||
+ | if p>2: | ||
+ | return 1 | ||
+ | return 0 | ||
+ | | ||
+ | | ||
+ | def onGrid(p): | ||
+ | return p[0]>=0 and p[0]<=7 and p[1]>=0 and p[1]<=7 | ||
+ | |||
+ | def add(p,v): | ||
+ | return [p[0]+v[0], | ||
+ | |||
+ | enableRepaint(False) | ||
+ | while True: | ||
+ | clear() | ||
+ | pref = [acc.getX()/ | ||
+ | for i in range(num): | ||
+ | p = points[i] | ||
+ | v = [getDir(randint(0, | ||
+ | r = add(p,v) | ||
+ | if onGrid(r): | ||
+ | if grid[r[0]][r[1]]==False: | ||
+ | grid[r[0]][r[1]]=True | ||
+ | grid[p[0]][p[1]]=False | ||
+ | p[0]=r[0] | ||
+ | p[1]=r[1] | ||
+ | dot(p[0], | ||
+ | | ||
+ | | ||
+ | repaint() | ||
+ | |||
+ | </ |