--- /dev/null
+import os, time, math
+
+ORIGIN = 294, 9
+
+def main():
+ callxdo("search flickgame\.org.* windowactivate")
+ settitle("Mushroom Train")
+ clickcolor(14)
+ fillpoint(200, 200)
+ left = 40
+ top = 20
+ for color in xrange(7, 13):
+ clickcolor(color)
+ drawtitle(left, top)
+ left += 1
+ top += 1
+ for ii, offset in enumerate(xrange(0, 60, 20)):
+ activateframe(ii)
+ clickcolor(14)
+ fillpoint(200, 200)
+ drawtrain()
+ drawmushroom(offset)
+ setbranches(ii + 2)
+ activateframe(3)
+ clickcolor(14)
+ fillpoint(200, 200)
+ drawtrain()
+ setbranch(0, 5)
+ setbranch(3, 5)
+ setbranch(15, 5)
+ activateframe(4)
+ clickcolor(13)
+ fillpoint(200, 200)
+ clickcolor(14)
+ drawparty(20, 20)
+ # for ii in xrange(16):
+ # activateframe(ii)
+ # fillpoint(200, 200, ii)
+ # if ii == 16:
+ # setbranch(ii, 1)
+ # else:
+ # setbranch(ii, ii + 2)
+ save("mushroom")
+ time.sleep(1)
+ openflick("mushroom")
+ time.sleep(4)
+ clickx = 700
+ clicky = 550
+ callxdo("mousemove %i %i" % (clickx, clicky))
+ time.sleep(2)
+ callxdo("click 1")
+ for _ in xrange(2):
+ time.sleep(1)
+ callxdo("mousemove_relative 10 0")
+ time.sleep(1)
+ callxdo("click 1")
+ time.sleep(1)
+ callxdo("mousemove_relative 250 0")
+ time.sleep(1)
+ callxdo("click 1")
+
+def setbranches(index):
+ setbranch(0, index)
+ setbranch(4, index)
+ setbranch(6, index)
+ setbranch(15, index)
+
+def drawmushroom(offset):
+ clickcolor(4)
+ drawrectangle(200 + offset, 300, 100, 40)
+ clickcolor(6)
+ drawhalfcircle(250 + offset, 300, 110)
+ fillpoint(250 + offset, 300 - 20, True)
+ clickbrush(2)
+ clickcolor(15)
+ clickpoint(180 + offset, 280, canvas=True)
+ clickpoint(280 + offset, 240, canvas=True)
+ clickbrush(5)
+ clickpoint(200 + offset, 230, canvas=True)
+ clickpoint(310 + offset, 280, canvas=True)
+ clickbrush(2)
+ clickcolor(0)
+ clickpoint(215 + offset, 322, canvas=True)
+ clickpoint(285 + offset, 322, canvas=True)
+ drawrectangle(240 + offset, 328, 20, 6)
+
+def drawtrain():
+ clickbrush(1)
+ clickcolor(3)
+ drawrectangle(420, 260, 180, 75)
+ clickbrush(0)
+ clickcolor(15)
+ for x in xrange(430, 430 + 180, 37):
+ drawrectangle(x, 270, 14, 40, False)
+ clickbrush(3)
+ clickcolor(0)
+ clickpoint(440, 350, canvas=True)
+ clickpoint(580, 350, canvas=True)
+
+def drawhalfcircle(x, y, r):
+ clickbrush(2)
+ drawline((x - r, y), (x + r, y))
+ for angle in range(0, 90, 5) + range(270, 360, 5):
+ end = getendpoint((x, y), angle, r)
+ clickpoint(end[0], end[1], canvas=True)
+
+def getendpoint(start, angle, magnitude, translate_angle=True):
+ """clockwise, 0 is up"""
+ x0, y0 = start
+ dx, dy = getdelta(angle, magnitude, translate_angle)
+ return x0 + dx, y0 + dy
+
+def getdelta(angle, magnitude, translate_angle=True):
+ if translate_angle:
+ angle = math.radians(angle)
+ return math.sin(angle) * magnitude, -math.cos(angle) * magnitude
+
+def drawrectangle(left, top, width, height, fill=True):
+ clickbrush(0)
+ drawline((left, top), (left + width, top))
+ drawline((left + width, top), (left + width, top + height))
+ drawline((left, top + height), (left + width, top + height))
+ drawline((left, top), (left, top + height))
+ time.sleep(.2)
+ if fill:
+ fillpoint(left + (width / 2), top + (height / 2), True)
+
+def drawparty(left, top):
+ height = 400
+ width = 100
+ clickbrush(4)
+ drawline((left, top), (left, top + height))
+ drawline((left, top), (left + 100, top))
+ drawline((left + width, top), (left + width, top + height / 2))
+ drawline((left, top + height / 2), (left + width, top + height / 2))
+ left += 125
+ drawline((left, top), (left, top + height))
+ drawline((left, top), (left + width, top))
+ drawline((left + width, top), (left + width, top + height))
+ drawline((left, top + height / 2), (left + width, top + height / 2))
+ left += 125
+ drawline((left, top), (left, top + height))
+ drawline((left, top), (left + width, top))
+ drawline((left + width, top), (left + width, top + height / 2))
+ drawline((left, top + height / 2), (left + width, top + height / 2))
+ drawline((left, top + height / 2), (left + width, top + height))
+ left += 125
+ drawline((left, top), (left + width, top))
+ drawline((left + width / 2, top), (left + width / 2, top + height))
+ left += 125
+ drawline((left, top), (left + width / 2, top + height / 2))
+ drawline((left + width, top), (left + width / 2, top + height / 2))
+ drawline((left + width / 2, top + height / 2), (left + width / 2, top + height))
+
+def drawtitle(left, top):
+ height = 100
+ clickbrush(0)
+ drawm(left, top, height, 30)
+ drawline((left + 40, top), (left + 40, top + height))
+ drawline((left + 40, top + height), (left + 55, top + height))
+ drawline((left + 55, top), (left + 55, top + height))
+ drawline((left + 65, top), (left + 65, top + height / 2))
+ drawline((left + 65, top), (left + 85, top))
+ drawline((left + 65, top + height / 2), (left + 85, top + height / 2))
+ drawline((left + 85, top + height / 2), (left + 85, top + height))
+ drawline((left + 65, top + height), (left + 85, top + height))
+ drawline((left + 95, top), (left + 95, top + height))
+ drawline((left + 95, top + height / 2), (left + 115, top + height / 2))
+ drawline((left + 115, top), (left + 115, top + height))
+ drawline((left + 125, top), (left + 125, top + height))
+ drawline((left + 125, top), (left + 145, top))
+ drawline((left + 145, top), (left + 145, top + height / 2))
+ drawline((left + 125, top + height / 2), (left + 145, top + height / 2))
+ drawline((left + 125, top + height / 2), (left + 145, top + height))
+ drawo(left + 155, top, height)
+ drawo(left + 185, top, height)
+ drawm(left + 215, top, height, 30)
+
+def drawo(left, top, height):
+ drawline((left, top), (left + 20, top))
+ drawline((left, top), (left, top + height))
+ drawline((left + 20, top + height), (left, top + height))
+ drawline((left + 20, top + height), (left + 20, top))
+
+def drawm(left, top, height, offset):
+ drawline((left, top), (left, top + height))
+ drawline((left, top), (left + offset, top))
+ drawline((left + offset, top), (left + offset, top + height))
+ drawline((left + offset / 2, top), (left + offset / 2, top + height))
+
+def drawline(start, end):
+ gotopoint(start[0], start[1], True)
+ callxdo("mousedown 1")
+ gotopoint(end[0], end[1], True)
+ callxdo("mouseup 1")
+ time.sleep(.2)
+
+def clickbrush(index):
+ clickpoint(765, [386, 348, 307, 270, 233, 195, 156, 119][index])
+
+def save(name):
+ clickpoint(771, 39)
+ time.sleep(1)
+ typeword(name)
+ hitkey("Return", 2, 500)
+
+def openflick(name):
+ hitkey("ctrl+t")
+ time.sleep(1)
+ hitkey("F11")
+ time.sleep(1)
+ hitkey("ctrl+l")
+ time.sleep(1)
+ typeword("file:///home/frank/projects/public/games/mt/%s.html" % name)
+ hitkey("Return")
+ time.sleep(1)
+ hitkey("F11")
+
+def hitkey(name, repeat=1, delay=0):
+ callxdo("key --repeat %i --repeat-delay %i %s" % (repeat, delay, name))
+
+def settitle(title):
+ clickpoint(533, 26, 3)
+ hitkey("BackSpace")
+ typeword(title)
+
+def typeword(word):
+ for char in word:
+ if char == " ":
+ hitkey("space")
+ elif char == ":":
+ hitkey("colon")
+ elif char == "/":
+ hitkey("slash")
+ elif char == ".":
+ hitkey("period")
+ else:
+ hitkey(char)
+
+def clickpoint(x, y, repeat=1, canvas=False):
+ gotopoint(x, y, canvas)
+ callxdo("click --repeat %i 1" % repeat)
+
+def clickcolor(index):
+ clickpoint(135 + index * 38, 476)
+
+def setbranch(color, index):
+ clickpoint(135 + color * 38, 497)
+ # callxdo("key %s" % keystokeysequence(str(index)))
+ callxdo("key --repeat 16 Up")
+ callxdo("key --repeat %i Down" % index)
+ clickpoint(0, 0)
+
+def keystokeysequence(keys):
+ sequence = ""
+ for char in keys:
+ sequence += char + "+"
+ return sequence
+
+def fillpoint(x, y, canvas=False):
+ clickpoint(766, 421)
+ clickpoint(x, y, canvas=canvas)
+
+def activateframe(index):
+ clickpoint(19, 58 + index * 27)
+
+def gotopoint(x, y, canvas=False):
+ ax = ORIGIN[0] + x
+ ay = ORIGIN[1] + y
+ if canvas:
+ ax += 98
+ ay += 52
+ callxdo("mousemove %i %i" % (ax, ay))
+
+def callxdo(command):
+ os.system("xdotool %s" % command)
+
+if __name__ == "__main__":
+ main()