Created
January 8, 2013 05:17
-
-
Save uakihir0/4481432 to your computer and use it in GitHub Desktop.
TheWorld のテーマ設定で用いられているカラー暗号化の仕組みのコードです。
いつか、JSか何かでWebで綺麗に再現できるような支援機構を作ります。
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
// We Cannot Use "{" & "}" & "," | |
static NSString *_IndList[300] = { | |
@"⠀", @"⠁", @"⠂", @"⠃", @"⠄", @"⠅", @"⠆", @"⠇", @"⠈", @"⠉", | |
@"⠊", @"⠋", @"⠌", @"⠍", @"⠎", @"⠏", @"⠐", @"⠑", @"⠒", @"⠓", | |
@"⠔", @"⠕", @"⠖", @"⠗", @"⠘", @"⠙", @"⠚", @"⠛", @"⠜", @"⠝", | |
@"⠞", @"⠟", | |
@"⠠", @"⠡", @"⠢", @"⠣", @"⠤", @"⠥", @"⠦", @"⠧", @"⠨", @"⠩", | |
@"⠪", @"⠫", @"⠬", @"⠭", @"⠮", @"⠯", @"⠰", @"⠱", @"⠲", @"⠳", | |
@"⠴", @"⠵", @"⠶", @"⠷", @"⠸", @"⠹", @"⠺", @"⠻", @"⠼", @"⠽", | |
@"⠾", @"⠿", | |
@"⡀", @"⡁", @"⡂", @"⡃", @"⡄", @"⡅", @"⡆", @"⡇", @"⡈", @"⡉", | |
@"⡊", @"⡋", @"⡌", @"⡍", @"⡎", @"⡏", @"⡐", @"⡑", @"⡒", @"⡓", | |
@"⡔", @"⡕", @"⡖", @"⡗", @"⡘", @"⡙", @"⡚", @"⡛", @"⡜", @"⡝", | |
@"⡞", @"⡟", | |
@"⡠", @"⡡", @"⡢", @"⡣", @"⡤", @"⡥", @"⡦", @"⡧", @"⡨", @"⡩", | |
@"⡪", @"⡫", @"⡬", @"⡭", @"⡮", @"⡯", @"⡰", @"⡱", @"⡲", @"⡳", | |
@"⡴", @"⡵", @"⡶", @"⡷", @"⡸", @"⡹", @"⡺", @"⡻", @"⡼", @"⡽", | |
@"⡾", @"⡿", | |
@"⢀", @"⢁", @"⢂", @"⢃", @"⢄", @"⢅", @"⢆", @"⢇", @"⢈", @"⢉", | |
@"⢊", @"⢋", @"⢌", @"⢍", @"⢎", @"⢏", @"⢐", @"⢑", @"⢒", @"⢓", | |
@"⢔", @"⢕", @"⢖", @"⢗", @"⢘", @"⢙", @"⢚", @"⢛", @"⢜", @"⢝", | |
@"⢞", @"⢟", | |
@"⢠", @"⢡", @"⢢", @"⢣", @"⢤", @"⢥", @"⢦", @"⢧", @"⢨", @"⢩", | |
@"⢪", @"⢫", @"⢬", @"⢭", @"⢮", @"⢯", @"⢰", @"⢱", @"⢲", @"⢳", | |
@"⢴", @"⢵", @"⢶", @"⢷", @"⢸", @"⢹", @"⢺", @"⢻", @"⢼", @"⢽", | |
@"⢾", @"⢿", | |
@"⣀", @"⣁", @"⣂", @"⣃", @"⣄", @"⣅", @"⣆", @"⣇", @"⣈", @"⣉", | |
@"⣊", @"⣋", @"⣌", @"⣍", @"⣎", @"⣏", @"⣐", @"⣑", @"⣒", @"⣓", | |
@"⣔", @"⣕", @"⣖", @"⣗", @"⣘", @"⣙", @"⣚", @"⣛", @"⣜", @"⣝", | |
@"⣞", @"⣟", | |
@"⣠", @"⣡", @"⣢", @"⣣", @"⣤", @"⣥", @"⣦", @"⣧", @"⣨", @"⣩", | |
@"⣪", @"⣫", @"⣬", @"⣭", @"⣮", @"⣯", @"⣰", @"⣱", @"⣲", @"⣳", | |
@"⣴", @"⣵", @"⣶", @"⣷", @"⣸", @"⣹", @"⣺", @"⣻", @"⣼", @"⣽", | |
@"⣾", @"⣿", | |
}; | |
// #################################################################################### | |
+ (int)getIndexFromChar:(NSString *)str{ | |
for(int i=0; i<256; i++){ | |
if([_IndList[i] isEqualToString:str]) return i; } | |
return 0; } | |
// #################################################################################### | |
+ (NSString *)colorToString:(UIColor *)color{ | |
const CGFloat *_com = CGColorGetComponents(color.CGColor); | |
UInt8 _r = (UInt8)(_com[0] * 255.f); | |
UInt8 _g = (UInt8)(_com[1] * 255.f); | |
UInt8 _b = (UInt8)(_com[2] * 255.f); | |
return [NSString stringWithFormat:@"%@%@%@", | |
_IndList[_r],_IndList[_g],_IndList[_b]]; | |
} | |
// #################################################################################### | |
+ (UIColor *)stringToColor:(NSString *)str{ | |
NSString *_rs = [str substringWithRange:NSMakeRange(0, 1)]; | |
NSString *_gs = [str substringWithRange:NSMakeRange(1, 1)]; | |
NSString *_bs = [str substringWithRange:NSMakeRange(2, 1)]; | |
float _r = ((float)[ThemeData getIndexFromChar:_rs]) / 255.f; | |
float _g = ((float)[ThemeData getIndexFromChar:_gs]) / 255.f; | |
float _b = ((float)[ThemeData getIndexFromChar:_bs]) / 255.f; | |
return [UIColor colorWithRed:_r green:_g blue:_b alpha:1.f]; } | |
// #################################################################################### | |
- (NSString *)makeStringFtomTheme{ | |
NSMutableArray *_ary = [NSMutableArray array]; | |
[_ary addObject:[ThemeData colorToString:mainColor]]; | |
[_ary addObject:[ThemeData colorToString:subColor]]; | |
[_ary addObject:[ThemeData colorToString:impColor]]; | |
[_ary addObject:[ThemeData colorToString:btnColor1]]; | |
[_ary addObject:[ThemeData colorToString:btnColor2]]; | |
[_ary addObject:[ThemeData colorToString:btnColor3]]; | |
[_ary addObject:[ThemeData colorToString:exBackGround]]; | |
[_ary addObject:[ThemeData colorToString:exBtnTextColor]]; | |
[_ary addObject:[ThemeData colorToString:exImageColor]]; | |
[_ary addObject:[ThemeData colorToString:exTintColor]]; | |
[_ary addObject:[ThemeData colorToString:exLineColor]]; | |
[_ary addObject:[ThemeData colorToString:exBarColor]]; | |
[_ary addObject:[ThemeData colorToString:exPopBackGround]]; | |
[_ary addObject:[ThemeData colorToString:exPopTextColor]]; | |
NSString *_str = [_ary componentsJoinedByString:@""]; | |
return [NSString stringWithFormat:@"#TWTheme {%@,%@}",name,_str]; | |
} | |
// #################################################################################### | |
+ (ThemeData *)makeThemeFromString:(NSString *)str{ | |
ThemeData *_theme = [[ThemeData alloc] init]; | |
NSString *reg = nil; | |
NSError *error = nil; | |
NSRegularExpression *regexp = nil; | |
NSTextCheckingResult *match = nil; | |
// Reg Exp | |
reg = @"#TWTheme \\{(.+?),(.+)\\}"; | |
regexp = [NSRegularExpression regularExpressionWithPattern:reg options:0 error:&error]; | |
match = [regexp firstMatchInString:str options:0 range:NSMakeRange(0, str.length)]; | |
if(match.numberOfRanges > 1){ | |
_theme.name = [str substringWithRange:[match rangeAtIndex:1]]; | |
str = [str substringWithRange:[match rangeAtIndex:2]]; } | |
NSMutableArray *_ary = [NSMutableArray array]; | |
if((str.length % 3) != 0) return nil; | |
while(str.length != 3){ | |
[_ary addObject:[str substringToIndex:3]]; | |
str = [str substringFromIndex:3]; } | |
[_ary addObject:str]; | |
if([_ary count] != CL_COLOR_NUMBER) return nil; | |
_theme.mainColor = [ThemeData stringToColor:[_ary objectAtIndex:0]]; | |
_theme.subColor = [ThemeData stringToColor:[_ary objectAtIndex:1]]; | |
_theme.impColor = [ThemeData stringToColor:[_ary objectAtIndex:2]]; | |
_theme.btnColor1 = [ThemeData stringToColor:[_ary objectAtIndex:3]]; | |
_theme.btnColor2 = [ThemeData stringToColor:[_ary objectAtIndex:4]]; | |
_theme.btnColor3 = [ThemeData stringToColor:[_ary objectAtIndex:5]]; | |
_theme.exBackGround = [ThemeData stringToColor:[_ary objectAtIndex:6]]; | |
_theme.exBtnTextColor = [ThemeData stringToColor:[_ary objectAtIndex:7]]; | |
_theme.exImageColor = [ThemeData stringToColor:[_ary objectAtIndex:8]]; | |
_theme.exTintColor = [ThemeData stringToColor:[_ary objectAtIndex:9]]; | |
_theme.exLineColor = [ThemeData stringToColor:[_ary objectAtIndex:10]]; | |
_theme.exBarColor = [ThemeData stringToColor:[_ary objectAtIndex:11]]; | |
_theme.exPopBackGround = [ThemeData stringToColor:[_ary objectAtIndex:12]]; | |
_theme.exPopTextColor = [ThemeData stringToColor:[_ary objectAtIndex:13]]; | |
return _theme; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment