def background(self): self.letters = f_read("emails") if config.NAME == "KLBFAX" and self.n == 1 and config.has_gmail_login( ): import gmail details = f_readlines("gmail") g = gmail.login(details[0], details[1]) unread = g.inbox().mail(unread=True) for mail in unread: mail.fetch() lines = "".join(mail.body.split("\r")).split("\n") if lines[ 0] == "EVENT" and "*****@*****.**" in mail.fr: try: with open_local('events', 'a') as f: for line in lines: if line != "EVENT": f.write(line + "\n") mail.read() except: pass elif lines[ 0] == "CARD" and "*****@*****.**" in mail.fr: with open('/home/pi/cards/' + lines[1], "w") as f: f.write("\n".join(lines[2:])) mail.read() elif "POINTS" in lines[0].upper( ) and "*****@*****.**" in mail.fr: from points import add_points length = 1 points_to_give = 0 while length <= len(lines[2]): try: if lines[2][:length] != "-": points_to_give = int(lines[2][:length]) length += 1 except: break add_points(lines[1].split("=")[0], points_to_give) mail.read() else: newletter = "" for line in lines: if line != "": while len(line) > 79: newletter += line[:79] + "\n" line = line[79:] newletter += line + "\n" self.letters = newletter + "\n" + "from " + mail.fr + "\n\n" + self.letters mail.read() self.letters = self.letters.split("\n") if len(self.letters) > 1000: self.letters = self.letters[:1000] with open_local("emails", "w") as f: f.write("\n".join(self.letters)) else: self.letters = self.letters.split("\n")
def create_stroke_outline(path, radius, linejoin=sk2const.JOIN_MITER, captype=sk2const.CAP_BUTT, miter_limit=MITER_LIMIT): """ Outlines a single stroke. Returns two lists of lists of bezier segments for both sides of the stroke. """ fw_segments = [] bw_segments = [] last_point = None segs = [path[0], ] + path[1] startpoint = [] + path[0] for i in range(len(segs)): segment = unpack_seg(segs[i], startpoint) startpoint = bezier_base_point(segs[i]) if not segment[0]: if last_point: c1 = sub_points(segment[2], last_point) if not c1 == [0.0]: t1 = mult_point(normalize(c1), radius) fw_segments.append( [add_points(last_point, [t1[1], -t1[0]]), add_points(segment[2], [t1[1], -t1[0]])]) bw_segments.insert(0, [sub_points(segment[2], [t1[1], -t1[0]]), sub_points(last_point, [t1[1], -t1[0]])]) last_point = segment[2] else: segments = build_parallel([last_point, segment[1][0], segment[1][1], segment[2]], radius) fw_segments.append(segments) segments = build_parallel([segment[2], segment[1][1], segment[1][0], last_point], radius) bw_segments.insert(0, segments) last_point = segment[2] # Connect segments if necessary for item in [fw_segments, bw_segments]: join_segs(item, radius, linejoin, miter_limit, path[2] == sk2const.CURVE_CLOSED) # Set caps for unclosed paths if not path[2] == sk2const.CURVE_CLOSED: fw_segments.insert(0, get_cap_segment(bw_segments[-1][-1], fw_segments[0][0], captype)) bw_segments.insert(0, get_cap_segment(fw_segments[-1][-1], bw_segments[0][0], captype)) return fw_segments, bw_segments
def create_stroke_outline (path, radius, linejoin=sk2_const.JOIN_MITER, captype=sk2_const.CAP_BUTT, miter_limit=MITER_LIMIT): """ Outlines a single stroke. Returns two lists of lists of bezier segments for both sides of the stroke. """ fw_segments = [] bw_segments = [] last_point = None segs = [path[0], ] + path[1] startpoint = [] + path[0] for i in range (len(segs)): segment = unpack_seg(segs[i], startpoint) startpoint = bezier_base_point(segs[i]) if not segment[0]: if last_point: c1 = sub_points(segment[2], last_point) if not c1 == [0.0]: t1 = mult_point(normalize(c1), radius) fw_segments.append( [add_points(last_point, [t1[1], -t1[0]]), add_points(segment[2], [t1[1], -t1[0]])]) bw_segments.insert(0, [sub_points(segment[2], [t1[1], -t1[0]]), sub_points(last_point, [t1[1], -t1[0]])]) last_point = segment[2] else: segments = build_parallel([last_point, segment[1][0], segment[1][1], segment[2]], radius) fw_segments.append(segments) segments = build_parallel([segment[2], segment[1][1], segment[1][0], last_point], radius) bw_segments.insert(0, segments) last_point = segment[2] # Connect segments if necessary for item in [fw_segments, bw_segments]: join_segs(item, radius, linejoin, miter_limit, path[2] == sk2_const.CURVE_CLOSED) # Set caps for unclosed paths if not path[2] == sk2_const.CURVE_CLOSED: fw_segments.insert(0, get_cap_segment (bw_segments[-1][-1], fw_segments[0][0], captype)) bw_segments.insert(0, get_cap_segment (fw_segments[-1][-1], bw_segments[0][0], captype)) return fw_segments, bw_segments
def build_parallel(p, radius, recursionlimit=6): """ This builds a list of bezier segments that are "sufficiently" close to a given source segment. It recursively subdivides, if the check for parallelity fails. """ # find tangent to calculate orthogonal neighbor of endpoint for i in p[1:]: c1 = sub_points(i, p[0]) if c1: break if c1 == [0, 0]: return [] t1 = mult_point(normalize(c1), radius) p0 = add_points(p[0], [t1[1], -t1[0]]) c1 = sub_points(p[1], p[0]) for i in [p[2], p[1], p[0]]: c2 = sub_points(p[3], i) if not c2 == [0, 0]: break t2 = mult_point(normalize(c2), radius) p3 = add_points(p[3], [t2[1], -t2[0]]) c2 = sub_points(p[3], p[2]) sd = subdivide_seg(p) center = sd[3] ccenter = mult_point(normalize(sub_points(sd[4], sd[3])), radius) new_center = add_points(center, [ccenter[1], -ccenter[0]]) seg = [p0, add_points(p0, c1), sub_points(p3, c2), p3] now_center = subdivide_seg(seg)[3] offset = mult_point(sub_points(new_center, now_center), 8.0 / 3) det = c1[0] * c2[1] - c1[1] * c2[0] if det: ndet = det / length(c1) / length(c2) else: ndet = 0 if math.fabs(ndet) >= 0.1: # "sufficiently" linear independent, cramers rule: oc1 = mult_point(c1, ((offset[0] * c2[1] - offset[1] * c2[0]) / det)) oc2 = mult_point(c2, ((c1[0] * offset[1] - c1[1] * offset[0]) / det)) else: # don't bother to try to correct the error, will figure out # soon if subdivision is necessary. oc1 = [0.0, 0.0] oc2 = [0.0, 0.0] new_p1 = add_points(add_points(p0, c1), oc1) new_p2 = add_points(sub_points(p3, c2), oc2) proposed_segment = [p0, new_p1, new_p2, p3] if check_parallel(p, proposed_segment, radius) or recursionlimit <= 0: return proposed_segment else: # "Not parallel enough" - subdivide. return (build_parallel(sd[:4], radius, recursionlimit - 1) + build_parallel(sd[3:], radius, recursionlimit - 1)[1:])
def build_parallel(p, radius, recursionlimit=6): """ This builds a list of bezier segments that are "sufficiently" close to a given source segment. It recursively subdivides, if the check for parallelity fails. """ # find tangent to calculate orthogonal neighbor of endpoint for i in p[1:]: c1 = sub_points(i, p[0]) if c1: break if c1 == [0, 0]: return [] t1 = mult_point(normalize(c1), radius) p0 = add_points(p[0], [t1[1], -t1[0]]) c1 = sub_points(p[1], p[0]) for i in [p[2], p[1], p[0]]: c2 = sub_points(p[3], i) if not c2 == [0, 0]: break t2 = mult_point(normalize(c2), radius) p3 = add_points(p[3], [t2[1], -t2[0]]) c2 = sub_points(p[3], p[2]) sd = subdivide_seg(p) center = sd[3] ccenter = mult_point(normalize(sub_points(sd[4], sd[3])), radius) new_center = add_points(center, [ccenter[1], -ccenter[0]]) seg = [p0, add_points(p0, c1), sub_points(p3, c2), p3] now_center = subdivide_seg(seg)[3] offset = mult_point(sub_points(new_center, now_center), 8.0 / 3) det = c1[0] * c2[1] - c1[1] * c2[0] if det: ndet = det / length(c1) / length(c2) else: ndet = 0 if math.fabs(ndet) >= 0.1: # "sufficiently" linear independent, cramers rule: oc1 = mult_point(c1, ((offset[0] * c2[1] - offset[1] * c2[0]) / det)) oc2 = mult_point(c2, ((c1[0] * offset[1] - c1[1] * offset[0]) / det)) else: # don't bother to try to correct the error, will figure out # soon if subdivision is necessary. oc1 = [0.0, 0.0] oc2 = [0.0, 0.0] new_p1 = add_points(add_points(p0, c1), oc1) new_p2 = add_points(sub_points(p3, c2), oc2) proposed_segment = [p0, new_p1, new_p2, p3] if check_parallel (p, proposed_segment, radius) or recursionlimit <= 0: return proposed_segment else: # "Not parallel enough" - subdivide. return (build_parallel (sd[:4], radius, recursionlimit - 1) + build_parallel (sd[3:], radius, recursionlimit - 1)[1:])
def generate_content(self): if self.points: from points import add_points add_points("Slytherin", 2) if self.points: self.add_text("Page failed to load...") self.add_newline() self.add_newline() self.add_text("2 points to Slytherin!") self.add_newline() self.add_newline() if self.ee is None: self.add_text("UNKNOWN ERROR") elif type(self.ee) == str: self.add_wrapped_text(self.ee) else: self.add_wrapped_text(str(self.ee)) self.add_newline() self.add_wrapped_text(self.trace)
def generate_content(self): extra = "" name = self.name from page import greetings greeting = greetings.random() if "Rafael" in name: if random()<0.6: greeting = "Muy Feo" add_points("Gryffindor",-1) extra = "\n\n-1 points to Gryffindor!" if random() < 0.01: name = "Jigsaw" add_points("Slytherin",10) extra = "\n\n10 points to Slytherin!" if random() < 0.01: name = "Fake Belgin" add_points("Squiberin",10) extra = "\n\n10 points to Squiberin!" extra += "\n\n"+self.extra self.content = colour_print(printer.text_to_ascii(greeting)) self.content += "\n\n" if self.large: self.content += colour_print(printer.text_to_ascii(name + "!")) else: self.content += name self.content += extra
def play_a_hand(board, forced_hands = [], forced_hand_positions = [], prevent_firstround_callers = [], prevent_secondround_callers = [], enable_alone = True, only_accept_alone = False, pass_condition = None): # does all of the setup for one hand setup(board, forced_hands, forced_hand_positions, prevent_firstround_callers, prevent_secondround_callers, enable_alone) if pass_condition is not None: if pass_condition(board): board.trump_suit = 'pass' return if board.trump_suit == 'null': return # happens if no one calls it # allow this option if only_accept_alone: if not board.going_alone: return # play 5 tricks for i in range(5): play_a_trick(board) # add points points.add_points(board) if board.show_each_turn: print(board.hand_result.capitalize())
def background(self): import os files = ["points", "events", "emails"] if config.NAME == "KLBFAX" and config.MAIN == True: from points import add_points os.system( "scp mscroggs:~/.klb/points /home/pi/.klbtemp/points > /dev/null 2>&1" ) with open("/home/pi/.klbtemp/points") as f: for line in f: lsp = line.strip("\n").split(",") add_points(lsp[0], int(lsp[1]), lsp[2]) with open("/home/pi/.klbtemp/points", "w") as f: pass os.system( "scp /home/pi/.klbtemp/points mscroggs:~/.klb/points > /dev/null 2>&1" ) for f in files: os.system("scp /home/pi/.klb/" + f + " mscroggs:~/.klbdump/" + f + " > /dev/null 2>&1") else: for f in files: os.system("scp mscroggs:~/.klbdump/" + f + " /home/pi/.klb/" + f + " > /dev/null 2>&1")
def flat_path(path, tlr=0.5): result = [[] + path[0]] start = [] + path[0] for point in path[1]: if len(point) == 2: result.append([] + point) start = [] + point else: p0 = sub_points(point[0], start) p1 = sub_points(point[1], start) p2 = sub_points(point[2], start) points = _flat_segment([0.0, 0.0], p0, p1, p2, tlr) for item in points: p = add_points(item, start) result.append(p) start = [] + point[2] return [result[0], result[1:], path[2]]
def check_parallel(source, parallel, radius, tolerance=0.01): """ This function checks, if two bezier segments are "sufficiently" parallel. It checks, if the points for the parameters 0.25, 0.5 and 0.75 of the tested segment are orthogonal to the resp. points of the source segment. 1% tolerance is default. It does not check the start and endpoints, since they are assumed to be correct by construction. """ for t0 in [0.25, 0.5, 0.75]: s = subdivide_seg(source, t0) t = subdivide_seg(parallel, t0) ccenter = mult_point(normalize(sub_points(s[4], s[3])), radius) orig = add_points(s[3], [ccenter[1], -ccenter[0]]) if length(sub_points(orig, t[3])) >= tolerance * radius: return False return True
def get_cap_segment(startpoint, endpoint, captype): """ This returns a list of bezier segments that form the end cap of a line. Valid captypes are: CAP_BUTT, CAP_ROUND, CAP_SQUARE """ # =====| if captype == sk2const.CAP_BUTT: return [startpoint, endpoint] # =====) elif captype == sk2const.CAP_ROUND: f = CIRCLE_CONSTANT d = mult_point(sub_points(endpoint, startpoint), 0.5) o = [d[1], -d[0]] new_p1 = add_points(startpoint, o) new_p2 = mult_point(o, f) return [ startpoint, add_points(startpoint, new_p2), add_points(new_p1, mult_point(d, 1 - f)), add_points(new_p1, d), add_points(new_p1, mult_point(d, 1 + f)), add_points(endpoint, new_p2), endpoint ] # =====] elif captype == sk2const.CAP_SQUARE: d = mult_point(sub_points(endpoint, startpoint), 0.5) o = [d[1], -d[0]] new_p1 = add_points(startpoint, o) new_p2 = add_points(endpoint, o) return [ startpoint, startpoint, new_p1, new_p1, new_p1, new_p2, new_p2, new_p2, endpoint, endpoint ] else: raise 'Unknown captype %d' % captype
def split_seg(self, base_point, point, t=0.5): if is_bezier(point): p0 = base_point p1, p2, p3 = point[:3] t2 = 1.0 - t r = add_points(mult_point(p1, t2) , mult_point(p2, t)) q1 = add_points(mult_point(p0, t2), mult_point(p1, t)) q2 = add_points(mult_point(q1, t2), mult_point(r, t)) q5 = add_points(mult_point(p2, t2), mult_point(p3, t)) q4 = add_points(mult_point(r, t2), mult_point(q5, t)) q3 = add_points(mult_point(q2, t2), mult_point(q4, t)) return [[q1, q2, [] + q3, 0], q3, [q4, q5, [] + p3, 0]] else: new_point = add_points(mult_point(base_point, (1.0 - t)), mult_point(point, t)) return [new_point, [] + new_point, None]
def split_seg(self, base_point, point, t=0.5): if is_bezier(point): p0 = base_point p1, p2, p3 = point[:3] t2 = 1.0 - t r = add_points(mult_point(p1, t2), mult_point(p2, t)) q1 = add_points(mult_point(p0, t2), mult_point(p1, t)) q2 = add_points(mult_point(q1, t2), mult_point(r, t)) q5 = add_points(mult_point(p2, t2), mult_point(p3, t)) q4 = add_points(mult_point(r, t2), mult_point(q5, t)) q3 = add_points(mult_point(q2, t2), mult_point(q4, t)) return [[q1, q2, [] + q3, 0], q3, [q4, q5, [] + p3, 0]] else: new_point = add_points(mult_point(base_point, (1.0 - t)), mult_point(point, t)) return [new_point, [] + new_point, None]
def flat_path(path, tlr=0.5): result = [] result.append([] + path[0]) start = [] + path[0] for point in path[1]: if len(point) == 2: result.append([] + point) start = [] + point else: p0 = sub_points(point[0], start) p1 = sub_points(point[1], start) p2 = sub_points(point[2], start) points = _flat_segment([0.0, 0.0], p0, p1, p2, tlr) for item in points: p = add_points(item, start) result.append(p) start = [] + point[2] return [result[0], result[1:], path[2]]
def subdivide_seg(seg, t=0.5): """ This subdivides a bezier segment at the (optional) Parameter t """ assert len(seg) == 4 t2 = 1.0 - t p01 = add_points(mult_point(seg[0], t2) , mult_point(seg[1], t)) p12 = add_points(mult_point(seg[1], t2), mult_point(seg[2], t)) p23 = add_points(mult_point(seg[2], t2), mult_point(seg[3], t)) p012 = add_points(mult_point(p01, t2), mult_point(p12, t)) p123 = add_points(mult_point(p12, t2), mult_point(p23, t)) p0123 = add_points(mult_point(p012, t2), mult_point(p123, t)) return (seg[0], p01, p012, p0123, p123, p23, seg[3])
def subdivide_seg(seg, t=0.5): """ This subdivides a bezier segment at the (optional) Parameter t """ assert len(seg) == 4 t2 = 1.0 - t p01 = add_points(mult_point(seg[0], t2), mult_point(seg[1], t)) p12 = add_points(mult_point(seg[1], t2), mult_point(seg[2], t)) p23 = add_points(mult_point(seg[2], t2), mult_point(seg[3], t)) p012 = add_points(mult_point(p01, t2), mult_point(p12, t)) p123 = add_points(mult_point(p12, t2), mult_point(p23, t)) p0123 = add_points(mult_point(p012, t2), mult_point(p123, t)) return seg[0], p01, p012, p0123, p123, p23, seg[3]
def split_bezier_curve(start_point, end_point, t=0.5): p0 = [] + start_point if len(start_point) > 2: p0 = [] + start_point[2] p1, p2, p3, flag = deepcopy(end_point) p0_1 = add_points(mult_point(p0, (1.0 - t)), mult_point(p1, t)) p1_2 = add_points(mult_point(p1, (1.0 - t)), mult_point(p2, t)) p2_3 = add_points(mult_point(p2, (1.0 - t)), mult_point(p3, t)) p01_12 = add_points(mult_point(p0_1, (1.0 - t)), mult_point(p1_2, t)) p12_23 = add_points(mult_point(p1_2, (1.0 - t)), mult_point(p2_3, t)) p0112_1223 = add_points(mult_point(p01_12, (1.0 - t)), mult_point(p12_23, t)) new_point = [p0_1, p01_12, p0112_1223, flag] new_end_point = [p12_23, p2_3, p3, flag] return new_point, new_end_point
def get_cap_segment (startpoint, endpoint, captype): """ This returns a list of bezier segments that form the end cap of a line. Valid captypes are: CAP_BUTT, CAP_ROUND, CAP_SQUARE """ # =====| if captype == sk2_const.CAP_BUTT: return [startpoint, endpoint] # =====) elif captype == sk2_const.CAP_ROUND: f = CIRCLE_CONSTANT d = mult_point(sub_points(endpoint, startpoint), 0.5) o = [d[1], -d[0]] new_p1 = add_points(startpoint, o) new_p2 = mult_point(o, f) return [startpoint, add_points(startpoint, new_p2), add_points(new_p1, mult_point(d, 1 - f)), add_points(new_p1, d), add_points(new_p1, mult_point(d, 1 + f)), add_points(endpoint, new_p2), endpoint] # =====] elif captype == sk2_const.CAP_SQUARE: d = mult_point(sub_points(endpoint, startpoint), 0.5) o = [d[1], -d[0]] new_p1 = add_points(startpoint, o) new_p2 = add_points(endpoint, o) return [startpoint, startpoint, new_p1, new_p1, new_p1, new_p2, new_p2, new_p2, endpoint, endpoint] else: raise "Unknown captype %d" % captype
def split_bezier_curve(start_point, end_point, t=0.5): p0 = start_point[2] if len(start_point) > 2 else start_point p1, p2, p3 = end_point[:3] flag = end_point[3] if len(end_point) == 4 else sk2const.NODE_CUSP p0_1 = add_points(mult_point(p0, (1.0 - t)), mult_point(p1, t)) p1_2 = add_points(mult_point(p1, (1.0 - t)), mult_point(p2, t)) p2_3 = add_points(mult_point(p2, (1.0 - t)), mult_point(p3, t)) p01_12 = add_points(mult_point(p0_1, (1.0 - t)), mult_point(p1_2, t)) p12_23 = add_points(mult_point(p1_2, (1.0 - t)), mult_point(p2_3, t)) p0112_1223 = add_points(mult_point(p01_12, (1.0 - t)), mult_point(p12_23, t)) new_point = [p0_1, p01_12, p0112_1223, flag] new_end_point = [p12_23, p2_3, p3, flag] return new_point, new_end_point
def generate_content(self): letters = f_read("emails") if not os.getenv('SLAVE'): import gmail details = f_readlines("gmail") g = gmail.login(details[0],details[1]) unread = g.inbox().mail(unread=True) for mail in unread: mail.fetch() lines = "".join(mail.body.split("\r")).split("\n") if lines[0] == "EVENT" and "*****@*****.**" in mail.fr: try: with open(join(expanduser("~"),'.klb/events'),'a') as f: for line in lines: if line!="EVENT": f.write(line+"\n") mail.read() except: pass elif lines[0] == "CARD" and "*****@*****.**" in mail.fr: with open('/home/pi/cards/'+lines[1],"w") as f: f.write("\n".join(lines[2:])) mail.read() elif "POINTS" in lines[0].upper() and "*****@*****.**" in mail.fr: from points import add_points length = 1 points_to_give = 0 while length<=len(lines[2]): try: if lines[2][:length]!="-": points_to_give = int(lines[2][:length]) length += 1 except: break add_points(lines[1].split("=")[0],points_to_give) mail.read() else: newletter_col = choice(self.colours.Background.non_boring) newletter = "" for line in lines: if line!="": while len(line)>79: newletter += newletter_col+line[:79]+"\n" line=line[79:] newletter+=newletter_col+line+"\n" letters=newletter+"\n"+newletter_col+self.colours.Foreground.BLACK+"from "+mail.fr+self.colours.Foreground.DEFAULT+self.colours.Background.DEFAULT+"\n\n"+letters mail.read() letters = letters.split("\n") if len(letters)>1000: letters = letters[:1000] with open(join(expanduser("~"),".klb/emails"),"w") as f: f.write("\n".join(letters)) else: letters = letters.split("\n") letters = letters[20*(self.n-1):20*self.n] letters = "\n".join(letters) letters = unicode(letters,'latin1') page = self.colours.colour_print(printer.text_to_ascii("Have your say "+str(self.n)+"/21",vertical_condense=True)) page += "\n\n" page += letters page += self.colours.Foreground.DEFAULT page += self.colours.Background.DEFAULT page += "\n\n" if self.n==21: page += "~ END OF LETTERS ~" else: page += "The letters continue on page "+str(200+self.n) self.content = page
def generate_content(self): from points import add_points add_points("Slytherin", 2)
def get_join_segment(startpoint, endpoint, radius, jointype, miter_limit=MITER_LIMIT): """ This returns a list of bezier segments that joins two points with a given radius (fails if the radius is smaller than the distance between startpoint) and endpoint). jointype is one of JOIN_MITER, JOIN_ROUND, JOIN_BEVEL """ if jointype == sk2const.JOIN_MITER: d = mult_point(sub_points(endpoint, startpoint), 0.5) if d == [0, 0]: return [] o = normalize([d[1], -d[0]]) if radius < length(d): return [startpoint, endpoint] h = math.sqrt(radius**2 - length(d)**2) h2 = length(d)**2 / h if h2 + h > miter_limit * radius: # Hit miter limit return [startpoint, endpoint] edge = add_points(add_points(startpoint, d), mult_point(o, h2)) new_seg1 = line_to_curve(startpoint, edge) new_seg2 = line_to_curve(edge, endpoint) return [ startpoint, ] + new_seg1 + new_seg2 elif jointype == sk2const.JOIN_ROUND: f = CIRCLE_CONSTANT d = mult_point(sub_points(endpoint, startpoint), 0.5) if d == [0, 0]: return [] o = mult_point(normalize([d[1], -d[0]]), radius) if radius < length(d): return [startpoint, endpoint] h = math.sqrt(radius**2 - length(d)**2) / radius center = sub_points(add_points(startpoint, d), mult_point(o, h)) d = mult_point(normalize(d), radius) t0 = circleparam(h) quadseg = [ sub_points(center, d), add_points(sub_points(center, d), mult_point(o, f)), add_points(sub_points(center, mult_point(d, f)), o), add_points(center, o) ] ret = [startpoint] + list(subdivide_seg(quadseg, t0)[4:]) quadseg = [ add_points(center, o), add_points(add_points(center, o), mult_point(d, f)), add_points(add_points(center, d), mult_point(o, f)), add_points(center, d) ] ret = ret + list(subdivide_seg(quadseg, 1 - t0)[1:3]) + [endpoint] return ret elif jointype == sk2const.JOIN_BEVEL: return [startpoint, endpoint] else: raise "Unknown join type %d" % jointype
from os.path import expanduser, join, isdir from os import mkdir import log_setup from random import choice from points import add_points import Keyboard import weather if not isdir(join(expanduser('~'), '.klb')): mkdir(join(expanduser('~'), '.klb')) if not os.getenv("SLAVE"): house = choice(["Ravenclaw", "Gryffindor", "Slytherin", "Hufflepuff", "Squib", "Durmstrang"]) add_points(house, 1) if house == "Hufflepuff": print("1 point to "+house+"! GO PUFFS!") else: print("1 point to "+house+"!") log_setup.read_from_file() Keyboard.start_keyboard_thread() Keyboard.subscribe(ceefax.name_page_handler) weather_thread = weather.weatherThread() weather_thread.start() while True:
def get_join_segment(startpoint, endpoint, radius, jointype, miter_limit=MITER_LIMIT): """ This returns a list of bezier segments that joins two points with a given radius (fails if the radius is smaller than the distance between startpoint) and endpoint). jointype is one of JOIN_MITER, JOIN_ROUND, JOIN_BEVEL """ if jointype == sk2_const.JOIN_MITER: d = mult_point(sub_points(endpoint, startpoint), 0.5) if d == [0, 0]: return [] o = normalize([d[1], -d[0]]) h = math.sqrt(radius ** 2 - length(d) ** 2) h2 = length(d) ** 2 / h if h2 + h > miter_limit * radius: # Hit miter limit return [startpoint, endpoint] edge = add_points(add_points(startpoint, d), mult_point(o, h2)) new_seg1 = line_to_curve(startpoint, edge) new_seg2 = line_to_curve(edge, endpoint) return [startpoint, ] + new_seg1 + new_seg2 elif jointype == sk2_const.JOIN_ROUND: f = CIRCLE_CONSTANT d = mult_point(sub_points(endpoint, startpoint), 0.5) if d == [0, 0]: return [] o = mult_point(normalize([d[1], -d[0]]), radius) h = math.sqrt(radius ** 2 - length(d) ** 2) / radius center = sub_points(add_points(startpoint, d), mult_point(o, h)) d = mult_point(normalize(d), radius) t0 = circleparam(h) quadseg = [sub_points(center, d), add_points(sub_points(center, d), mult_point(o, f)), add_points(sub_points(center, mult_point(d, f)), o), add_points(center, o)] ret = [startpoint] + list (subdivide_seg(quadseg, t0)[4:]) quadseg = [add_points(center, o), add_points(add_points(center, o), mult_point(d, f)), add_points(add_points(center, d), mult_point(o, f)), add_points(center, d)] ret = ret + list (subdivide_seg(quadseg, 1 - t0)[1:3]) + [endpoint] return ret elif jointype == sk2_const.JOIN_BEVEL: return [startpoint, endpoint] else: raise "Unknown join type %d" % jointype