# This design tries to emphasize the accelerating # movement toward the viewer. The curves make an # impression of swinging forward from the 100 x 100 # view up to the 200 x 200 view. import math def sqr(x): return x*x def mod(num, den): return (num-int(num/den)*den) objectTag = 123 pointTag = 234 pixelTag = 345 bitmapTag = 456 def makeObject(newTag): data = [] data.append(objectTag) data.append(newTag) return data def checkObject(object): if object[0] != objectTag: print "error: not an object" def getObjectTag(object): checkObject(object) return object[1] def makePoint(x, y): data = [] data.append(makeObject(pointTag)) data.append(x) data.append(y) return data def checkPoint(p): if getObjectTag(p[0]) != pointTag: print "error: not a point" def getPointX(p): checkPoint(p) return p[1] def getPointY(p): checkPoint(p) return p[2] def makePixel(color): data = [] data.append(makeObject(pixelTag)) data.append(color) return data def checkPixel(pix): if getObjectTag(pix[0]) != pixelTag: print "error: not a pixel" def getPixelColor(pix): checkPixel(pix) return pix[1] def makeBitmap(width, height, backColor): bm = [] bm.append(makeObject(bitmapTag)) bm.append(int(width)) bm.append(int(height)) for y in range(0, int(height)): for x in range(0, int(width)): bm.append(makePixel(backColor)) return bm def checkBitmap(bm): if getObjectTag(bm[0]) != bitmapTag: print "error: not a bitmap" def getBitmapWidth(bm): checkBitmap(bm) return bm[1] def getBitmapHeight(bm): checkBitmap(bm) return bm[2] def getBitmapPixel(bm, p): checkBitmap(bm) return bm[3+int(getPointY(p))*getBitmapWidth(bm)+int(getPointX(p))] def setBitmapPixel(bm, p, pix): checkBitmap(bm) bm[3+(int(getPointY(p))*getBitmapWidth(bm))+int(getPointX(p))] = pix def drawBitmapOnBitmap(destBm, p, srcBm): for y in range(0, getBitmapWidth(srcBm)): for x in range(0, getBitmapHeight(srcBm)): setBitmapPixel(destBm, makePoint(x+getPointX(p), y+getPointY(p)), getBitmapPixel(srcBm, makePixel(x, y))) def drawPixel(pix, destP): g.setPixel(int(getPointX(destP)), int(getPointY(destP)), int(getPixelColor(pix))) def drawBitmap(bm, destP): for y in range(0, getBitmapHeight(bm)): for x in range(0, getBitmapWidth(bm)): drawPixelField(getBitmapPixel(bm, makePoint(x, y)), makePoint(x+getPointX(destP), y+getPointY(destP))) def drawBitmapSprite(bm, destP, transKey): for y in range(0, getBitmapHeight(bm)): for x in range(0, getBitmapWidth(bm)): pix = getBitmapPixel(bm, makePoint(x, y)) if getPixelColor(pix) != transKey: drawPixel(pix, makePoint(x+getPointX(destP), y+getPointY(destP))) def drawPixelField(pix, p1, p2): g.field(int(getPointX(p1)), int(getPointY(p1)), int(getPointX(p2)), int(getPointY(p2)), int(getPixelColor(pix))) def drawBitmapScaledBig(bm, destP, horizScale, vertScale): for y in range(0, getBitmapHeight(bm)): for x in range(0, getBitmapWidth(bm)): drawPixelField(getBitmapPixel(bm, makePoint(x, y)), makePoint((x*horizScale)+getPointX(destP), (y*vertScale)+getPointY(destP)), makePoint((x*horizScale)+getPointX(destP)+horizScale, (y*vertScale)+getPointY(destP)+vertScale)) def drawBitmapScaledSmall(bm, destP, horizScale, vertScale): for y in range(0, getBitmapHeight(bm)): for x in range(0, getBitmapWidth(bm)): drawPixelField(getBitmapPixel(bm, makePoint(x, y)), makePoint((x*horizScale)+getPointX(destP), (y*vertScale)+getPointY(destP)), makePoint((x*horizScale)+getPointX(destP)+horizScale, (y*vertScale)+getPointY(destP)+vertScale)) def drawBitmapScaled(bm, destP, horizScale, vertScale): if horizScale+vertScale > 2: drawBitmapScaledBig(bm, destP, horizScale, vertScale) else: drawBitmapScaledSmall(bm, destP, horizScale, vertScale) def drawBitmapSpriteScaledSmall(bm, destP, transKey, horizScale, vertScale): oxi = -1 oyi = -1 for y in range(0, getBitmapHeight(bm)): for x in range(0, getBitmapWidth(bm)): pix = getBitmapPixel(bm, makePoint(x, y)) if getPixelColor(pix) != transKey: xi = x * horizScale yi = y * vertScale if oxi != xi or oyi != yi: drawPixel(getBitmapPixel(bm, makePoint(x, y)), makePoint(xi+getPointX(destP), yi+getPointY(destP))) oxi = xi*horizScale oyi = yi*vertScale def drawBitmapSpriteScaledBig(bm, destP, transKey, horizScale, vertScale): for y in range(0, getBitmapHeight(bm)): for x in range(0, getBitmapWidth(bm)): pix = getBitmapPixel(bm, makePoint(x, y)) if getPixelColor(pix) != transKey: drawPixelField(getBitmapPixel(bm, makePoint(x, y)), makePoint((x*horizScale)+getPointX(destP), (y*vertScale)+getPointY(destP)), makePoint((x*horizScale)+getPointX(destP)+horizScale, (y*vertScale)+getPointY(destP)+vertScale)) def drawBitmapSpriteScaled(bm, destP, transKey, horizScale, vertScale): if horizScale+vertScale > 2: drawBitmapSpriteScaledBig(bm, destP, transKey, horizScale, vertScale) else: drawBitmapSpriteScaledSmall(bm, destP, transKey, horizScale, vertScale) maxT = 45.0 xRes = 20.0 yRes = 20.0 def funcX(t): i = t*1.0/maxT return sqr(sqr(1.0-i))*50.0 def funcY(t): i = t*1.0/maxT return sqr(1.0-i)*100.0 def funcXS(t): i = t*1.0/maxT return (100.0+i*100.0)/xRes def funcYS(t): i = t*1.0/maxT return (100.0+i*100.0)/yRes bitmap = makeBitmap(xRes, yRes, -1) for y in range(0, int(yRes)): for x in range(0, int(xRes)): if mod(x*x+y*y,13) == 0 and sqr(xRes/2-x)+sqr(yRes/2-y) < sqr((xRes+yRes)/4): setBitmapPixel(bitmap, makePoint(x, y), makePixel(100.0*(x/xRes+y/yRes*y/yRes))) for t in range(0, int(maxT+1)): drawBitmapSpriteScaled(bitmap, makePoint(funcX(t), funcY(t)), -1, funcXS(t), funcYS(t))