Changeset 10615 for src/django_gheat/wlheatmap
- Timestamp:
- Apr 29, 2012, 7:59:27 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/django_gheat/wlheatmap/tile.py
r9662 r10615 16 16 import time 17 17 18 # Rending with PIL and computation with numpy has proven to be to slow to be19 # usable, but is still in here for refence purposes.20 try:21 from PIL import Image22 import ImageDraw23 import numpy as np24 except ImportError:25 pass26 18 27 19 class PyGamePicture(): … … 70 62 pygame.draw.circle(new_surf,combined_colour,center,r,0) 71 63 self.surf.blit(new_surf,(0,0),special_flags=pygame.BLEND_RGBA_MAX) 72 73 74 class PILPicture():75 """ Basic PIL class, allowing simple image manipulations """76 im = None77 def __init__(self, method, size):78 self.im = Image.new(method, size)79 self.data = np.array(self.im)80 81 def write(self,fh,format='png'):82 self.im.save(fh,format)83 84 def make_circle(self,draw, center, radius,colour=(0,255,0)):85 """ Cicle gradient is created by creating smaller and smaller cicles """86 (center_x, center_y) = center87 for i in range(0,radius):88 draw.ellipse(89 (center_x - radius + i,90 center_y - radius + i,91 center_x + radius - i,92 center_y + radius - i93 ),94 colour +(255 * i/(radius * 2),)95 )96 97 def add_circle(self, center, radius, colour):98 """ Adding a new cicle is a matter of creating a new one in a empty layer99 and merging it with the current one100 101 XXX: Very heavy code, should actually only work on the data arrays, instead102 of doing all the magic with high-level images """103 104 im_new = Image.new("RGBA", self.im.size)105 draw = ImageDraw.Draw(im_new)106 self.make_circle(draw, center, radius, colour)107 108 data2 = np.array(im_new)109 110 # Add channels to make new images111 self.data = self.data + data2112 self.im = Image.fromarray(self.data)113 114 64 115 65
Note:
See TracChangeset
for help on using the changeset viewer.