Chapter 3 Squeak: Object-oriented design with multimedia applications

Slides:



Advertisements
Similar presentations
Getting Started With Alice: The Basics By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Advertisements

Mission Technology Introduction to Scratch! June 2007.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
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 Scratch!
CSE 3302 Programming Languages Chengkai Li Spring 2008 Object-Oriented Programming Lecture 13 – OO Programming, Spring CSE3302 Programming Languages,
Joe the Box Chapter 3 Squeak: Object-oriented design with multimedia applications.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Introduction to Using the Notebook 10 Software for SMART Board Day 2 LIVINGSTON PARISH PUBLIC SCHOOLS Facilitated by S. Waltman.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Morphic A highly unusual graphical toolkit! Originates in the Self project at Sun –Self: a prototype-based programming language –No classes---objects inherit/instantiate.
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
Computer Programming Modeling a Passive Solar Home.
1 Project designed and created by M. Shajith Kumar.
Getting started with the turtle Find the latest version of this document at
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
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 6 Introduction to Hexa – Workshop 2 3D Pipe Junction
Unit 6 – Multimedia Element: Animation
The Essentials of Alice (Bunny)
Getting Started With Alice: The Basics
An Introduction to Alice (Short Version)
PYGAME.
SketchUp Chocolate Level of Difficulty Time
Introduction to presentations ms PowerPoint
Class 22: Inheritance CS150: Computer Science University of Virginia
Example: Card Game Create a class called “Card”
3.01 Apply Controls Associated With Visual Studio Form
Intro to CS Monday, August 29
Intro to CS Monday, August 24
Gimp Guide Mr Hall.
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
Intro to GML.
Introduction to TouchDevelop
Introduction to Testing, SUnit and Error Handling
Alice Variables Pepper.
INTERMEDIATE PROGRAMMING LESSON
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Introduction to TouchDevelop
Extend Text Editor to Draw shapes
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
An Introduction to Alice
Game Loop Update & Draw.
Scratch for Storytelling
Working with Symbols and Interactivity
INTERMEDIATE PROGRAMMING LESSON
Introduction to PowerPoint
Whatcha doin'? Aims: Begin to create GUI applications. Objectives:
Introduction to Object-Oriented Programming in Alice
Getting Started With Alice
Moodle Training — Advanced Topics —
Greenfoot November 8, 2009.
Getting Started With Alice: The Basics
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Model, View, Controller design pattern
Lesson One: Objects in Alice: Positioning and Moving Them
creating a ecosystems model in net logo
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Case Study: Prototyping a Play-Writing Workbench
Chapter 1 Introducing Small Basic
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:

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

Story Generating: How to File In/Out Code Playing with Joe the Box A microworld for learning about Boxes Originally by Adele Goldberg Analyzing Box How to Draw Extending Box Generating: How to take apart an example Improving Box A Start on UML

Filing in Normal way of passing around code in Smalltalk Plain text file, suffix .st (SmallTalk) or .cs (Change Set) Load in Boxes by filing it in (First, get it on your desk) Find it in the FileList Then yellow-button-menu, and choose File In

FileList

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

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

Joe is a Box joe class "PrintIt" Joe is an instance of a Box It knows how to do things that Boxes know how to do turn: move: grow: Neat example of what Joe can do:

Joe being a Box

Jill is also a box jill := Box new. "Make Jill" Jill knows the same things as Joe, in the same way, but has different data jill turn: 127 "Jill turns, Joe stays the same." Two different boxes, with different Positions Sizes Orientations

Class Box's Methods

Box's Instance Methods

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

NamedBox methods Overriding instance methods: draw, undraw Add undrawNameColor: New class method: named:

Creating the Box Class Definition Class method new

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

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

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

Class method for clearWorld (Form extent: 600@200) fillWhite display A Form is a bitmap graphic Form extent: 600@200 creates one of the given size (as a Point, h@v) fillWhite makes it all white display puts it up at 0@0 on the Display

How to Draw (in Squeak) Creating a Form Form fromUser "Lets you select off the screen" |f| f:= Form fromUser. f edit. Use Morphic's editor (New morph… menu) Form fromFileNamed: 'my.gif' HTTPSocket httpGif: 'www.cc.gatech.edu/gvu/images/headers/titles/gvu-center.gif'

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

Rotating a Form | a f | f := Form fromDisplay: (0@0 extent: 200@200). "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: 130@66)) rotateBy: (a := a+5)) display]. f display "Put the original corner of the screen back"

How Forms work Forms are manipulated with BitBlt Bit Block Transfer It's what makes overlapping windows and pop-up menus possible Squeak includes a new kind of BitBlt called WarpBlt Instead of merely moving one rectangle somewhere else, it moves one rectangle to a quadrilateral Try: FishEyeMorph new openInWorld

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 Pens have a heading and a pen state They draw on Display, or create them newOnForm:

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 Follow the same pattern Undraw the current Box representation Changing something Draw it again

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

Getting input from the user Recall [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?

named: aName How named: works | 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 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 How do you reuse foregroundColor:backgroundColor:? Try implementors (Alt/Command-M) Try senders (Alt/Command-N) Find example class methods and try them How generate random colors? Look for instance creation methods for Color Find class Random, read class examples and comments

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

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

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

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

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

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

Fixing NamedBox draw Previous 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? With representations UML (Unified Modeling Language) is the O-O Standard The original Box class structure:

How do we depict the redesign?