Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Wrote a Random Notepad++ Theme Generator!!!

Discussion in 'Scripting' started by drudiverse, Mar 22, 2016.

  1. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    I have just written a notepad++ theme RANDOM GENERATOR :DDD it runs in unity3d compiler at the moment and it can generate 1000ds of xml color templates by changing text colors of one theme, which is faster than searching online and DLing them, you have to specify roughly the brightness of bg and fg and it will generate the random colors, you can change the code to add fonts and some random saturation and value on top of the base values which are the brightness darkness preferences.
    2016-03-24_034622.jpg
    For reference, here is code of the N++ random theme generator, run it in unity3 and change the file paths. If you run it in a loop of 100 it will make 100 themes every time, it requires a notepad theme example file in the first path.

    JS:
    Code (csharp):
    1.  
    2.             var darks = 0.05; //base contrast , for the moment it's high contrast.
    3.             var brights = 0.95;//base contrast , for the moment it's high contrast.
    4.             var sat = 0.45; //  Saturation... .4 is pastel colors and .8 is distracting candy colors
    5.             //  hue will be random
    6.             var mediums = //base contrast , for the moment it's high contrast.
    7.  
    8.             var sourcexml :  String = "C:/Users/WorkStation/Documents/audiow/Assets/codes/Black board.xml";
    9.             var savetopath : String = "C:/Users/WorkStation/Documents/audiow/Assets/codes/" ;   //these are both paths
    10.  
    11.             function Start(){
    12.  
    13.             for (var i = 0; i < 1000 ; ++i) //Make 1000 themes in 2 seconds, now we're rolling:)
    14.             lineChanger();
    15.  
    16.  
    17.             }
    18.  
    19.                 function lineChanger()
    20.                     {
    21.                         var gobalDarkColor = RGBToHex(HSVtoRGB( Vector3( Random.value , sat , darks ) ) ) ;          
    22.                         var globalCommentColor = RGBToHex(HSVtoRGB( Vector3( Random.value , sat , brights*.75 )  ) ); // make comments a bit less bright with a multiplier on the value
    23.                         var arrLine : String[] = File.ReadAllLines(sourcexml);
    24.  
    25.                         for(s in arrLine ){ // Study a theme XML to see how to group color changes by keyword, wordstyle, commment, widgetstyle, global, are the 4 different styles i was going to use
    26.          
    27.                             if ( s.Contains("WordsStyle") && !s.Contains("COMMENT")){// general random colors and a background color
    28.              
    29.                                 var randomColor = RGBToHex(HSVtoRGB( Vector3( Random.value , sat , brights )  ) );
    30.                                 var pos = s.IndexOf( "bgColor=" );//change background color hex code
    31.                                 s= s.Remove(pos+9, 6).Insert(pos+9, gobalDarkColor);
    32.                                 pos = s.IndexOf( "fgColor=" );//change foreground color hex code
    33.                  
    34.                                 s= s.Remove(pos+9, 6).Insert(pos+9, randomColor);
    35.                  
    36.                  
    37.                             }
    38.              
    39.                             if ( s.Contains("WordsStyle") && s.Contains("COMMENT")){
    40.  
    41.                      // general random all same comment colors. can be less bright
    42.          
    43.          
    44.          
    45.                             }
    46.                             if ( s.Contains("WidgetStyle") && s.Contains("Global")){// has to be same background as uniform background from wordstyles
    47.                 //global color should be light or dark and it's the background of page outside of lines and spaces
    48.                             }
    49.              
    50.                             if ( s.Contains("WidgetStyle") && !s.Contains("Global")){// general random all same comment colors can be les bright
    51.          
    52.                                        //this is for tabs and selected lines, marked lines, and so forth in notepad, will perhaps finish this afterwards. Haven't figured out a presets for changing the colors of selected text, matching text markers and so on, however the current above code works a treat to make 1000ds of presets with different colors for the main text, and then just flip through 1000 presets to find one that matches mood, very nice indeed it's quite helpful for concentration, to have psychochromatic balanced colors on the text coding, it's like weaving friendship bracelets, in a programmatic way. :)
    53.                  
    54.          
    55.                             }
    56.  
    57.                         }
    58.                         File.WriteAllLines(savetopath+"ThemeGenV1_"+ Random.Range(0,60000).ToString() +".xml", arrLine);
    59.          
    60.  
    61.                 }
    62.  
    63.  
    64.             function Hue( H: float ): Vector3
    65.             {
    66.                 var R : float= Mathf.Abs(H * 6 - 3) - 1;
    67.                 var G : float= 2 - Mathf.Abs(H * 6 - 2);
    68.                 var B : float= 2 - Mathf.Abs(H * 6 - 4);
    69.                 return Vector3( Mathf.Clamp01(R),Mathf.Clamp01(G),Mathf.Clamp01(B) );
    70.             }
    71.  
    72.             function HSVtoRGB( HSV: Vector3): Vector4
    73.             {
    74.                 //return Vector4(((Hue(HSV.x) - 1) * HSV.y + 1) * HSV.z,1);
    75.                 var H = Hue(HSV.x) ;
    76.                 H= Vector3 (H.x-1, H.y-1, H.z-1)* HSV.y ;
    77.                 H= Vector3 (H.x + 1, H.y + 1, H.z + 1)* HSV.z;
    78.                 return Vector4(H.x, H.y, H.z,1);
    79.                     // return Vector4(Mathf.Floor(H.x*255), Mathf.Floor(H.y*255), Mathf.Floor(H.z*255),1);
    80.             }
    81.  
    82.             function rgb2hex(C:Vector4):String{
    83.  
    84.                 var rByte  = System.BitConverter.GetBytes(C.x * 256);
    85.                 var gByte = System.BitConverter.GetBytes(C.y * 256);
    86.                 var bByte = System.BitConverter.GetBytes(C.z * 256);
    87.  
    88.                 var rgb :String = rByte.ToString() + gByte.ToString() + bByte.ToString();
    89.             }
    90.  
    91.  
    92.             function GetHex (decimal : int) {
    93.                 alpha = "0123456789ABCDEF8";
    94.                     //print("val " + decimal);
    95.                 out = "" + alpha[decimal];
    96.                 return out;
    97.             };
    98.  
    99.             function HexToInt (hexChar : char) {
    100.                 var hex : String = "" + hexChar;
    101.                 switch (hex) {
    102.                     case "0": return 0;
    103.                     case "1": return 1;
    104.                     case "2": return 2;
    105.                     case "3": return 3;
    106.                     case "4": return 4;
    107.                     case "5": return 5;
    108.                     case "6": return 6;
    109.                     case "7": return 7;
    110.                     case "8": return 8;
    111.                     case "9": return 9;
    112.                     case "A": return 10;
    113.                     case "B": return 11;
    114.                     case "C": return 12;
    115.                     case "D": return 13;
    116.                     case "E": return 14;
    117.                     case "F": return 15;
    118.                 }
    119.             };
    120.  
    121.             function RGBToHex (color : Color):String {
    122.               red = color.r * 255;
    123.               green = color.g * 255;
    124.               blue = color.b * 255;
    125.  
    126.               a = GetHex(Mathf.Floor(red / 16));
    127.               b = GetHex(Mathf.Round(red % 16));
    128.               c = GetHex(Mathf.Floor(green / 16));
    129.               d = GetHex(Mathf.Round(green % 16));
    130.               e = GetHex(Mathf.Floor(blue / 16));
    131.               f = GetHex(Mathf.Round(blue % 16));
    132.  
    133.               z = a + b + c + d + e + f;
    134.  
    135.               return z;
    136.             };
     
    Last edited: Mar 25, 2016
  2. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    Last edited: Mar 24, 2016