Created
March 31, 2011 12:34
-
-
Save halcat0x15a/896279 to your computer and use it in GitHub Desktop.
SVGの色をIntシーケンスに。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private def color(node: Node, attr: String): Seq[Int] = { | |
val a = """#(.{2})(.{2})(.{2})""".r | |
val b = """#(.)(.)(.)""".r | |
val c = """rgb\((\d+)\,(\d+)\,(\d+)\)""".r | |
val d = """rgb\((\d+)%\,(\d+)%\,(\d+)%\)""".r | |
node.attribute(attr) map (_.text) orElse { | |
(node.attribute("style") map { style => | |
style.text.split(";") find (_.contains(attr)) map { str => | |
str.trim.split(":").last | |
} | |
}).get | |
} map (_ match { | |
case a(rgb @ _*) => rgb map (Integer.parseInt(_, 16)) | |
case b(rgb @ _*) => rgb map (s => Integer.parseInt(s * 2, 16)) | |
case c(rgb @ _*) => rgb map Integer.parseInt | |
case d(rgb @ _*) => rgb map (s => (s.toDouble * 255).toInt) | |
}) getOrElse Seq(0, 0, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment