$URL$
"""
import pygame
+from colorsys import hls_to_rgb
+from gradients import gradients
# TODO : positionner cette constance en fonction de la résolution d'affichage
+# externaliser la conf.
BORDER = 5 # 5px
+FIRST_HUE = 0.6
+OFF_LUMINANCE = 0.1
+OFF_SATURATION = 1
+ON_TOP_LUMINANCE = 0.9
+ON_BOTTOM_LUMINANCE = 0.6
+ON_SATURATION = 1
class _PlayingScreenBase(object) :
def __init__(self, distinctNotes=[]) :
triées du plus grave au plus aigu.
"""
self.distinctNotes = distinctNotes
+ self.keyboardLength = 0
self.keyboardRects = []
self._initRects()
self.drawColumns()
"""
ambitus = self.distinctNotes[-1].midi - self.distinctNotes[0].midi
if ambitus <= 12 :
- keyboardLength = 8
+ self.keyboardLength = 8
else :
- keyboardLength = 11
+ self.keyboardLength = 11
screen = pygame.display.get_surface()
dispWidth = screen.get_width() - 2 * BORDER
dispHeight = screen.get_height() - 2 * BORDER
- columnWidth = int(round(float(dispWidth) / keyboardLength))
+ columnWidth = int(round(float(dispWidth) / self.keyboardLength))
rects = []
- for i in range(keyboardLength) :
+ for i in range(self.keyboardLength) :
upperLeftCorner = (i*columnWidth + BORDER, BORDER)
rect = pygame.Rect(upperLeftCorner, (columnWidth, dispHeight))
rects.append(rect)
self.keyboardRects = rects
+
+ def _initColumns(self) :
+
+ hueStep = FIRST_HUE / (self.keyboardLength - 1)
+ for i, rect in enumerate(self.keyboardRects) :
+ hue = FIRST_HUE - hueStep * i
+ c = Column(hue)
def drawColumns(self) :
class SongPlayingScreen(_PlayingScreenBase) :
def __init__(self, song) :
- super(SongPlayingScreen, self).__init__(song.)
+ super(SongPlayingScreen, self).__init__(song.distinctNotes)
self.song = song
class Column(pygame.sprite.Sprite) :
- def __init__(self, color) :
- pass
\ No newline at end of file
+ def __init__(self, hue, rect) :
+ pygame.sprite.Sprite.__init__(self)
+ sur = Surface(rect.size)
+ rgba = hls_to_rgb(hue, OFF_LUMINANCE, OFF_SATURATION) + (255,)
+ sur.fill(rgba)
+ self.stateOff = sur
+
+ topRgba = hls_to_rgb(hue, ON_TOP_LUMINANCE, ON_SATURATION) + (255,)
+ bottomRgba = hls_to_rgb(hue, ON_BOTTOM_LUMINANCE, ON_SATURATION) + (255,)
+ size = rect.inflate(2*rect.width,0).size
+ self.stateOn = gradients.vertical(size, topRgba, bottomRgba)
+
\ No newline at end of file