© copyright 2003 logotron limited · edition 1 the greatbig imagine ... simple solution •...

21

Upload: hatu

Post on 19-Aug-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach
Page 2: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach
Page 3: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved1

© Copyright 2003 Logotron Limited

Published by Logotron

Part Number: Imagine9

All rights reserved

No part of this publication, either the whole or any part of the program ordocumentation, may be reproduced, transmitted, transcribed, stored in aretrieval system or translated into any language or computer language inany form or by any means, electronic, mechanical, optical, chemical, manualor otherwise, except as permitted under the licence agreement, without theexpress written permission of the publisher.

Edition 1

THE GREAT BIG IMAGINE LOGO PROJECT BOOK

Page 4: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

01 LogoMotion – Image Editor For Imagine 1

02 Basic Turtle Commands.

03 Commands With Inputs 1

04 Commands With Inputs 2

05 Events. Drawing While Dragging

06 Conditions

07 Random Walks. How To Terminate Recursion

08 Processes

09 Multiple Turtles 1

10 Image As A Turtle Shape

11 LogoMotion – Image Editor For Imagine 2

12 Multiple Turtles 2

• basic drawing one picture• Working with a region (selection)• working with photography

• basic movements, cleaning the page• pen of the turtle, pen colour, pen width• choosers, Buttons window, random inputs• more commands• repeat command• edit command

• defining your own commands• command with input

• commands with several inputs• poly command• pen colours and pen widths as inputs

• change t1 dialogue box• automatic dragging• your own button – onPush event• turtle and its onDrag event• your own command as a reaction to onDrag event• how to make command more random

• generating random numbers: examples and exercises• drag the flower and stamp• reaction depending on the colour of the

background – conditional instructions• endless walk – infinite tail recursion

• movements restricted into a rectangle• compound conditions – and, or• random walk: exercises• how to terminate recursion

• parallel process• switch button and its onPush and onRelease events• processes with names, cancel the process• page and pane• horizontal slider• build your own game – connecting dots

• New Turtle tool• how to address turtles• addressing one turtle with apostrophe• in-the-middle curve, position as a vector,

computations with vectors• experiments

• exploring default shape, stamp command• image as a value of a variable• image, frames and frame items. Pacman• In the Meadow project

• working with animation• ready-made animation• transform and generate• create your own animation

• creating turtles with the new command, list of settings• flocks of turtles• turtles chasing turtles – pig hunting• who is active – permanently and temporarily• generating turtles while moving around a circle

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved2

CONTENTS – LIST OF TOPICS AND CONCEPTS

Page 5: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

13 Problems and Projects

14 Project 1 Bugs In a Sheep Pen

15 Revision Problems and Assignments

16 Drawing Lists 1

17 Drawing Lists 2

18 Drawing Lists 3 Dynamic Programmable Shapes

19 Lists 1 Collecting Points and Drawing Them

20 Lists 2 Working With Text. Sentences

21 Lists 3 Operations. Building Listsfrom Parts

22 Recursion To Draw Fractal Curves

23 Classes and Object Oriented Scripting 1

24 Classes and Object Oriented Scripting 2

25 Project 2 Arrow Labyrinth (final project)

• firework• gymnastic festival – many turtles in a regular formation• contest of bugs• more pighunting strategies• living picture – several objects and processes

• Mid Course test

• Problems and projects from 1-14

• programmable shapes, drawing lists• Mill project• setting pen colour and pen width inside drawing list

• what can be used inside a drawing list• Arrow project• Watching Eyes project, onLoad event• The Watch project

• dynamic programmables shapes• Circle1 project 1 – slider to resize the circle• Circle project 2 – resizing by dragging the border• introduction to dynamic geometry

• revision of different kinds of lists• lists and their items• empty list• collecting points by mouse – simple solution• processing lists of points• collecting points as a property of the page• collecting drawings with several segments

• setting font for a turtle, about fonts• turtle printing into the page, command label• printing into circles, polygons and columns• textSize command• text as a shape of the turtle• generating random sentences

• commands and operations• defining your own operations, output command• recursive operations on numbers• list of the names of turtles

• fractal curves, snow flakes and variations• carpet fractal curves• recursive trees• recursive trees with random irregularities

• load background• onClean event of the page• fish with their own speeds and sizes• Save as Web Project…• class of wooden blocks, its subclasses

• grey stars on the sky• stars moving away from the centre of the page,onCreate event

• lighting the stars• improved dynamic geometry

• define Card and other classes• generate arrow labyrinth• define behaviour for the bug to walk through the

labyrinth, go command

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved3

Page 6: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

The workbook materials provide a school with resources to create a substantialcourse starting in Year 7 and working through to Year 9. The materials aredesigned so that progression is built in. Also available are assessment activitiesand projects for students to work on.

The Workbook provides a sound approach to providing skills in taught ICT thatare transferable into mathematics and design and technology activities.

The chart which follows maps the use of the whole workbook against the cur-rent schemes of work for ICT and suggests where the activities may fit in othersubjects.

The design of the materials is such that units of work can be broken down intosingle, double sessions of time, or provide a set of related and coherent workover a short period of 4 to 5 weeks.

The workbook encourages, within clear parameters, students to create and pro-duce materials for themselves. They learn to understand some clever ideas in aconcrete way and it is expected that application of this learning with the manyexercises and projects will extend and enrich the students learning.

The design and technology department will find some very good sections thatthey can build into a dynamic and interesting course for students. These includethe work around Logomotion which focuses on animation and design. Theseareas are of real interest to today’s students.

The workbook provides teachers with materials to teach key design conceptssuch as working with a single or multiple images, working with regions andworking with different media. The access to these concepts is not trivial but wehope that these materials will make the entry quick and the output worthwhile.

The animation activities provide an interesting and neat way of exploring whatthe first principles of animation are e.g. animation loops, frames and delays andtransformation. For the novice user, the results are immediate and it provides theteacher with a good introduction to the whole process of animation.

Many teachers of mathematics have a range of ICT materials and resources thatthey use to help students understand specific ideas and concepts. They alsooften seek materials that build on what has already been taught and learned.Finding an ICT resource that works with students development in the same wayas their understanding of number, for example, is a very important tool.

These materials provide teachers with an opportunity to break down the sections into manageable bites of activities and slot them into the curriculumwhere appropriate. The workbook is designed to revisit ideas with new exercisesand projects - by adding to and extending the previous activities a progression isbuilt in.

The workbook is geared to allow a wide range of ability to participate in theactivities without the teacher having to come up with alternative ideas to meetthe demands of the whole class.

Secondary schools also have a range of timetable demands and for those whochose the approach of having focus days on a theme or subject, there are a num-ber of excellent projects that would provide a good days work.

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved4

INTRODUCTION

PATHWAY 1 - AS AN ICT COURSE FOR KS3 STUDENTS

PATHWAY 2 - AS A COURSE FOR MATHEMATICS & ICT

PATHWAY 3 - AS A COURSE FOR DESIGN & TECHNOLOGY WITH ICT

The Imagine Logo Secondary Workbook is designed so that a number of path-ways of use can be achieved by schools. There are four key pathways through thematerials.

Page 7: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

By the time students reach the age of 14 +, they have experienced much of the‘traditional’ ICT lessons that are available.

Students can now direct their own learning. The Workbook is an excellentresource for this approach as it provides a structure which is clear but notbound chapter by chapter. There are exercises and activities to try out a varietyof concepts or ideas.

The student is encouraged to apply what they have learned through earlier proj-ects to test out their experience and knowledge. The tutor has access to theassessment activities and can gain an evidence based approach to judging thestudents development.

Chapter heading ICT reference Other subjects

Logomotion – Image Editor for Imagine 1 Design and Technology

Basic turtle commands

Repeat Unit 4 Mathematics

Your own commands

Commands with Inputs Unit 4 Mathematics

Events while dragging Unit 1 Mathematics

Conditions Unit 1 Design and Technology

Mathematics

Random walks

How to terminate recursion Mathematics

Processes Design and Technology

Multiple Turtles 1 Design and Technology

Image as a turtle shape Design and Technology

Logomotion – Image editor for Imagine 2 Design and Technology

Mathematics

Mutliple turtles 2 Unit 6/13 Design and Technology

Mathematics

Problems and projects Unit 15 Design and Technology

Mathematics

Projects 1 – Bugs in a sheep pen Unit 15 Design and Technology

Mathematics

Revision Problems and Assignments Design and Technology

Mathematics

Drawing Lists 1

Drawing Lists 2

Drawing Lists 3

Dynamic Programmable shapes Unit 6/13 Mathematics

Lists 1 Collecting Points and Drawing them

Lists 2 Working with text.

Sentences

Lists 3 Operations. Building Lists from parts

Recursion to draw fractal curves Mathematics

Classes and OOPs 1 Mathematics

Classes and OOPs 2

Projects2 Arrow Labyrinth ( final test) Unit 15

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved5

PATHWAY 4 - AS AN ICT COURSE FOR STUDENTS AGED 14 - 16

CURRICULUM MAP

Page 8: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

LogoMotion is a powerful bitmap and animation editor. You canuse it either directly from Imagine Logo, or as a stand-alone application. It is a powerful tool for drawing pictures, backgrounds,animations etc. LogoMotion provides an excellent range of tools fordrawing and painting, writing text in any font, style, colour and sizeonto graphics and inserting basic regular geometric shapes.

Using LogoMotion directly from Imagine Logo:

WORKING WITH A BASIC DRAWING CONTAINING ONE PICTURE

Experiment and become familiar with the following tools and concepts:

• Free-hand drawing.• Setting the colour.

There are three different views of the colour palette available for specifying the colour:

HSV (drag the small round mark within the colour circle to specify the hue, and/or a white cross within the triangle to specify the saturation and value),

RGB (specify the contribution of each of the three red, green and blue components to the current colour) or Palette (it offers 256pre-selected colours).

To change the view, click on the palette with the right mouse button and select another view.

• Setting the transparency of a colour.•Anti-aliasing for making the drawings smoother.

Use the Zoom tool (click Zoom or press F6 or Ctrl+Q, Ctrl+W or use your mouse wheel...) to compare a diagonal line with Anti-aliasing turned On or Off.

• The Undo and Clear buttons.• Basic tools (click each tool several times to cycle through its

options): Line, Ellipse (used for circles), Rectangle, Spline – simple, closed, filled, Polygon – simple, closed, filled.

•Fill and Colour Replacer.• Keyboard constraints when drawing: Shift and Ctrl.• Inserting text.• Setting the Nib size using the three basic options.

More options exist in the Tool settings dialogue box.

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved6

1 LOGOMOTION – IMAGE EDITOR FOR IMAGINE

• In Imagine Logo click on the turtle with the right mouse button and select Edit Shape from its context menu:

• In Imagine Logo click on a turtle (for example turtle t1) with the right mouse button and select Change t1 from the context menu:

• Select the Edit Background…command from the Page menu:

• In the Change t1dialogue box click

• on the large button displaying the

• current shape of the turtle:

Page 9: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

WORKING WITH A REGION (SELECTION)

• Defining a region. Learn to use the Shift key + drag for re-defining the borders and position of the selection rectangle.

• Moving, copying, resizing, rotating, slanting and other operations with a selection.

Drawing with selection: select a region, right click inside it and select the Paint with Selection command. This specifies a special nib, which can be used for all basic tools, for filling, inserting text etc.

Note: this nib reacts to the currently selected colour. Try selecting another colour and watch the nib!

WORKING WITH PHOTOGRAPHS

You can open a photograph, resize it (often you get a better result if you resize a photo with Anti-aliasing On),cut off some parts or apply different painting effects or tools such as smearing, erasing, colouring, darkening, lightening, sharpening, softening etc. Note that you can choose an effect,then apply it, for example, when drawing free-hand,drawing a line, adding a filled ellipse or text or anything else. You can apply the effect with high precision using filled polygons – see how precisely one part of John Lennon's coat has been lightened. You can also control the intensity of the effect using different settings of the colour transparency.

WORKING WITH SEVERAL PICTURES

Press the F4 key to open/close the Organizer window. This is a useful feature when you are working with several pictures at the same time.

To create (add) a new, empty picture (new page):Go to the File menu and choose the New command.Then click on the Picture Settings button and choose a Picture Style, for example:

•Shape size 128 x 128, Transparency – transparent, (not full alpha channel, because Imagine Logo is not able to process semi transparent shapes).

•Imagine Page (size 796 x 499, no transparency).•Small Icon, Mouse Cursor, Or icon… etc.• Or choose your own settings.

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved7

Page 10: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

HINTS AND TIPS

BASIC MOVEMENTS. CLEANING THE PAGE

PEN, PEN COLOUR, PEN WIDTH

COMMAND SHORT WORD RESULTS EXAMPLES

forward number fd number • Turtle moves forward by number fd 50of pixels. fd -25

fd 12.5fd 20 + 40

back number bk number • Turtle moves backward by bk 30number pixels. bk -54

right angle rt angle • Turtle turns right by angle. rt 45rt -38

left angle lt angle • Turtle turns left by angle. lt 26lt -99

clean • Cleans the page, the turtle’s current position and heading do not change, it stayswhere it is.

clearScreen cs • Cleans the page and moves the turtle to its home positionand basic heading.

penUp pu • Makes the turtle lift its pen up. From then on, when the turtle moves, it does not draw a line.

penDown pd • Makes the turtle put its pen down.From then on, when the turtle moves,it draws a line (in itscurrent pen colour and width).

setPenColour colour setPc”colour • Sets a new pen colour Setpc “red

setPenWidth penWidth setPw penWidth • Sets a new pen width (an integer Setpw 2number 1 or 2 or...)

setXCor X-coordinate • Changes the turtles X or Y- coordinatesetYCor Y-coordinate (you will not use these commands very often)

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved8

2 BASIC TURTLE COMMANDS. REPEAT

Colour in Imagine Logo, is for example red, red3, red4 red5or an RGB code (red, green and blue), such as [255 0 100]

Pen width is an integer number

Point is a list of two numbers (coordinates) [X Y].

Choosers. Enter F9

Page 11: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

RANDOM INPUTS

MORE COMMANDS

COMMAND repeat N [to_do to_do ... ]

EXAMPLES

For commands fd, rt, lt...

fd anyrt anysetPc anysetPw any

setPos anysetXCor anysetYCor any

setHeading anyorsetH any

setPc [255 0 any]setPos [0 any]

to be used with commands like fd, rt, lt, setPc,setPw... and many others.

right click a button, fill in Text and/or Commands

COMMAND SHORT WORD RESULTS

setPos point setPos [0 -100] • Moves the turtle to the point specified by the input, does not change the current turtle’s heading. If its pen is pd - the turtle draws a line (you will not use this command very often).

setHeading angle setH 90 • Turns the turtle so that its heading is the anglesetH angle setH 270 specified.

setH -90

dot • a dot at its current position using the current pen colour and pen width.

point diameter point 20 • Make the turtle print a point with a given diameter.Using the current pen colour.

A sequence of identical instructions fd 100 rt 90fd 100 rt 90fd 100 rt 90fd 100 rt 90

can be replaced by: repeat 4 [fd 100 rt 90]

repeat number [to_do to_do ... ]The sequence of instructions [to_do to_do ... ] is run again and again - the specified number of times

triangle repeat 3 [fd 100 rt 120] repeat 3 [fd 100 rt 360/3]

square repeat 4 [fd 100 rt 90] repeat 4 [fd 100 rt 360/4]

polygon with 5 sides repeat 5 [fd 100 rt 72] repeat 5 [fd 100 rt 360/5]

circle repeat 24 [fd 20 rt 15] repeat 24 [fd 20 rt 360/24]

star with 5 sides repeat 5 [fd 100 rt 144] repeat 5 [fd 100 rt 720/5]

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved9

Page 12: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

Defining our own commands - edit or ed - to...end

to nameOfNewCommand • This structure teaches the turtle how to carry out the new to_do command named NameOfNewCommand. This new nameto_do can be any usual sequence of words without spaces...end

to square to triangle to houserepeat 4 repeat 3 square[fd 60 rt 90] [fd 60 lt 120] fd 60end end rt 90

trianglelt 90bk 60end

EXERCISES AND COMMENTS

• Make sure that you understand the differences between the words command, instruction, input.

• Instruction starts with the name of a command, followed by one or more inputs (or no inputs at all - like in cs).

• Before the instruction is run by Imagine Logo, its inputs are evaluated.In the instruction fd 30 + 20 the input is the number 50 - the result of evaluating 30 + 20.

• Type in instructions using the repeat command and random inputsso that the turtle draws these pictures:

Exercise: Define commands to draw the following pictures. Make use of the pencolour and pen width commands and all the basic turtle geometry commands.Also, make use of the repeat command:

➔ ➔➔

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved10

2 BASIC TURTLE COMMANDS

Page 13: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

Exercise: In the commands to draw the following pictures make use of your own square, triangle and circle commands:

Exercise: Make use of the repeat command:

Exercise: In the commands to draw the following pictures make use of pen colour and pen width commands and also of the dot command:

Exercise: Make use of random inputs:.

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved11

Page 14: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

You can create a new command either:

• In the command line by typing the edit or ed command,for example: ? ed “square, or:

• In the Explore Project window (F4) by double clicking on the Procedures item.

You can modify a command which you have already

defined either:

• In the command line by typing the edit or ed command,for example: ? ed “square, or:

• In the Explore Project window by double clicking on the name of the command.

COMMAND WITH INPUT

In the title line of the command definition the name of the to square :Sinput is specified (there is always a colon in front of the name). repeat 4 [fd :S rt 90]Then this name and colon are used as an input for the forward endcommand, for example fd :S. The colon indicates that the value of S defines the number for forward.

Define square :S. Use it in the command line with different inputs.

Experiment with:repeat 10 [square … ].Experiment with random pen colours and pen widths.

? repeat 8 [square 40 lt 45]

Define other commands with inputs like triangle, star, leaf…

Note: When creating a new command, don't give it a name that already

exists as a standard command in Imagine Logo. It is allowed but

only very advanced users should do this.

Exercise Define commands to draw the following pictures:

All drawings done this way are of the same size because the commands which draw them use the forward command withconstant inputs - i.e. they state a constant number of turtle steps (for example fd 100 or fd 60 etc.). However, you can also define commands that have variable inputs.

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved12

3 COMMANDS WITH INPUTS

Page 15: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

Define other commands that make use of your own previously

defined commands, like the following house command:

to house :Ssquare :Sfd :S rt 90triangle :S

end

Extend the definition of the house command by adding a random pen colour and width.

Tip: When defining a command, always think about how the turtle will end up (its final position and heading). Make it easy to call again.

to house :Ssquare :Sfd :S rt 90triangle :Slt 90 fd -:Send

If you keep to this rule, it is easier to program more complex compositions like a street of houses etc.

Exercise: Define your version of the house :S command. Use this command to draw a street of houses.

Exercise: Define a version of house :S, in which the roof sticks out over the base square by (a) 10 points, (b) 25% of the length of side :S.

Exercise: Define house :S so that the roof sticks out over the base square by a random value. To do so, you need two new tools and techniques:

• The operation random number which generates and outputs a random integer number between 0 and number-1, inclusive.

• A way of temporarily remembering a number, i.e. a local variable.You can create local variables using let _name value.

to house :S to house :Ssquare :S setPc any setPw anyfd :S rt 90 square :Slet "D random 50 fd :S rt 90bk :D setPc any setPw anytriangle :S + 2 * :D let "D random :S / 2fd :D bk :Dlt 90 fd -:S triangle :S + 2 * :Dend fd :D

lt 90 pu fd -:S pdend

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved13

Note: When the turtle draws a house in this way (following the house command definition to the left),it is not left in the correct position for starting again.

Page 16: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

Exercise: Define the circle :S command as a polygon with 24 sides, where :S is the length of the side.Then with the help of the commands square :S, triangle :S and circle :S draw the following figures:

Exercise: Define commands, to draw the following figures:

sun :S :L house :S :R slat :S1 :S2(draw it as a polygon with 24-sides, (where :S is the length of the (where :S1 is the height of let :S be the length of a side and square base and :R the length the rectangular part and::L the length of a ray). of the side of the roof) S2 its width).

Exercise: Define commands to draw the following figures:

Sun1 :N :S rake :N :S1 :S2 rays :N :S fence :N :S1 :S2

An input can express anything, not just the length of a side. In the following polygon command, the first input represents the number of sides:

to polygon :N :SsetPc anyrepeat :N [fd :S rt 360 / :N]

end

COMMANDS WITH SEVERAL INPUTS

Some commands may have more than one input. Define the following rectangle :A :B command with two inputs: its width and its height:

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved14

4 COMMANDS WITH INPUTS 2

to rectangle :A :Brepeat 2 [fd :A rt 90 fd :B rt 90]end

Page 17: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

COMMAND POLY

The polygon command can be made to generate any shape by defining it so that the turtle moves forward :N times with length :S and turns rt :A:

to poly :N :S :A ? poly 8 30 45 poly 5 60 144 ? poly 18 10 10

repeat :N [fd :S rt :A]

end

Exercise: Use your own poly command to draw the following figures:

PEN COLOUR AND PEN WIDTH AS INPUTS

Anything can serve as an input to a command – not only a length, an angle or a number of repetitions,but also the pen colour or the pen width etc.

to colSquare :S :Col ? rt 15 repeat 6 setPc :Col [colSquare 30 any rt 60]repeat 4 [fd :S rt 90]

end

to colWidthCircle :S :Col :wsetPc :ColsetPw :wrepeat 24 [fd :S rt 15]

end

Exercise: Define commands to draw the following figures:

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved15

Page 18: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

A SIMPLE EXPERIMENT WITH COLOURS

It's time to start a new Project. Right click on the turtle, select the Change t1 command and the Change t1 dialogue box willopen. Look at its tabs – you can use them to view and reset most ofthe settings of turtle t1. For each setting of the turtle (for examplethe pen colour) there is a pair of tools (procedures): an operationwhich tells you about the current value of this setting (for examplepenColour) and a command to modify it (for examplesetPenColour):

? show penColour ; the same as sh pcblack? setPenColour "blue? sh pcblue

Open the Change t1 dialogue box again and check this change inits Painting tab. Then, open the Shape tab and tick the AutoDrag option.

Close the dialogue box and drag the turtle along the page using themouse. It draws like a pencil -– this is your first "free hand drawing".

You are about to do a lot of drawing, so you need a tool for

cleaning the page:

• In the Main Bar, click on the New Button tool, then click on the upper left-hand corner of the page. This creates an empty button. You can click it, but nothing happens.

• Right click on your new button, choose the Change b1command and the Change b1 dialogue box will open. Type the command cs (that is, clearScreen) in the Caption field.

• Define the onPush event for the button, this specifies what happens when you click on the button. Enter clearScreen.Close ffthe window by clicking on the Ok button.

• Press (and keep pressed) Ctrl and , using the right mouse button, drag the lower right corner of the button. This resizes the button.

Right click on the turtle, open its Change t1 dialogue box,

find the Events tab and:

• Click on the Add button. In the list of events, choose onDragand click on the Ok button.

• Define the body (reaction) of this event to be setPc any setPw any.

• Click on the Ok button. The Change t1 dialogue box will close.

You have just defined the onDrag event. This is what should happen, repeatedly, when you drag the turtle around the page usingthe mouse.

Instead of setPc any specify the colour as a mixture of differentamounts of three colours [red green blue], for example [100100 85]. All three numbers here must be integer numbers between 0 and 255, inclusive. Now replace one of thesethree numbers by any, for example setPc [100 100 any].

The Great Big Imagine Logo Project Book Copyright 2003 Logotron Ltd. All rights reserved16

5 EVENTS. DRAWING WHILE DRAGGING

Page 19: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

THE REACTION TO ONDRAG MAY BE THE NAME OF YOUR OWN COMMAND

• Experiment with different commands. Define onDrag as –• Experiment with turning the pen up and down. pd house pu wait 30• In the onDrag event use wait number, if the reaction You will need to define the house command:

happens too often. ? ed "houseto housesetPc any setPw anyrepeat 5 [fd 40 rt 90]repeat 3 [fd 40 lt 120]lt 90 bk 40end

HOW TO MAKE A COMMAND MORE RANDOM

You need the random operation. As its input it takes a positive 0, 1, 2 ... N-1:integer number, for example N. Its result (output) is an integer ? sh random 10number chosen at random from the numbers 7

? sh 5 + random 5The result (output) of 5 + random 5 is either 5 or 6 or 7 or 8 or 9. 8

The aim is to make the turtle draw houses at random sizes as you to house :Sdrag it around. Define the house command with an input that setPc any setPw anydetermines its size: repeat 5 [fd :S rt 90]

repeat 3 [fd :S lt 120]lt 90 bk :Send

Unfortunately this deos not work. You cannot say house any, becausehouse is a command that you have created and you haven't told it howto respond to an input of any. Therefore you have to use random in this case.

Define onDrag as pd house 10 + random 50 pu wait 30.If you want the houses to be scattered even less ‘regularly’, you can replace wait 30 by a greater range of values for the spaces between houses:

wait random 100.

Define commands and reactions to the onDrag event and try to create the figures on the right. Make use of the random :N operation.You may also find the pick operation useful, this takes a list of options and outputs one of them chosen at random:

? sh pick [yellow6 yellow7 yellow8 yellow9 yellow10]yellow7

The Great Big Imagine Logo Project BookCopyright 2003 Logotron Ltd. All rights reserved17

More experiments with the onDrag event

(Do the following first: open the Change t1 dialogue box, go to its Position tab and set the Range to Window) .•setPc any setPw any fd 40 bk 40.• Change the pen width to 3, onDrag – fd 40 bk 40.• Switch the pen off, that is set it to pu, then specify: onDrag – pd fd 40 pu bk 40.

•setPc "blue pd fd 50 setPc any point 30 pu bk 50 wait 30 – add this wait command only if the reaction happens too often.

•setPc "blue setPw 1 pd fd any setPc any setPw any dot pu.

• Change the pen width to 3, turn the pen on, that is pd, and set: onDrag – setPc any fd 30 bk 60 fd 30.

•setPc any fd 40 bk 80 fd 40 rt 5 .

Page 20: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach
Page 21: © Copyright 2003 Logotron Limited · Edition 1 THE GREATBIG IMAGINE ... simple solution • processing lists of points ... The workbook provides teachers with materials to teach

124 Cambridge Science ParkMilton RoadCambridgeCB4 0ZSUnited Kingdom

Tel +44 (0)1223 425558Fax +44 (0)1223 425349Email [email protected] www.logo.com