Don't get me wrong, the theme-roller looks quite nice, but it does not work for me to create new themes at all.
What I want is: based upon theme-b create a new theme with the same look (shades, color saturation and so on) but in a different color. For example to make red buttons, green buttons and so on.. this is not possible in a few steps with the theme roller, since you have to insert all colors by hand and find out what they are with a seperate tool.
If you only want the same theme but in a different color, I have the solution for you.
This code snipped snipped takes an existing swatch (for extample theme-b) and adjusts all colors to a new hue (according to the HSL-specifications). Then it renames all css-classes and comments for you to easy copy-paste the generated code into your existing css file. voila, you have a new swatch in another color.
For example. hue "120" is for green, hue "360" is for red. Try taking swatch b and set the new hue to 120. you will have a copy of the theme b but colored in a green, that looks like the original blue..
Instructions:
1. Create a new HTML File with jQuery libraries ready to use
2. Paste this code in the body section of your html file:
- source<br/>
- <textarea name="csstext" id="csstext" style="width: 100px; height: 100px;"></textarea><br/>
- new Hue Value (0-360) <input name="newhue" id="newhue"/><br/>
- old data theme (a,b,c etc) <input name="oldtheme" id="oldtheme"/><br/>
- new data theme (f,g,h etc) <input name="newtheme" id="newtheme"/><br/>
- <button name="generate" id="generate">Generate!</button>
- <br/>
- <textarea name="result" id="result" style="width: 100px; height: 100px;"></textarea>
3. paste a valid css theme from the jquery mobile css file into the first textarea, preferable is the theme 'b' from the default themes
4. enter 'b' in the next text-input
5. enter 'f' in the second text-input
6. hit 'generate'
7. copy the generated code and add it to your jquery mobile css file
JS code to be copied on the bottom of your html file inside <script></script>:
- function hexToRgb(hex) {
- var r = parseInt(hex.substr(1,2), 16); // Grab the hex representation of red (chars 1-2) and convert to decimal (base 10).
- var g = parseInt(hex.substr(3,2), 16);
- var b = parseInt(hex.substr(5,2), 16);
- return { r: r, g: g, b: b};
- }
- function RGBtoHex(R,G,B) {
- return '#' + toHex(R)+toHex(G)+toHex(B);
- }
- function toHex(N) {
- if (N==null){
- return "00";
- }
- N=Math.round(N);
- N=parseInt(N);
- if (N==0 || isNaN(N)) {
- return "00";
- }
- N=Math.max(0,N);
- N=Math.min(N,255);
- N=Math.round(N);
- return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
- }
- function rgbToHsl(r, g, b){
- r /= 255, g /= 255, b /= 255;
- var max = Math.max(r, g, b), min = Math.min(r, g, b);
- var h, s, l = (max + min) / 2;
- if(max == min){
- h = s = 0; // achromatic
- }else{
- var d = max - min;
- s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
- switch(max){
- case r: h = (g - b) / d + (g < b ? 6 : 0); break;
- case g: h = (b - r) / d + 2; break;
- case b: h = (r - g) / d + 4; break;
- }
- h /= 6;
- }
- return new hsl(h,s,l);
- //return { h: h, s: s, l: l };
- }
- /**
- * Converts an HSL color value to RGB. Conversion formula
- * adapted from http://en.wikipedia.org/wiki/HSL_color_space.
- * Assumes h, s, and l are contained in the set [0, 1] and
- * returns r, g, and b in the set [0, 255].
- *
- * @param Number h The hue
- * @param Number s The saturation
- * @param Number l The lightness
- * @return Array The RGB representation
- */
- function hslToRgb(h, s, l){
- var r, g, b;
- if(s == 0){
- r = g = b = l; // achromatic
- }else{
- function hue2rgb(p, q, t){
- if(t < 0) t += 1;
- if(t > 1) t -= 1;
- if(t < 1/6) return p + (q - p) * 6 * t;
- if(t < 1/2) return q;
- if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
- return p;
- }
- var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
- var p = 2 * l - q;
- r = hue2rgb(p, q, h + 1/3);
- g = hue2rgb(p, q, h);
- b = hue2rgb(p, q, h - 1/3);
- }
- return { r: r * 255, g: g * 255, b: b * 255 };
- }
- function hsl(h,s,l) {
- this.h = h;
- this.s = s;
- this.l = l;
- this.setHasDeg = function(degree) {
- this.hdeg = degree / 360;
- }
- }
- $(document).ready(function() {
- $('#generate').click(function(){
- var cssFile = $('#csstext').val();
- var newHue = $('#newhue').val();
- var result = $('#result');
- var oldTheme = $('#oldtheme').val();
- var newTheme = $('#newtheme').val();
-
- function replaceCallback(color){
- console.log('changing: ' + color);
- color = hexToRgb(color);
- color = rgbToHsl(color.r,color.g,color.b);
- color.h = (newHue / 360);
- color = hslToRgb(color.h,color.s,color.l);
- color = RGBtoHex(color.r,color.g,color.b);
- console.log('changed to: ' + color);
- return color;
- }
-
- cssFile = cssFile.replace(/#[0-9A-Fa-f]{6}/g, replaceCallback);
- cssFile = cssFile.replace(new RegExp("-" + oldTheme + " ", "g"), "-" + newTheme + " "); // z.B: .ui-bar-f --> .ui-bar-t
- cssFile = cssFile.replace(new RegExp("-" + oldTheme + ",", "g"), "-" + newTheme + ","); // z.B: .ui-bar-f, --> .ui-bar-f,
- cssFile = cssFile.replace(new RegExp("{" + oldTheme + "-", "g"), "{" + newTheme + "-"); // convert comments to keep compatible with the theme-roller
- //cssFile = cssFile.replace(new RegExp("/\/\* " + oldTheme.toUpperCase() + "/", "g"), "/* " + newTheme.toUpperCase()); // Header line..
- result.val(cssFile);
- });
- });
Note: I didn't make the rgb/hex/hsl conversion fuctions, I just modified them a bit. Copyright to the authors.
Note: The regex to find colors is pretty simple and only matches colors, that have 7 letters, eg #01Ab3f . adjust the regex to match all valid colors if you want.
Note: hue-modification only affects colors. Black, White and Greytones are not colors according to HSL and will therefor not change. Read some wikipedia articels if you want to know more.