1bf002cc3df3224ea9e858afda7edc145810b2cb
1 # -*- coding: utf-8 -*-
4 bandes arc-en-ciel représentant un clavier.
10 from colorsys
import hls_to_rgb
11 from gradients
import gradients
12 # TODO : positionner cette constance en fonction de la résolution d'affichage
13 # externaliser la conf.
18 ON_TOP_LUMINANCE
= 0.9
19 ON_BOTTOM_LUMINANCE
= 0.6
22 class _PlayingScreenBase(object) :
23 def __init__(self
, distinctNotes
=[]) :
25 distinctNotes : notes disctinctes présentes dans la chanson
26 triées du plus grave au plus aigu.
28 self
.distinctNotes
= distinctNotes
29 self
.keyboardLength
= 0
30 self
.keyboardRects
= []
35 def _initRects(self
) :
36 """ création des espaces réservés pour
37 afficher les colonnes.
39 ambitus
= self
.distinctNotes
[-1].midi
- self
.distinctNotes
[0].midi
41 self
.keyboardLength
= 8
43 self
.keyboardLength
= 11
45 screen
= pygame
.display
.get_surface()
47 # taille de la zone d'affichage utile (bordure autour)
48 dispWidth
= screen
.get_width() - 2 * BORDER
49 dispHeight
= screen
.get_height() - 2 * BORDER
51 columnWidth
= int(round(float(dispWidth
) / self
.keyboardLength
))
54 for i
in range(self
.keyboardLength
) :
55 upperLeftCorner
= (i
*columnWidth
+ BORDER
, BORDER
)
56 rect
= pygame
.Rect(upperLeftCorner
, (columnWidth
, dispHeight
))
59 self
.keyboardRects
= rects
61 def _initColumns(self
) :
63 hueStep
= FIRST_HUE
/ (self
.keyboardLength
- 1)
64 for i
, rect
in enumerate(self
.keyboardRects
) :
65 hue
= FIRST_HUE
- hueStep
* i
69 def drawColumns(self
) :
72 def highLightColumn(self
) :
76 class SongPlayingScreen(_PlayingScreenBase
) :
78 def __init__(self
, song
) :
79 super(SongPlayingScreen
, self
).__init
__(song
.distinctNotes
)
84 class Column(pygame
.sprite
.Sprite
) :
86 def __init__(self
, hue
, rect
) :
87 pygame
.sprite
.Sprite
.__init
__(self
)
88 sur
= Surface(rect
.size
)
89 rgba
= hls_to_rgb(hue
, OFF_LUMINANCE
, OFF_SATURATION
) + (255,)
93 topRgba
= hls_to_rgb(hue
, ON_TOP_LUMINANCE
, ON_SATURATION
) + (255,)
94 bottomRgba
= hls_to_rgb(hue
, ON_BOTTOM_LUMINANCE
, ON_SATURATION
) + (255,)
95 size
= rect
.inflate(2*rect
.width
,0).size
96 self
.stateOn
= gradients
.vertical(size
, topRgba
, bottomRgba
)