Ignore:
Timestamp:
May 5, 2011, 11:13:51 AM (14 years ago)
Author:
rick
Message:

Conditional tranparenty, to make sure points with the same value have the same colour.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/django_gheat/website/tile.py

    r9150 r9151  
    55# Rick van der Zwet <info@rickvanderzwet.nl>
    66from django.core.management import setup_environ
     7from django.db.models import Max
    78from django.http import HttpResponse
    89from gheat.models import *
     
    4546
    4647
    47   def add_circle(self, center, radius, colour=(255,0,0)):
    48     # Quirky hack to generate lineair gradient circles and merge them with the parent.
     48  def add_circle(self, center, radius, colour=(255,0,0), transparancy=0):
     49    """
     50    Hack to add lineair gradient circles and merge with the parent. The
     51    transparancy can be configured to make the circles to fade out in the
     52    beginning
     53    """
     54    # Make calculations and ranges a whole bunch more easy
     55    radius = int(math.ceil(radius))
     56
    4957    new_surf = pygame.Surface(self.surf.get_size(),flags=pygame.SRCALPHA)
     58    alpha_per_radius = float(2.55 * (100 - transparancy)) / radius
    5059    for r in range(radius,1,-1):
    51       pygame.draw.circle(new_surf,colour + (255 - (r * (float(255)/radius)),),center,r,0)
     60      alpha = (radius - r) * alpha_per_radius
     61      pygame.draw.circle(new_surf,colour + (alpha,),center,r,0)
    5262    self.surf.blit(new_surf,(0,0),special_flags=pygame.BLEND_RGBA_MAX)
    5363
     
    182192     latitude__lte=nw_deg.lat,latitude__gte=se_deg.lat,
    183193     longitude__lte=se_deg.lon,longitude__gte=nw_deg.lon)
     194
     195  # XXX: Signal is not normalized in the database making it unknown when a
     196  # signal is said to be 100% or when it is actually less, currently seems to
     197  # copy the raw reported values
     198  MAX_SIGNAL = 50
    184199 
    185200  def dif(x,y):
     
    207222    # different patterns.
    208223    #
    209     im.add_circle((xcoord,ycoord),float(meting.signaal) / meters_per_pixel,(255,0,0))
     224    im.add_circle((xcoord,ycoord),float(meting.signaal) / meters_per_pixel,(255,0,0),MAX_SIGNAL - meting.signaal)
    210225 
    211226  log.info("BoundingBox NW: %s" % nw_deg)
Note: See TracChangeset for help on using the changeset viewer.