/ Published in: Python
See link for screenshot
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
colormode(HSB) class Icon(object): def __init__(self): self.width = 5 self.height = 5 self.pixels = [random(2) \ for i in xrange(self.width * self.height)] self._symmetrize() self.pixelsize = 8 self.fg_col = (random(1.0), random(0.4, 1.0), 0.25) self.bg_col = ((self.fg_col[0] + 0.2) % 1.0, self.fg_col[1], 1.0) def paint(self, x_pos=0, y_pos=0): nostroke() for y in xrange(self.height): for x in xrange(self.width): if self.pixels[x + self.width * y]: col = self.fg_col else: col = self.bg_col fill(color(col)) rect(x * self.pixelsize + x_pos, y * self.pixelsize + y_pos, self.pixelsize, self.pixelsize) def _symmetrize(self): for y in xrange(self.height): for x in xrange(int(self.width / 2), self.width): self.pixels[x + self.width * y] = \ self.pixels[(self.width - (x + 1)) + self.width * y] class IconGrid(object): def __init__(self, width, height): self.width = width self.height = height self.icons = [Icon() for x in xrange(self.width) \ for y in xrange(self.height)] def paint(self): for y in xrange(self.height): for x in xrange(self.width): icon = self.icons[x + y * self.width] pw = icon.width * (icon.pixelsize + 1) ph = icon.height * (icon.pixelsize + 1) icon.paint(x * pw, y * ph) grid = IconGrid(8, 13) grid.paint()
URL: http://dev.soup.io/post/281433