Calico Differences

From IPRE Wiki
Jump to: navigation, search

These are the known differences between Calico and the previous Python Myro prototype.

See also Calico Graphics for more documentation on the new Graphics library.


1) The module name is now "Myro" rather than "myro":

from Myro import *
import Myro

2) timeRemaining() has been removed.

Was this:

while timeRemaining(30):

You should now use this:

for t in timer(30):

3) upgrade() is now in firmwareupgrade:

import firmwareupgrade

4) joyStick() has been renamed "joystick()" (all lowercase)

5) Python's input() is mapped to Myro.ask() and always returns a string. Use eval(ask()) to get old input() behavior (as does Python3).

6) There is a basic computer object; needs beep, setVolume, playSong

7) playNote was removed (never referenced in text)

8) New functions:

  • makePicture(window) - makes a picture from a window's contents
  • makePicture(picture) - makes a copy of a picture
  • uninit() - closes the connection to the robot

9) Removed color_rgb; use makeColor(r, g, b[, a]), Color(r, g, b[, a]). These can also take color names (eg, "red") or hexidecimal strings (eg, "#010203").

10) String color names should have a makeColor() wrapped around them: makeColor("name") or Color("name"). All of the W3C colors are valid, including the standards "black", "white", "red", "green", "blue", "gray", "darkGray", "lightGray", "yellow", "pink", "magenta", "cyan" and 100's more. To get list of all possible, use:

>>> getColorNames()

makeColor() and Color() can also take hexadecimal strings, such as "#ff0011". Must start with '#'.

11) Removed color names variables gray, black, white, etc. Use makeColor("gray") instead.

12) Added alpha support for all pixels and graphics, eg getRGBA(), arrow.color.alpha

13) You need to "from Graphics import *" to get all of Graphics; only subset is in the Myro module

14) GraphWin is now Window; use WindowClass to subclass

15) You can use a tuple or list where you used to have to use a Point instance

16) Speech now supports the following:

getVoices()         # returns a list of voice codes
getVoiceNames()     # returns a list of voice names showing language/gender, eg "English-US Female"
setVoice(code)      # takes a voice code
setVoiceName(name)  # takes a voice name
speak(text)         # speaks a voice in the set voice name/code
speak(text, async)  # speaks a voice asynchronously (1, the default) or synchronously (0). Synchronously will block until done speaking

There are more voice codes than listed as well. You can combine the base voice code with "+m1", "+m2", "+m3", "+m4", "+m5", "+m6", "+m7" (for different male voices), "+f1", "+f2", "+f3", "+f4", "+f5" (for different female voices), "+fast", "+klatt", "+klatt2", "+klatt3", "+whisper", "+whisperf" and "+croak"

For example:

speak("I see dead people.")

17) Python is 2.7, and uses / as true division, and includes the "with" statement and "print" function.

18) removed repaint() as it is not necessary as windows update automatically; If you must, use win.update() or show(pic) again

19) In chapter 11, page 295, in order to make 'freshegg' script work,

day,year = input("Enter the day,year: ") 

should be changed into:

day,year = eval(ask("Enter the day,year: "))

20) The line:

square = ask("Enter your move: ")-1

Should be:

square = eval(ask("Enter your move: ")) - 1

21) On page 170,

'From math import *' --> should be 'from math import *'

22) renamed move_to to moveTo, rotate_to to rotateTo, interval_update to intervalUpdate

23) The same color model is used in pictures and with graphics. Colors can be specified with names, or r,g,b[,a]:

>>> arrow = Arrow(Point(10, 10))
>>> arrow.draw(win)
>>> arrow.color = makeColor("red")    # dynamic change, fill and outline to red
>>> = 128           # dynamic change, fill and outline green components
>>> arrow.outline = makeColor("blue") # dynamic change, outline to blue
>>> arrow.fill.alpha = 50             # dynamic change, alpha of fill to 50
>>> pic = makePicture(10, 20)  
>>> pixel = getPixel(pic, 10, 10)
>>> color = getColor(pixel)              #
>>> = 255                      # dynamic change, red component is max
>>> color.alpha = 100                    # dynamic change, alpha to 100 (0 is transparent, 255 opaque)
>>> setColor(pixel, makeColor("yellow")) # dynamic change, pixel color to yellow

24) You can rotate, scale, and move graphics (pictures, lines, etc)

>>> obj.rotation = 90                    # dynamic change, rotate 90 degrees
>>> obj.scale = 1.2                      # dynamic change, scale by 1.2
>>> obj.x = 100                          # dynamic change, move center horizontal to 100
>>> obj.y = 150                          # dynamic change, move center vertical to 150

25) This no longer works:

>>> from Myro import *
>>> robot
<robot is undefined!>

You must now import Myro, and access it from there:

>>> import Myro
>>> Myro.robot

26) Image and Bitmap items were removed (used in converting Guzdial mediacomp image to Zelle object). Now do this:

>>> pic = makePicture(100, 200)   # or takePicture()
>>> pic.draw(win)                 # and treat like any other shape (rotate, scale, etc)

27) There is now an uninit() function which closes the robot connection.

28) Graphics objects: Arrow (looks like Logo turtle), Dot, Curve, Text, Line, Pen, Picture, Rectangle, Polygon, Circle, Oval, Pie, Arc, and Group

29) Can't draw a Point onto a window; use Dot instead

30) In chapter 10, page 254, change 'possibleMoves(board,player)' to 'possibleMoves(board)'


def gameOver(board):
    return len(possibleMoves(board)) == 0 or winner(board) != ' '

31) P263, missing parentheses: scores.append(lookahead(b,opponent(player),0,LEVEL-1))

32) getStall() only works when robot is moving; suggest removing from book, or changing example

33) All shapes have a penUp() and penDown(); penUp() returns a list of Points visited since penDown()

34) pic.color.[alpha, red, green, and blue] can be used to set the channel of a pic. For example:

>>> pic.border.alpha = 255
>>> pic.color.alpha = 128
>>> pic.fill.alpha = 0 

The last will make all pixels in a pic transparent.

35) shape.stackOnTop() and shape.stackOnBottom() changes the z-order of the drawn shapes

36) Supported: getMouse() => tuple, getWindow() => Window(), getWindow("title") => Window(), win.getMouse() => tuple

37) Window does not currently show x,y nor r,g,b,a; for now use:

def showPixel():
   click = getMouse()
   pixel = getPixel(pic, click[0], click[1])
   color = getColor(pixel)
   print("(x=%s, y=%s), r=%s, g=%s, b=%s, a=%s" % (pixel.x, pixel.y,,,, color.alpha))

38) New function getMouseNow() which returns (x,y) of mouse position (can be outside of window including negative numbers).

39) New callbacks that take (object, event):

  • win.onMouseMovement(func)
  • win.onMouseUp(func)
  • win.onClick(func)/win.onMouseDown(func) (handles click down)
  • win.onKeyPress(func)
  • win.onKeyRelease(func)

40) Window.mode is "auto", "manual" or "physics".

  • Use "win.step() with "manual" or "physics"
  • Nothing needed with "auto"
  • "physics" turns graphical objects into simulation in gravity, bounce, etc.

41) getKeyPressed() - returns last key name pressed, getKeyState(), getMouseState() - returns "up" or "down"

42) or

  • - a function that takes no arguments; can run forever
  • - calls step(.01) forever

43) print is now the function from Python 3.0

44) For randomness, use: getSeed(), setSeed(int), random()/randomNumber(). Seed is initially 0, which means that it starts randomly and can't be replicated.

45) Add getGamepad() and getGamePadNow() - works about the same as before:

  • getGamePad(index) - the index of gamepad (first is zero)
  • getGamePad(index, what) - what is "name", "axis", "ball", "button", "hat", "count"

getGamePad waits until something changes (up or down).

46) Gradient

from Graphics import *

win = Window()

sq = Rectangle((100, 100), (200, 200))
sq.gradient = Gradient("linear", (-50, 0), Color("red"), (50, 0), Color("blue"))

c = Circle((250, 250), 50)
c.gradient = Gradient("radial", (0, 0), 10, Color("red"),
                      (0, 0), 30, Color(0, 0, 0, 0))
c.outline = None

47) No calibrate(); not needed with Scribbler2



Please see Calico Bugs for a list of known issues.