Joe the Box Chapter 3 Squeak: Object-oriented design with multimedia applications.

Slides:



Advertisements
Similar presentations
Getting Started with PowerPoint
Advertisements

Getting Started With Alice: The Basics By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Unit 3 Day 4 FOCS – Web Design. No Journal Entry.
Mission Technology Introduction to Scratch! June 2007.
Introduction to InDesign Understanding the Basics DTB203 Interior Visualisation
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Boardmaker 6 Basic Tutorial
Stéphane Ducasse 1 The Taste of Smalltalk.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
C++ Graphics Primitives April 15th. void clearscreen(int c) –clear the screen to background color c –If c = 1 screen black.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
ABC’s of PowerPoint (Office 2007) Part 1: Basic Vocabulary Part 2: Cursors Part 3: Insert Your Text Part 4: Insert Your Pictures Part 5: Basic Tools &
Emerging Technologies Beginning SmartBoard for Teachers.
By: Zaiba Mustafa Copyright ©
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
INTRODUCTION TO THE SCRATCH PROGRAMMING ENVIRONMENT.
Chapter 3 Working with Symbols and Interactivity.
A Mid-Term study guide of covered commands. SAVING  Using the Save command allows the drafter to save an already developed drawing.  The Save As command.
Using the Smart Board Jeanne Klein Instructor Computer Inservice Program Spring 2006.
Introduction to Scratch!
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 8 Fall 2010.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
PowerPoint 1 The Basics 1. Save this file to your Apps Folder as YourLastName_PP1 2. Read each slide. 3. Complete each set of numbered directions.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Object-Oriented Programming Lecture 13 – OO Programming, Spring CSE3302 Programming Languages,
Techniques & Tools in this Workshop 1.GeoGebra Website 2.Webstart vs. Applet Start 3.Basic GeoGebra Window 4. New Point tool 5. Move tool 6.Free and Dependent.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Working with Symbols and Interactivity
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Intro to the Squeak environment. Getting Squeak Read instructions for working in labs linked from course web pages. –Save your Squeak.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
Getting Started With AutoCAD ENGR 2 Week #1 Laboratory.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
PLACING AND LINKING GRAPHICS
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Illuminating Computer Science CCIT 4-6Sep
Open Publisher- it is part of Microsoft Office Then find: Blank publications Full page.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Pinnacle Pro Painting Program User Manual Created by: David Kwasny Chris Schulz W. Scott DePouw.
Computer Programming Modeling a Passive Solar Home.
1 Project designed and created by M. Shajith Kumar.
Know your computer Make a Folder Copy from Word to Composer Format the Font Change the Alignment Format the Background Format the Colors Insert a Picture.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
2D Design – A Guide! SECTION 1.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
Basic 2D Graphics in Android. Android Graphics Programming There are many ways to do graphics programming in Android – 2D vs. 3D – static vs. dynamic.
© 2006 ~ 2007 CalmoSoft Project for Vista Smalltalk.
Computer Programming with Scratch JAOIT 8. Scratch Scratch is a programming language that makes it easy to create your own interactive stories, animations,
Getting Started With Alice: The Basics. Step 1: Background Open up Alice, and choose a background for your Alice world. Your world is something you can.
Chapter 3 Squeak: Object-oriented design with multimedia applications
Learning to program with Logo
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Introduction to Testing, SUnit and Error Handling
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Game Loop Update & Draw.
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
creating a ecosystems model in net logo
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Presentation transcript:

Joe the Box Chapter 3 Squeak: Object-oriented design with multimedia applications

Story zGenerating: How to File In/Out Code zPlaying with Joe the Box yA microworld for learning about Boxes yOriginally by Adele Goldberg zAnalyzing Box zHow to Draw zExtending Box zGenerating: How to take apart an example zImproving Box yA Start on UML

Filing in zNormal way of passing around code in Smalltalk yPlain text file, suffix.st (SmallTalk) or.cs (Change Set) zLoad in Boxes by filing it in y(First, get it on your computer) zFind it in the FileList zClick the File-in button

FileList Directory Structure Pattern to match to filenames Contents of selected file Files in the directory

Filing out zSimply choose FileOut from the yellow-button menu in the Browser yFor any of category, class, protocol, or method

Creating Boxes zBox clearWorld "To open the world" zjoe := Box new. "To create Joe"

Joe is a Box zjoe class "PrintIt" zJoe is an instance of a Box yIt knows how to do things that Boxes know how to do xturn: xmove: xgrow: zNeat example of what Joe can do:

Joe being a Box

Jill is also a box zjill := Box new. "Make Jill" zJill knows the same things as Joe, in the same way, but has different data yjill turn: 127 "Jill turns, Joe stays the same." yTwo different boxes, with different xPositions xSizes xOrientations

Class Box's Methods

Box's Instance Methods

NamedBox zjane := NamedBox named: 'jane'. "Note: Different creation method" zjane isKindOf: Box "PrintIt to see true"

NamedBox methods zOverriding instance methods: draw, undraw zAdd undrawNameColor: zNew class method: named:

Creating the Box zClass Definition zClass method new

Issues in Creating the Box zWhy is it “super” not “self” in the Class method new? zWhy do we get a Box out of this new and not an instance of Object (or whatever)? zWhat if NamedBox did the exact same definition of new? Would it work?

Equivalent method for new new | temporaryNewObject | temporaryNewObject := super new. “Create the new object” temporaryNewObject initialize. “Initialize it” ^temporaryNewObject “Return it”

So what's happening in initialize? initialize position := "Set instance variables" size := 50. tilt := 0. self draw. "Make it appear."

Class method for clearWorld clearWorld (Form extent: fillWhite display zA Form is a bitmap graphic yForm extent: creates one of the given size (as a Point, zdisplay puts it up at on the Display

How to Draw (in Squeak) yCreate a form from a file x|f| xf:= Form fromFileNamed: 'my.gif‘. f display. yCreate form from a URL xHTTPSocket httpGif: ' -center.gif‘ yGet form from the screen xForm fromUser “select on screen”

Shrinking and Magnifying Forms | f s | f := Form fromUser. "Let the user define a rectangle" s := f shrink: f boundingBox by: 5. "Shrink it" s displayOn: Display at: Sensor waitButton "Display it" s := f magnify: f boundingBox by: s display.

Rotating a Form | a f | f := Form fromDisplay: extent: "Save the screen" a := 0. "Rotation value" [Sensor anyButtonPressed] whileFalse: "Rotate until mousebutton" "Grab screen from mousepoint, rotate, and display" [((Form fromDisplay: (Sensor cursorPoint extent: rotateBy: (a := a+5)) display]. f display "Put the original corner of the screen back"

How Forms work zForms are manipulated with BitBlt yBit Block Transfer yIt's what makes overlapping windows and pop-up menus possible zSqueak includes a new kind of BitBlt called WarpBlt yInstead of merely moving one rectangle somewhere else, it moves one rectangle to a quadrilateral yTry: FishEyeMorph new openInWorld

Making other objects on Forms zFrom Smalltalk-80, Squeak actually knows about lots of graphical objects than can draw themselves on Forms: Arcs, Splines, Circles | aCircle aForm | aForm := Form extent: "This will define the circle edge" aForm fillBlack. aCircle := Circle new. aCircle form: aForm. aCircle radius: 50. aCircle center: aCircle displayOn: Display

Teaching Boxes to Draw draw | myPen | myPen := Pen new. "Create a new Pen for drawing" myPen up. "Don't draw while setting it up" "Set up the Pen with the Boxes' characteristics" myPen goto: position. myPen turn: tilt. myPen color: (Color black). "Now put the Pen down and draw the box." myPen down. 4 timesRepeat: [myPen go: size; turn: 90].

Pens as Turtles zPens have a heading and a pen state zThey draw on Display, or create them newOnForm:

Putting Pens in Morphic Images zNote that Morphic redraw destroys Pen/Form marks. form := Form extent: p := Pen newOnForm: form. p down. 4 timesRepeat: [p go: 50; turn: 90]. (SketchMorph withForm: form) openInWorld “m := ImageMorph new. m setNewImageFrom: form. m openInWorld.”

How Boxes undraw undraw | myPen | myPen := Pen new. "Create a new Pen for drawing" myPen up. "Set it up for drawing the Box" myPen goto: position. myPen turn: tilt. myPen color: (Color white). "Now draw it with the background color" myPen down. 4 timesRepeat: [myPen go: size; turn: 90].

All other Box methods zFollow the same pattern yUndraw the current Box representation yChanging something yDraw it again

Two examples grow: increment self undraw. size := size + increment. self draw. move: pointIncrement self undraw. position := position + pointIncrement. self draw.

Getting input from the user zRecall  [Sensor anyButtonPressed] whileFalse:  [joe moveTo: (Sensor mousePoint)]  Sensor is a global variable  Instance of InputSensor  Access point for the Mouse and Keyboard

Sensor for keyboard

Sensor for mouse

Extending Box to create NamedBox Box subclass: #NamedBox instanceVariableNames: 'name ' classVariableNames: '' poolDictionaries: '' category: 'Boxes'

What would happen if we did new? jane := NamedBox new. jane name: 'Jane'. jane draw. Here's the result: Why?

How named: works named: aName | newBox | newBox := super new. "Do the normal Box draw" newBox undraw. "Erase it – using NamedBox erase" newBox name: aName. "Set the name" newBox draw. "Draw it with the name" ^newBox

How draw and undraw work draw super draw. "Draw myself as a Box" self drawNameColor: (Color black). "Draw my name in black" undraw super undraw. "Undraw myself as a Box" self drawNameColor: (Color white). "Erase my name in white"

Where unnamed NamedBox instances get their name drawNameColor: aColor | displayName | (name isNil) ifTrue: [name := 'Unnamed']. "If no name, fake one" displayName := name asDisplayText. "Make the string a kind of Form" displayName "Set its color" foregroundColor: aColor backgroundColor: (Color white). displayName displayAt: position. "Display it"

Generating: Reusing an Example Goal: Name in random colors zHow do you reuse foregroundColor:backgroundColor:? yTry implementors (Alt/Command-M) yTry senders (Alt/Command-N) yFind example class methods and try them zHow generate random colors? yLook for instance creation methods for Color yFind class Random, read class examples and comments

Putting together the pieces myGenerator := Random new. 30 timesRepeat: [ name:=‘Fred Flintstone' asDisplayText. name foregroundColor: (Color r: myGenerator next g: myGenerator next b: myGenerator next) backgroundColor: (Color transparent). name displayAt: (100 (100 atRandom).]

Improving Boxes  Design flaws in Boxes  Creating new Pens and duplicating functionality  Pens have a location and direction  draw/undraw have too much replication  Improvements  Each Box gets its own Pen  Rewrite draw/undraw

Improving Box zNew Box instance vars: size and pen initialize pen := Pen new. "Put a pen in an instance variable." pen place: size := 50. self draw.

Delegate to Pen zDelegation: Asking another object to perform a service for the original object. move: pointIncrement self undraw. pen place: (pen location) + pointIncrement. self draw. turn: degrees self undraw. pen turn: degrees. self draw.

Re-doing draw/undraw draw self drawColor: (Color black). undraw self drawColor: (Color white).

drawColor for new Box drawColor: color pen color: color. 4 timesRepeat: [pen go: size; turn: 90].

Fixing NamedBox draw zPrevious version knew Box position drawNameColor: aColor | displayName | (name isNil) ifTrue: [name 'Unnamed']. displayName := name asDisplayText. displayName foregroundColor: aColor backgroundColor: (Color white). displayName displayAt: (pen location).

How do we talk about designs? zWith representations zUML (Unified Modeling Language) is the O-O Standard zThe original Box class structure:

How do we depict the redesign?