def draw_heart(handle): fsd = 256*256-1 sz = 256*8 points = [ messages_pb2.Move(x=int(fsd/2.0 + -sz*(13*math.cos(t)-5*math.cos(2*t)-2*math.cos(3*t)-math.cos(4*t))), y=int(fsd/2.0 + sz*16*math.sin(t)**3), laserPower=10) for t in numpy.linspace(0, 6, 2048) ] for i in xrange(10000): print "Sending batches of %d points" % (len(points,)) if i % 10 == 0: print sent, (sent / (time.time() - start)) for pt in points: send(handle, pt.SerializeToString())
def draw_heart(handle): fsd = 4 * 256 * 256 - 1 # points = [ messages_pb2.Move(x=int(t), y=int(t), laserPower=100) for t in numpy.linspace(0, fsd, 2048) ] points = [ messages_pb2.Move(x=int(fsd), y=int(0), laserPower=100) for t in numpy.linspace(0, fsd, 2048) ] print "First point %d, %d" % (points[0].x, points[0].y) print "First point %r" % (points[0].SerializeToString(), ) print "max", max(points, key=lambda p: max(p.x, p.y)) print "min", min(points, key=lambda p: min(p.x, p.y)) for i in xrange(10000): print "Sending batches of %d points" % (len(points, )) if i % 10 == 0: print sent, (sent / (time.time() - start)) for pt in points: send(handle, pt.SerializeToString())
global sent out = ['\x40', '\x02'] # \x02 is the message type for move for c in msg: if ord(c) in [0x40, 0x41, 0x42]: out.append('\x42') out.append('%c' % ((~ord(c)) & 0xFF), ) else: out.append(c) out.append('\x41') sent += len(out) #print sent, repr(''.join(out)) s.write(''.join(out)) fsd = 256 * 256 - 1 sz = 256 * 4 points = [(fsd / 2.0 + -sz * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t)), fsd / 2.0 + sz * 16 * math.sin(t)**3) for t in numpy.linspace(0, 6, 256)] for i in xrange(10000): print sent, (sent / (time.time() - start)) for x, y in points: move = messages_pb2.Move() move.x = int(x) move.y = int(y) move.laserPower = 24 send(move.SerializeToString())
def send(msg): global sent out = ['\x40', '\x02'] # \x02 is the message type for move for c in msg: if ord(c) in [0x40, 0x41, 0x42]: out.append('\x42') out.append('%c' % ((~ord(c)) & 0xFF), ) else: out.append(c) out.append('\x41') sent += len(out) #print sent, repr(''.join(out)) s.write(''.join(out)) fsd = 256 * 256 - 1 sz = 256 * 4 points = [ messages_pb2.Move(x=int(fsd / 2.0 + -sz * (13 * math.cos(t) - 5 * math.cos(2 * t) - 2 * math.cos(3 * t) - math.cos(4 * t))), y=int(fsd / 2.0 + sz * 16 * math.sin(t)**3), laserPower=10) for t in numpy.linspace(0, 6, 2048) ] for i in xrange(10000): if i % 100 == 0: print sent, (sent / (time.time() - start)) for pt in points: send(pt.SerializeToString())