[Microbit-Python] Image is hard to use

Larry Hastings larry at hastings.org
Mon Oct 5 09:46:03 CEST 2015



I can only create /so/ many Image objects before I get an 020 / the 
thing seizes up.  But once I've created an Image object, it's painful to 
change it.  My only option is the plodding set_pixel_value().  This is 
pretty painful if I want to make action-y games.

I suggest the following changes to the Image object:

  * Change the repr so it prints the internal array of pixels.
  * Remove "_value" from the names of Image object methods
    (set_pixel_value -> set_pixel, get_pixel_value -> get_pixel).
  * Add a .clear() method that sets all pixels to 0.
  * Add a .set(s) method that takes the same string as the constructor.
  * Add an .update(image) method that sets the image to be a copy of
    another.  (It'd change the dimensions too.)
  * Add a .copy(image, x, y) method that copies pixels from another
    image to the current image.  (This wouldn't change the dimensions of
    the original image.)  x, y would be the position to write the
    incoming image to.  If it can support optional parameters, it'd be
    nice to default x and y to 0.  It'd also be heavenly to add on:
      o "mode", which can be either OVERWRITE (set all pixels to the
        value of the image passed in), or BRIGHTEST (which would set the
        pixel to the brighter of either the original pixel or the
        incoming pixel).  Default would be OVERWRITE.
      o width, height, which would restrict the size of the image copied
        over.

I admit, if I only got one of .set(), .update(), or .copy(), I'd be 
pretty happy.


Finally: is that initializer for the Image your doing Damien, or is that 
from the HAL?  It's kind of wonky.  It'd be nice if I could have an 
array of arrays of integers.  Or five bytes, though I admit that might 
be painful for the students.

In particular: why is the initializer of the Image a string, but the 
"value" parameter of set_pixel_value an integer?  This is weirdly 
inconsistent.


//arry/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/mailman/private/microbit/attachments/20151005/aa6dacd2/attachment.html>


More information about the Microbit mailing list