#curved strokes of two paintbrushes paint a black circle of varying #size, depending on current percentage (25, 50, 75, or 100). #White and black brushes are used. import math brushDim = 12 brush = [] def sqr(val): return (val * val) SEED = 343545 def nextRand(val): return (val*3 + 234955457) % 12345676 def random(seedValue, maxVal): return (seedValue % maxVal) def drawBrush(offx, offy, solidColor): for y in range(0, brushDim): for x in range(0, brushDim): if brush[y][x] != 0: if solidColor == -1: g.pen(brush[y][x]) else: g.pen(solidColor) g.setPixel(int(offx+x), int(offy+y), brush[y][x]) def drawBrushLine(offx1, offy1, offx2, offy2, solidColor): if offx1 > offx2: temp = offx1 offx1 = offx2 offx2 = temp temp = offy1 offy1 = offy2 offy2 = temp S = 123 yList = range(0, brushDim) if offy1 > offy2: yList.reverse() for y in yList: for x in range(0, brushDim): if brush[y][x] != 0: if solidColor == -1: g.pen(brush[y][x]) else: g.pen(solidColor) g.line(int(offx1+x), int(offy1+y), int(offx2+x), int(offy2+y)) def drawBrushCurve(x1, y1, x2, y2, x3, y3, solidColor): ax_coeff = (2 * x3) + (2 * x1) - (4 * x2) bx_coeff = (4 * x2) - (3 * x1) - x3 ay_coeff = (2 * y3) + (2 * y1) - (4 * y2) by_coeff = (4 * y2) - (3 * y1) - y3 x = x1 y = y1 curveRes = 8 for it in range(1, curveRes+1): ox = x oy = y t = it * 1.0 / curveRes x = (ax_coeff * sqr(t)) + (bx_coeff * t) + x1 y = (ay_coeff * sqr(t)) + (by_coeff * t) + y1 drawBrushLine(ox, oy, x, y, solidColor) while 1: for frames in range(0, 320): if frames == 0: percentage = 25.0 theRadius = math.sqrt(100.0 * percentage / math.pi) strokeSize = percentage if frames == 80: percentage = 50.0 theRadius = math.sqrt(100.0 * percentage / math.pi) strokeSize = percentage if frames == 160: percentage = 75.0 theRadius = math.sqrt(100.0 * percentage / math.pi) strokeSize = percentage if frames == 240: percentage = 100.0 theRadius = math.sqrt(100.0 * percentage / math.pi) strokeSize = percentage g.field(0,0,int(percentage),5,25) g.field(int(percentage),0,100,5,0) for y in range(0, brushDim): newRow = [] for x in range(0, brushDim): if sqr(x-(brushDim/2)) + sqr(y-(brushDim/2)) <= sqr(brushDim/2): SEED = nextRand(SEED) if random(SEED, 100) <= 25: newRow.append(100) else: newRow.append(0) else: newRow.append(0) brush.append(newRow) okToExit = 0 while okToExit == 0: center = 0 SEED = nextRand(SEED) p1x = random(SEED, 100) SEED = nextRand(SEED) p1y = random(SEED, 100) SEED = nextRand(SEED) p2x = p1x + random(SEED,strokeSize) - (strokeSize/2) SEED = nextRand(SEED) p2y = p1y + random(SEED,strokeSize) - (strokeSize/2) SEED = nextRand(SEED) p3x = p2x + random(SEED,strokeSize) - (strokeSize/2) SEED = nextRand(SEED) p3y = p2y + random(SEED,strokeSize) - (strokeSize/2) SEED = nextRand(SEED) if sqr(p1x - 50) + sqr(p1y - 50) < sqr(theRadius): center = center + 1 else: center = center - 1 if sqr(p2x - 50) + sqr(p2y - 50) < sqr(theRadius): center = center + 1 else: center = center - 1 if sqr(p3x - 50) + sqr(p3y - 50) < sqr(theRadius): center = center + 1 else: center = center - 1 if center >= 3: color = 100 okToExit = 1 if center <= -2: color = 0 okToExit = 1 drawBrushCurve(p1x, p1y, p2x, p2y, p3x, p3y, color)