sumolib.color
1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 2# Copyright (C) 2012-2026 German Aerospace Center (DLR) and others. 3# This program and the accompanying materials are made available under the 4# terms of the Eclipse Public License 2.0 which is available at 5# https://www.eclipse.org/legal/epl-2.0/ 6# This Source Code may also be made available under the following Secondary 7# Licenses when the conditions for such availability set forth in the Eclipse 8# Public License 2.0 are satisfied: GNU General Public License, version 2 9# or later which is available at 10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 12 13# @file color.py 14# @author Daniel Krajzewicz 15# @author Michael Behrisch 16# @date 2012-12-04 17 18from __future__ import absolute_import 19 20 21class RGBAColor: 22 23 def __init__(self, r, g, b, a=None): 24 self.r = r 25 self.g = g 26 self.b = b 27 self.a = a 28 29 def toXML(self): 30 if self.a is not None: 31 return "%s,%s,%s,%s" % (self.r, self.g, self.b, self.a) 32 else: 33 return "%s,%s,%s" % (self.r, self.g, self.b) 34 35 36def decodeXML(c): 37 colorSwitch = { 38 "red": RGBAColor(255, 0, 0, 255), 39 "green": RGBAColor(0, 255, 0, 255), 40 "blue": RGBAColor(0, 0, 255, 255), 41 "yellow": RGBAColor(255, 255, 0, 255), 42 "cyan": RGBAColor(0, 255, 255, 255), 43 "magenta": RGBAColor(255, 0, 255, 255), 44 "orange": RGBAColor(255, 128, 0, 255), 45 "white": RGBAColor(255, 255, 255, 255), 46 "black": RGBAColor(0, 0, 0, 255), 47 "grey": RGBAColor(128, 128, 128, 255), 48 "gray": RGBAColor(128, 128, 128, 255), 49 "invisible": RGBAColor(0, 0, 0, 0) 50 } 51 knownColor = colorSwitch.get(c) 52 if knownColor is None: 53 return RGBAColor(*[float(x) for x in c.split(",")]) 54 return knownColor
class
RGBAColor:
22class RGBAColor: 23 24 def __init__(self, r, g, b, a=None): 25 self.r = r 26 self.g = g 27 self.b = b 28 self.a = a 29 30 def toXML(self): 31 if self.a is not None: 32 return "%s,%s,%s,%s" % (self.r, self.g, self.b, self.a) 33 else: 34 return "%s,%s,%s" % (self.r, self.g, self.b)
def
decodeXML(c):
37def decodeXML(c): 38 colorSwitch = { 39 "red": RGBAColor(255, 0, 0, 255), 40 "green": RGBAColor(0, 255, 0, 255), 41 "blue": RGBAColor(0, 0, 255, 255), 42 "yellow": RGBAColor(255, 255, 0, 255), 43 "cyan": RGBAColor(0, 255, 255, 255), 44 "magenta": RGBAColor(255, 0, 255, 255), 45 "orange": RGBAColor(255, 128, 0, 255), 46 "white": RGBAColor(255, 255, 255, 255), 47 "black": RGBAColor(0, 0, 0, 255), 48 "grey": RGBAColor(128, 128, 128, 255), 49 "gray": RGBAColor(128, 128, 128, 255), 50 "invisible": RGBAColor(0, 0, 0, 0) 51 } 52 knownColor = colorSwitch.get(c) 53 if knownColor is None: 54 return RGBAColor(*[float(x) for x in c.split(",")]) 55 return knownColor