====== Programmieren der Oxocard in TigerJython ====== * [[https://www.tigerjython4kids.ch/index.php?inhalt_links=robotik/navigation.inc.php&inhalt_mitte=robotik/oxocard/sequenz.inc.php|Tutorial]] from oxocard import * from random import randint num = 3 points = [[randint(0,7), randint(0,7)] for i in range(num)] vecs = [[0.005*randint(20,100), 0.005*randint(20,100)] for i in range(num)] def glocke(p1,p2): d2 = (p1[0]-p2[0])**2+(p1[1]-p2[1])**2 return int(255.0/(1.0+d2/5)) enableRepaint(False) while True: for i in range(8): for k in range(8): rgb = [glocke(points[c],[i,k]) for c in range(3)] dot(i, k, rgb) for c in range(num): for i in range(2): points[c][i]+=vecs[c][i] if (points[c][i]<-2 or points[c][i]>10): vecs[c][i]=-vecs[c][i] points[c][i]+=vecs[c][i] repaint() from oxocard import * from random import randint from oxoaccelerometer import * acc = Accelerometer.create() num = 12 points = [[randint(0,7), randint(0,7)] for i in range(num)] colors = [] for i in range(num): colors.append([randint(50,255),randint(50,255),randint(50,255)]) 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],p[1]+v[1]] enableRepaint(False) while True: clear() pref = [acc.getX()/4.0, -acc.getY()/4.0] # preferred direction of movement for i in range(num): p = points[i] v = [getDir(randint(0,300)/100.0+pref[k]) for k in range(2)] 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],p[1],colors[i]) repaint()