-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradient_box.py
More file actions
29 lines (22 loc) · 820 Bytes
/
gradient_box.py
File metadata and controls
29 lines (22 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding: utf-8
# In[1]:
from __future__ import division
import sfml
# In[3]:
class GradientBox(sfml.TransformableDrawable):
def __init__(self, nodes):
assert nodes > 1
self.nodes = nodes
self.vertices = sfml.VertexArray(sfml.PrimitiveType.TRIANGLES_STRIP,nodes*2)
for i in range(nodes):
x = i/(nodes-1)
self.vertices[2*i].position = sfml.Vector2(x,0.0)
self.vertices[2*i+1].position = sfml.Vector2(x,1.0)
def colourise(self,colouriser):
for i in range(self.nodes):
colour = colouriser(i/(self.nodes-1))
self.vertices[2*i].color = colour
self.vertices[2*i+1].color = colour
def draw(self,target,states):
states.transform *= self.transform
target.draw(self.vertices,states)