@@ -42,18 +42,30 @@ def clamp(value):
4242 return min (max (value , 0 ), 1 )
4343
4444
45+ def lookup_pen_color (pen_color_value , explicit_color_rgba ):
46+ if explicit_color_rgba is not None :
47+ return explicit_color_rgba
48+ if pen_color_value in RM_PALETTE :
49+ color = RM_PALETTE [pen_color_value ]
50+ else :
51+ _logger .warning ("Unknown pen color: %s" , pen_color_value )
52+ color = RM_PALETTE [PenColor .BLACK ]
53+ if len (color ) == 3 :
54+ return (* color , 255 )
55+ else :
56+ return color
57+
58+
4559class Pen :
46- def __init__ (self , name , base_width , base_color_id ):
60+ def __init__ (self , name , base_width , base_color ):
4761 self .base_width = base_width
48- self .base_color = RM_PALETTE [ base_color_id ]
62+ self .base_color = base_color # rgba
4963 self .name = name
5064 self .segment_length = 1000
5165 self .base_opacity = 1
5266 # initial stroke values
5367 self .stroke_linecap = "round"
5468 self .stroke_opacity = 1
55- self .stroke_width = base_width
56- self .stroke_color = base_color_id
5769
5870 # note that the units of the points have had their units converted
5971 # in scene_stream.py
@@ -75,7 +87,7 @@ def get_segment_width(self, speed, direction, width, pressure, last_width):
7587 return self .base_width
7688
7789 def get_segment_color (self , speed , direction , width , pressure , last_width ):
78- return "rgb " + str (tuple (self .base_color ))
90+ return "rgba " + str (tuple (self .base_color ))
7991
8092 def get_segment_opacity (self , speed , direction , width , pressure , last_width ):
8193 return self .base_opacity
@@ -122,13 +134,13 @@ def create(cls, pen_nr, color_id, width):
122134
123135
124136class Fineliner (Pen ):
125- def __init__ (self , base_width , base_color_id ):
126- super ().__init__ ("Fineliner" , base_width * 1.8 , base_color_id )
137+ def __init__ (self , base_width , base_color ):
138+ super ().__init__ ("Fineliner" , base_width * 1.8 , base_color )
127139
128140
129141class Ballpoint (Pen ):
130- def __init__ (self , base_width , base_color_id ):
131- super ().__init__ ("Ballpoint" , base_width , base_color_id )
142+ def __init__ (self , base_width , base_color ):
143+ super ().__init__ ("Ballpoint" , base_width , base_color )
132144 self .segment_length = 5
133145
134146 def get_segment_width (self , speed , direction , width , pressure , last_width ):
@@ -151,8 +163,8 @@ def get_segment_color(self, speed, direction, width, pressure, last_width):
151163
152164
153165class Marker (Pen ):
154- def __init__ (self , base_width , base_color_id ):
155- super ().__init__ ("Marker" , base_width , base_color_id )
166+ def __init__ (self , base_width , base_color ):
167+ super ().__init__ ("Marker" , base_width , base_color )
156168 self .segment_length = 3
157169
158170 def get_segment_width (self , speed , direction , width , pressure , last_width ):
@@ -161,8 +173,8 @@ def get_segment_width(self, speed, direction, width, pressure, last_width):
161173
162174
163175class Pencil (Pen ):
164- def __init__ (self , base_width , base_color_id ):
165- super ().__init__ ("Pencil" , base_width , base_color_id )
176+ def __init__ (self , base_width , base_color ):
177+ super ().__init__ ("Pencil" , base_width , base_color )
166178 self .segment_length = 2
167179
168180 def get_segment_width (self , speed , direction , width , pressure , last_width ):
@@ -180,14 +192,14 @@ def get_segment_opacity(self, speed, direction, width, pressure, last_width):
180192
181193
182194class MechanicalPencil (Pen ):
183- def __init__ (self , base_width , base_color_id ):
184- super ().__init__ ("Mechanical Pencil" , base_width ** 2 , base_color_id )
195+ def __init__ (self , base_width , base_color ):
196+ super ().__init__ ("Mechanical Pencil" , base_width ** 2 , base_color )
185197 self .base_opacity = 0.7
186198
187199
188200class Brush (Pen ):
189- def __init__ (self , base_width , base_color_id ):
190- super ().__init__ ("Brush" , base_width , base_color_id )
201+ def __init__ (self , base_width , base_color ):
202+ super ().__init__ ("Brush" , base_width , base_color )
191203 self .segment_length = 2
192204 self .stroke_linecap = "round"
193205 self .opacity = 1
@@ -205,44 +217,45 @@ def get_segment_color(self, speed, direction, width, pressure, last_width):
205217 rev_intensity = abs (intensity - 1 )
206218 segment_color = [int (rev_intensity * (255 - self .base_color [0 ])),
207219 int (rev_intensity * (255 - self .base_color [1 ])),
208- int (rev_intensity * (255 - self .base_color [2 ]))]
220+ int (rev_intensity * (255 - self .base_color [2 ])),
221+ self .base_color [3 ]]
209222
210- return "rgb " + str (tuple (segment_color ))
223+ return "rgba " + str (tuple (segment_color ))
211224
212225
213226class Highlighter (Pen ):
214- def __init__ (self , base_width , base_color_id ):
215- super ().__init__ ("Highlighter" , base_width , base_color_id )
227+ def __init__ (self , base_width , base_color ):
228+ super ().__init__ ("Highlighter" , base_width , base_color )
216229 self .stroke_linecap = "square"
217230 self .base_opacity = 0.3
218231 self .stroke_opacity = 0.2
219232
220233
221234class Shader (Pen ):
222235
223- def __init__ (self , base_width , base_color_id ):
224- super ().__init__ ("Shader" , base_width , base_color_id )
236+ def __init__ (self , base_width , base_color ):
237+ super ().__init__ ("Shader" , base_width , base_color )
225238 self .stroke_linecap = "round"
226239 self .base_opacity = 0.1
227240 # self.stroke_opacity = 0.2
228241 self .name = "Shader"
229242
230243class Eraser (Pen ):
231- def __init__ (self , base_width , base_color_id ):
232- super ().__init__ ("Eraser" , base_width * 2 , base_color_id )
244+ def __init__ (self , base_width , base_color ):
245+ super ().__init__ ("Eraser" , base_width * 2 , base_color )
233246 self .stroke_linecap = "square"
234247
235248
236249class EraseArea (Pen ):
237- def __init__ (self , base_width , base_color_id ):
238- super ().__init__ ("Erase Area" , base_width , base_color_id )
250+ def __init__ (self , base_width , base_color ):
251+ super ().__init__ ("Erase Area" , base_width , base_color )
239252 self .stroke_linecap = "square"
240253 self .base_opacity = 0
241254
242255
243256class Calligraphy (Pen ):
244- def __init__ (self , base_width , base_color_id ):
245- super ().__init__ ("Calligraphy" , base_width , base_color_id )
257+ def __init__ (self , base_width , base_color ):
258+ super ().__init__ ("Calligraphy" , base_width , base_color )
246259 self .segment_length = 2
247260
248261 def get_segment_width (self , speed , direction , width , pressure , last_width ):
0 commit comments