Creative Ant Farm project report (2002)

818 views

Published on

An experiment in Object-Oriented Lingo programming

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
818
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Creative Ant Farm project report (2002)

  1. 1. CREATIVEANTFARMan experiment in object-oriented lingo programmingSAE London - Multimedia Arts DegreeOctober 2002Module 103 - Basic Multimedia StudiesResearch ProjectObject-Oriented Programming vs. Procedural Progrmmaing in Lingo student name: Amir Dotan student ID: 42480 course code: MAD1001Y
  2. 2. CREATIVEANTFARM an experiment in object-oriented lingo programming 1.0 Introduction 2.0 Research Description 2.1 Research objectives 2.2 Theoretical research 2.3 Practical research – concept and description 2.3.1 Program storyboard 2.3.2 Classes description 3.0 Paradigm shift – stepping into OOP 4.0 OOP vs. Procedural in Lingo – the grid case study 5.0 Conclusions and personal findings 6.0 Resources 7.0 AppendixSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  3. 3. CREATIVEANTFARM an experiment in object-oriented lingo programming 1.0 Introduction Object-oriented is a programming methodology, which became highly accepted and widely used during the course of the last two decades. It offers an efficient approach to minimizing develop- ment time and maximizing code reusability. Among the object-oriented languages one can find C++, Java and Smalltalk to name but a few and leading multimedia-authoring environments such as Macromedia Director and Macromedia Flash make use of the object-oriented paradigm across different levels and facilitate object-oriented scripting to some extent. Before object-oriented was introduced, the methodology used to program was a procedural one which was based mainly on constructing a set of routines to execute a task. That approach posed problems and difficulties, which lead to the creation of the object-oriented paradigm. Today, both methodologies are being practiced and implemented in Lingo (Director) and Action- Script (Flash). Since each one represents an approach, a developer can choose to adopt one ap- proach over the other. The result may be the same in terms of functionality and visual, but very different when it comes to code reusability, program scalability etc. This project sought to examine and evaluate the two paradigms in the context of Lingo program- ming. The importance and significance of the research stretched beyond Lingo and offered an in- troduction to fundamental object-oriented concepts, which stand at the heart of other important programming languages. The project consisted of writing a program in Lingo using the object-oriented paradigm as a means of learning and get familiar with the different concepts and design patterns and this writ- ten report, which will describe the experience of dealing with object-oriented programming and the major differences felt between developing a program using object-oriented and procedural programming.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  4. 4. CREATIVEANTFARM an experiment in object-oriented lingo programming 2.0 Research description The research included a paliminary theoretical study into the concepts of object-oriented thinking followed by a practical development process. Both consumed almost the same amount of time (approximately 3 months each) and proved to be as equaly important and crucial. A great deal of the theorectical research seemd at times obscure and too absract, and once the actual develop- ment started it was referenced a number of times and only then became more understandble. 2.1 Research objectives The main objective of this research project was to get familiar with the object-oriented mindset and how it can be implemented in Lingo. In order to accomplish this goal a program was written in Lingo using the object-oriented paradigm, which served as an important experimental ground. The secondary objective was to examine the difference between the two methodologies being pro- cedural and object-oriented programming and evaluate them in the context of the development process. 2.2 Theoretical research Prior to the practical research an extensive theoretical research was made to try and come to terms with object-oriented concepts such as encapsulation, inheritance, polymorphism and oth- ers. Most of the resources rightfully argued that these concepts are somewhat difficult to visualize and digest without practical practice and since adopting the object-oriented approach demanded a complete paradigm shift, these early stages seemed confusing and at times frustrating. Seeing as how object-oriented is a methodology that isn’t reserved to a one single language, a large part of the resources consisted of material, which had nothing to do with Lingo or Director and that allowed a wider view on the topic from the very beginning. 2.3 Practical research – concept and description The practical aspect of the research was to write a program in Lingo using the object-oriented para- digm. The concept that was chosen to serve as the creative framework of the program was titled “Creative ant farm” and it dictated the demands and requirements of the system. “Creative ant farm” is an experimental program with no commercial value at this point, in which the user is asked to create a pixilated drawing on a grid, and upon completion a group of animated ants reconstruct the drawing on the screen using different kinds of leafs. This specific idea seemed ideal for a project dealing with object-oriented concepts due to the fact that a main part of the program will have to be a “living” element (the ant) which will have to du- plicated and allow each instance to display a different behavior and act independently. It will prove to be an important lesson in understanding the nature of polymorphism and the ability of instances of a class to display individual property values, which result in an individual behavior.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  5. 5. CREATIVEANTFARM an experiment in object-oriented lingo programming 2.0 Research description 2.3.1 Program storyboard 1st stage – creating a grid After an introduction screen, the user is asked to enter 2 parameters that will define the size of the grid: the total number of cells and the number of cells in arrow. To avoid a situation where the grid gets outside the movie (100 cell and 2 cells in a row will result in 50 rows) once the user defined the total cells and presses on the 2nd field, a message appears which display the valid range the user can choose from as the value. In any case invalid values are entered, the program outputs an alert mes- sage.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  6. 6. CREATIVEANTFARM an experiment in object-oriented lingo programming 2.0 Research description 2.3.1 Program storyboard 2nd stage – creating the drawing Once the grid is created, the user starts selecting cells by clicking them and changes their color. He can deselect a cell selection by selecting it again. The screen also of- fers the user to go back to previous screen and define a new grid in case he wishes to do.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  7. 7. CREATIVEANTFARM an experiment in object-oriented lingo programming 2.0 Research description 2.3.1 Program storyboard 3rd stage – reconstructing the drawing When the user presses the “done” button the screen clears and from this moment on there is no more interaction with the program. Animated ants appear from different directions carrying a leaf heading toward a point on the screen. When they reach it they pause for a few seconds and then drop the leaf and continue moving till they are outside the screen. The end result is a complete reconstruction of the original drawing only on a larger scale and using leafs to visualize it.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  8. 8. CREATIVEANTFARM an experiment in object-oriented lingo programming 2.0 Research description 2.3.2 Classes description The object-oriented design of the program makes use of 6 classes. The following de- scription is relevant to get a first look of the logical structure object-oriented offers, and how a program runs on many objects that are all instances of a small group of classes. The number of instances is of less importance once the right and most effec- tive relationship between the classes is established. Designing that relationship was one of the more challenging aspects of the project. 1. AppManager Class - Initializes the program and creates the 2 manager objects: GridManager and AntManager. - Control the navigation inside the program. - Receives user input and checks validation of entry fields. - Receives user input on the grid. 2. GridManager Class - Creates the grid. - Updates the grid. - Removes the grid. 3. AppObject Class - Contains common methods such as doPuppet() and getLoc() and serves as a super class for AntClass and GridBlockClass. 4. Ant Class - Defines an ant object and includes all the properties and method, which generate the movement toward a target on screen. 5. GridBlock Class - Defines a grid block object. 6. SpriteManager - Controls the distribution of sprite numbers to which object that wishes to be puppeted.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  9. 9. CREATIVEANTFARM an experiment in object-oriented lingo programming 3.0 Paradigm shift – stepping into OOP Making the “switch” from procedural to object-oriented thinking was not an easy one. It demanded a new way of looking and analyzing things and a new unfamiliar approach to problem solving. At first it seemed less natural and intuitive, but as the development process progressed, it became obvious that once the mind has been set, the object-oriented thought can be just as intuitive and natural as the procedural one. As oppose to procedural programming, object-oriented felt stricter and logically more demanding. The delicate relationships between the classes and the fundamental concepts that must be upheld force a constant evaluation of the structure and logic. If in procedural programming there wasn’t a feeling that there is a limit on the number of routines (although you should always strive to keep it down to the absolute minimum), in object-oriented the question of whether or not a new class should be introduced is critical and even once such a class has been added question of possible in- heritance arise and the evaluation starts all over again. Not to say that object-oriented is more difficult or better, but it seemed that in object-oriented there are more consideration that may appear limiting but in a fact has the opposite effect. Since Lingo facilitates object-oriented programming on a very basic level (inheritance using the an- cestor property, class definition using parent scripts) it proved to be a good starting point to experi- ment with object-oriented programming. Not because is allows the developer to disregard object- oriented rules, on the contrary, it forces him to pay more attention and be more resilient since the programming environment doesn’t supply everything automatically.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  10. 10. CREATIVEANTFARM an experiment in object-oriented lingo programming 4.0 OOP vs. Procedural programming in Lingo As was described before, this research project sought to examine object-oriented programming in Lingo in comparisment to procedural programming, the difficulty was that the Director environment was designed with object-oriented in mind, and even if one makes no use of parent scripts or any object-oriented concept knowingly, the environment itself operates in an object-oriented manor. Behaviors, being an integral and fundamental part of any Director production, represent the ob- ject-oriented paradigm and benefits of reusing code through out a program by having properties, which allow each instance of the code to display different behavior based on a common and shared description. That being said, it is impossible to program in pure procedural manor even if the logic of the pro- gram is structured as a set of functions in movie scripts. Because Director offers object-oriented solution built in to its environment, the result of practicing procedural programming is a hybrid between procedural and object-oriented where the use of be- haviors represents the object-oriented part, and functions in movie script the procedural approach. So even a developer that isn’t familiar with the object-oriented methodology enjoys part of its ben- efits and advantages. Had the program been redesigned using the procedural paradigm in mind it probably would have looked and operated the same way as the object-oriented version since as a methodology it offers a means to an end, and shouldn’t have no bearing on the visual and functional aspect. The developer, not the user, will feel the difference in terms of work when it comes to updating the program, scale it, detect and fix bugs etc. To illustrate how the same task looks from two different programming views, the GridManager Class, which creates the grid has been translated into a pro- cedural routine, which appears to be doing the exact same thing. But when examined in the context of the overhaul system, the fact that in the object-oriented version all of the grid information is en- capsulated inside the gridManager object, ensures that the grid data can not be tampered with by any other part of the program resulting in errors and other problems. In the procedural version, the functions use global variables that are exposed to any other function in the program and can be accessed anytime from anywhere. A risk that object-oriented tackles by enforcing information hiding and protection. Another clear advantage when it comes to reducing the amount of code used in the program is the fact that the gridManager can be extended or inherit methods and properties from a super class. Had there been 5 more manager objects in the program, a method such ass addObjects() could have been inherited and written only once. That is an important feature that can not be imitated with functions. Although they can call each other and return values they can not be structured in such a way that will ensure greater flexibility and code reduction.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  11. 11. CREATIVEANTFARM an experiment in object-oriented lingo programming 5.0 Conclusions and personal findings Object-oriented is a way of solving problem. As a methodology that’s its essence. The object-ori- ented mindset may be hard to digest at first, and even then it takes time and practice to understand how to apply it to achieve the best possible result. The procedural approach appears to be more intuitive and because of that object-oriented tends to be regarded as a higher form of programming, when in fact, it shouldn’t be. It’s just different. Procedural programming may seem to be easier to practice, but once you get into the object-ori- ented mindset its hard to understand how did you ever program without it in mind, since it changes the way one perceives the programming language in relation to itself and other languages as well. Understanding objects helps to better understand how a software works and operates, and in case of packages such as Director and especially Flash (where there’s the ability to change/extend built-in objects) it allows the developer far greater creative freedom when it comes to coding. The object-oriented approach is becoming a sort of a standard and by understanding its concepts and features a developer can better adapt to new technological realities such as .NET and others. As for Lingo, I believe that it’s important to extend the built-in object-oriented environment Director offers and explore the realm of parent scripts and other object-oriented concepts. Eventhough Lingo facilitates basic object-oriented programming, it is still suficinte to design robust applications and get familiar with key concepts that can later be applied and extended in other lan- guages such as Java, C++, C#, ActionScript, JavaScript etc. Utilizing object-oriented programming in Lingo, as in any other programming environment, helps simplifiing a problem and consieving a better solution. That better solution will strive to reuse code in an efficiant way and offer a flexible approach to the program’s design. I found that object-oriented thinking is a philosopical and mental advanture. It makes the develop- ment process more challenging and rewarding. The end result is a simplified solution to a complex problem, which might be used as parts or as a whole in future projects. This project showed me how 1,000 different ants can be created out of a single class, and these ants represent windows in an application, characters in a game and anything else that can and should be classified in order to ensure maximum use of code and minimum time spent writing it.SAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  12. 12. CREATIVEANTFARM an experiment in object-oriented lingo programming 6.0 Resources Baylis. E., Bounds. J., Britton. D., Thevathasan. L., Director 8.5 Studio, Birmingham, UK: friends of ED, 2001. Small. P., Lingo Sorcery - The magic of lists, objects and intelligent agents, USA: John Wiley & Son Ltd, 2nd edition 1999. Drol. W., Object Oriented Macromedia Flash MX, USA: APress, 2002. Decker. R., Hirshfield. S., Programming Java - an introduction to programming using Java, USA: PWS Publishing Company, 1998. Building OOP applications in Flash 5 http://www.debreuil.com/docs/ch01_Intro.htm LingOOP: Object-Oriented Programming with Lingo & DreamLight Director Talisman Tips & Tricks http://www.dreamlight.com/insights/07/objects.htm http://www.director-online.com/howTo/UD_articles/OOP.html http://www.director-online.com/howTo/UD_articles/UD19.html Object Oriented Programming Concepts http://www.umsl.edu/~subraman/concepts_toc.html Introduction To Object-Oriented Programming http://bepp.8m.com/english/oop/ Object oriented thinking http://www.mcli.dist.maricopa.edu/director/misc/sorcery/wio0896c/sorcery/oot.htm Why Procedural is the Wrong First Paradigm if OOP is the Goal http://csis.pace.edu/~bergin/papers/Whynotproceduralfirst.htmlSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  13. 13. CREATIVEANTFARM an experiment in object-oriented lingo programming 7.0 Appendix 1. GridManager Class compared with CreateGrid routine CreateGrid routine - the procedural approach global gridPropList,gridList,targetList,gridMode on initGrid xstart,ystart,rowLimit,totalBlocks,gridMember gridMode=true targetList=[0] gridList=[] gridPropList=[:] gridPropList.addProp(#xStart,xstart) gridPropList.addProp(#yStart,ystart) gridPropList.addProp(#blockMember,gridMember) gridPropList.addProp(#rowLimit,rowlimit) gridPropList.addProp(#totalBlocks,totalBlocks) puppetGrid() end on puppetGrid repeat with i=1 to gridPropList.getProp(#totalBlocks) tempSprNum=getFreeChannel() sprite(tempSprNum).puppet=true sprite(tempSprNum).scriptInstanceList.add(script(“gridBlock_script”).new()) gridList.add(sprite(tempSprNum)) sprite(tempSprNum).member=gridPropList.getProp(#blockMember) sprite(tempSprNum).loc=point(-100,-100) updatestage end repeat sendAllSprites(#setMode,”unselected”) calculatePos(gridPropList.getProp(#xStart),gridPropList.getProp(#yStart)) end on calculatePos startX,startY blockwidth=gridList[1].width blockY=startY blockX=startX-blockWidth blocksInRow=1 repeat with i=1 to gridPropList.getProp(#totalBlocks) blockX=blockX+blockWidth gridList[i].loc=point(blockX,blockY) blocksInRow=blocksInRow+1 if blocksInRow>gridPropList.getProp(#rowLimit) then blockY=blockY+blockWidth blockX=startX-blockWidth blocksInRow=1 end if end repeat endSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  14. 14. CREATIVEANTFARM an experiment in object-oriented lingo programming 7.0 Appendix 1. GridManager Class compared with CreateGrid routine CreateGrid routine - the procedural approach (continue) on addToTargetList theItem repeat with i in targetList if i=theItem then targetList.deleteOne(theItem) put targetList abort end if end repeat repeat with i in targetList if i<>theItem then myCount=myCount+1 if myCount=targetList.count then targetList.add(theItem) put targetList myCount=0 exit repeat end if next repeat end if end repeat end on rescaleGrid toAdd repeat with i=1 to gridPropList.getProp(#totalBlocks) gridList[i].rect=gridList[i].rect.inflate(toAdd,toAdd) gridList[i].blend=30 end repeat gridMode=false calculatePos(gridPropList.getProp(#xStart),gridPropList.getProp(#yStart)) end on getFreeChannel repeat with i=1 to the lastChannel if sprite(i).member=member 0 of castLib 0 then return i exit repeat end if end repeat endSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  15. 15. CREATIVEANTFARM an experiment in object-oriented lingo programming 7.0 Appendix 1. GridManager Class compared with CreateGrid routine GridManager Class - the object-oriented approach property _xstart,_ystart,_gridMember,_blocksInRow,_gridList,_rowlimit,_totalBlocks property _maxBlocks,_maxInRow,_maxInCol,_blockWidth,_gridMemberWidth,_minBlocks on new me me._gridList=[] me._maxBlocks=253 me._minBlocks=2 me._maxInRow=23 me._maxInCol=me._maxBlocks/me._maxInRow return me end on init me,xstart,ystart,rowLimit,totalBlocks me._xstart=xstart me._ystart=ystart me._gridMember=”gridBlock” me._rowLimit=rowlimit me._totalBlocks=totalBlocks me.puppetlist() end on addObj me,myObj me._gridList.add(myObj) add the actorlist,myObj end on puppetList me repeat with i=1 to me._gridList.count me._gridList[i].doPuppet(me._gridMember,point(-100,-100)) sprite(me._gridList[i]._sprite).scriptInstanceList[1]=script(“mouseeventsclass”).new(me._gridList[i]._ sprite,me._gridMember) end repeat me.calculatePos(me._xstart,me._ystart) endSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  16. 16. CREATIVEANTFARM an experiment in object-oriented lingo programming 7.0 Appendix 1. GridManager Class compared with CreateGrid routine GridManager Class - the object-oriented approach (continue) on calculatePos me,startX,startY blockwidth=me._gridList[1].getWidth() blockY=startY blockX=startX-blockWidth me._blocksInRow=1 repeat with i=1 to me._totalBlocks blockX=blockX+blockWidth me._gridList[i].setLoc(point(blockX,blockY)) me._blocksInRow=me._blocksInRow+1 if me._blocksInRow>me._rowLimit then blockY=blockY+blockWidth blockX=startX-blockWidth me._blocksInRow=1 end if end repeat end on rescaleObjects me,toAdd repeat with i=1 to me._gridList.count me._gridList[i].rescale(toAdd) end repeat me._gridMemberWidth=me._gridlist[1].getwidth() me.calculatePos(me._xstart,me._ystart) end on updateGrid me,blockSprite,antAngle,leafMember repeat with i=1 to me._gridList.count if me._gridList[i].getSprite()=blockSprite then me._gridList[i].setAngle(antAngle) me._gridList[i].setMember(leafMember) me._gridList[i].visibleMode(100) exit repeat end if end repeat end on destroy me repeat with i=1 to me._gridList.count me._gridList[i].remove() me._gridList[i].destruct() me._gridList[i]=void end repeat endSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies
  17. 17. CREATIVEANTFARM an experiment in object-oriented lingo programming 7.0 Appendix 1. GridManager Class compared with CreateGrid routine GridManager Class - the object-oriented approach (continue) on getMaxBlocks me return me._maxBlocks end on getMinBlocks me return me._minBlocks end on getMaxInRow me return me._maxInRow end on getMaxInCol me return me._maxInCol end on setXYstart me,newXstart,newYstart me._xstart=newXstart me._ystart=newYstart end on destruct me me.destroy() me._xstart=void me._ystart=void me._gridMember=void me._blocksInRow=void me._gridList=[] me._rowlimit=void me._totalBlocks=void me._maxBlocks=void me._maxInRow=void me._maxInCol=void me._blockWidth=void me._gridMemberWidth=void me=void endSAE London - Multimedia Arts Degree // October 2002 // Module 103 - Basic Multimedia Studies

×