Bitmap/Python: Difference between revisions

Content added Content deleted
(→‎Alternative version: since the default background is white, it makes sense to make the default paint color black (this is also required by Bitmap/Bresenham's_line_algorithm#Python))
m (Fixed syntax highlighting.)
 
Line 4: Line 4:


{{works with|python|2.4}}
{{works with|python|2.4}}
<lang Python>import sys # for stdout
<syntaxhighlight lang="python">import sys # for stdout


class c_color(object):
class c_color(object):
Line 65: Line 65:
result = self.pixels[y][x]
result = self.pixels[y][x]
assert type(result) is c_color
assert type(result) is c_color
return result</lang>
return result</syntaxhighlight>


===Alternative version===
===Alternative version===
Line 71: Line 71:


This makes use of named tuples and may well work with Python 2.6+ too.
This makes use of named tuples and may well work with Python 2.6+ too.
<lang python>from collections import namedtuple
<syntaxhighlight lang="python">from collections import namedtuple
from copy import copy
from copy import copy


Line 139: Line 139:
+--------------------+
+--------------------+


'''</lang>
'''</syntaxhighlight>