def lineCommand(points, arrow, solid, noisy=False): if noisy: attributes = [ "line width = %.2fcm" % (0.1 + truncatedNormal(-1, 1) * 0.04) ] else: attributes = ["line width = 0.1cm"] if arrow: scale = 1.5 if noisy: scale = 1.2 + random() * (1.5 - 1.2) * 1.2 scale = round(scale, 1) differentStyles = [ "-{>[scale = %f]}", "-{Stealth[scale = %f]}", "-{Latex[scale = %f]}" ] if noisy: style = choice(differentStyles) else: style = differentStyles[0] attributes.append(style % (scale)) if not solid: if not noisy: attributes += ["dashed"] else: attributes += [ "dash pattern = on %dpt off %dpt" % (choice(range(5)) + 2, choice(range(5)) + 2) ] if noisy: attributes += ["pencildraw"] a = ",".join(attributes) return "\\draw [%s] %s;" % (a, " -- ".join(map(str, points)))
def command(center, radius, noisy=False): noisy = "pencildraw," if noisy else "" radius = float(radius) lw = "line width = 0.1cm" if noisy: lw = "line width = %.2fcm" % (0.1 + truncatedNormal(-1, 1) * 0.03) return "\\node[draw,%scircle,inner sep=0pt,minimum size = %.2fcm,%s] at %s {};" % ( noisy, radius * 2, lw, center)
def noisyEvaluate(self): # short lines should have less noise added to their offsets if self.length() < 3: n = COORDINATENOISE setCoordinateNoise(n * self.length() / 4.0 * COORDINATENOISE) # 60% of the noise is applied equally to each coordinate # 40% of the noise is per coordinate setCoordinateNoise(0.4 * COORDINATENOISE) points = [p.noisyEvaluate() for p in self.points] setCoordinateNoise(COORDINATENOISE / 0.4) dx = truncatedNormal(-1, 1) * COORDINATENOISE * 0.6 dy = truncatedNormal(-1, 1) * COORDINATENOISE * 0.6 points = [str((x + dx, y + dy)) for (x, y) in points] e = [Line.lineCommand(points, self.arrow, self.solid, noisy=True)] if self.length() < 3: setCoordinateNoise(n) return e
def noisyLineCommand(p1, p2, p3, p4, noisy=True): attributes = ["line width = 0.1cm"] if noisy: attributes = [ "line width = %.2fcm" % (0.1 + truncatedNormal(-1, 1) * 0.04) ] if noisy: attributes += ["pencildraw"] attributes = ",".join(attributes) return "\\draw [%s] %s -- %s -- %s -- %s -- cycle;" % (attributes, p1, p2, p3, p4)
def command(p1, p2, noisy=False): attributes = ["line width = 0.1cm"] if noisy: attributes = [ "line width = %.2fcm" % (0.1 + truncatedNormal(-1, 1) * 0.04) ] if noisy: attributes += ["pencildraw"] attributes = ",".join(attributes) (x1, y1) = p1 (x2, y2) = p2 p1 = "(%.2f,%.2f)" % (x1, y1) p2 = "(%.2f,%.2f)" % (x1, y2) p3 = "(%.2f,%.2f)" % (x2, y2) return "\\draw [%s] %s -- %s -- %s-- cycle;" % (attributes, p1, p2, p3)
def noisyEvaluate(self): r = self.radius + truncatedNormal(-1, 1) * RADIUSNOISE return [Circle.command(self.center.noisyEvaluate(), r, noisy=True)]
def vertexNoise(): return truncatedNormal(-1, 1) * COORDINATENOISE * 0.3
def centerNoise(): return truncatedNormal(-1, 1) * COORDINATENOISE * 0.7
def noisyEvaluate(self): return (self.x + truncatedNormal(-1, 1) * COORDINATENOISE, self.y + truncatedNormal(-1, 1) * COORDINATENOISE)