'''ParadigmShow.py A multi-paradigm presentation. ''' from PMGraphics import drawStringInPMImage, getPMGraphics,\ isValidWindow, updatePMImageNumbers from java.awt import Color W = 800; H = 600 # The image dimensions temp = pmNewImage(0, "Temporary", W, H, 128,128,192) pmMaximizeWindow(temp) drawStringInPMImage("Imperative Programming", wn=0, fontSize=24, y=200, color=(128,0,255)) drawStringInPMImage("is") drawStringInPMImage("pretty basic.") pmMessage("That's imperative programming.", "Do it!", 600,700, 300,100) class slide(object): def __init__(self, title, bg=(225,225,200)): self.title = title self.backgroundColor = Color(bg[0],bg[1],bg[2]) def renderOn(self, wn): self.wn = wn if not isValidWindow(wn): wn = pmNewImage(wn, self.title, W, H, 128,128,128) pmMaximizeWindow(wn) self.wn = wn g = getPMGraphics(wn) g.setColor(self.backgroundColor) g.fillRect(0, 0, W, H) drawStringInPMImage(self.title, y=100, color=(192,0,0)) updatePMImageNumbers(wn) return self.wn a = slide("Object-oriented Programming") mainWin = a.renderOn(0) class fancySlide(slide): def wipeTo(self, temp, wn, n=5): # first render on the temporary slide. self.renderOn(temp) # make sure wn exists if not isValidWindow(wn): pmNewImage(wn, self.title,W, H, 128,128,128) pmSetSource1(temp) pmSetSource2(wn) pmSetDestination(wn) pmHideProgress() pmHideSelections(wn) for i in range(n): bar = W * (i+1) /n pmSetFormula("if x<"+str(bar)+" then s1(x,y) else s2(x,y)") pmSetRectangle(wn, int(W*i/n),0,int(W/n)+1,H) pmCompute() pmSleep(1000/n) pmSetRectangle(wn,0,0,W,H) b = fancySlide("This uses ... Inheritance!",bg=(128,128,100)) b.wipeTo(temp, mainWin, 50) pmMessage("That slide was an object!", "Being objective", 600,700, 300,100) # Now for a recursive function to help generate "content". def funfun(n): if n==1: return 'fun' else: return 'fun '+funfun(n-1) # And a recursive function to handle transition... def zoomzoom(n, sourceSlide, destSlide): if n<0: return else: denom = 1.1**n wd = int(W/denom); hd = int(H/denom) x1 = (W-wd)/2; y1 = (H-hd)/2 pmSetSource1(sourceSlide.wn) pmSetDestination(destSlide.wn) pmSetRectangle(destSlide.wn, x1, y1, wd, hd) pmSetFormula("S1(x,y)") pmCompute() zoomzoom(n-1, sourceSlide, destSlide) c = slide("Functional programming is\n "+funfun(10)) c.renderOn(temp) zoomzoom(25, c, a) pmMessage("End of fun.", "No more fun", 600,700, 300,100) # Finally, functional (callable) objects: class selfTransitioningSlide(fancySlide): def __call__(self, temp, wn): self.wipeTo(temp, wn, 20) sts = selfTransitioningSlide("Callable objects are lovable!") sts(temp,a.wn) # The call.