49 users online (1 members and 48 guests)  


  Results 1 to 4 of 4

Related

  1. search bar    Forum: HTML Forum
    Replies: 1
  2. Replies: 5
  3. SEARCH script not aligning in table correctly    Forum: Website Scripts Forum
    Replies: 4
  4. search engine that pay    Forum: Webmaster Ethics
    Replies: 1
  1. #1
    MrsKitty's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    2

    Lightbulb I need help with a search table!

    I would like to make (by myself, no "auto generate" sites, please- I want to learn) a table where I can search within it. For instance, If I have a table that has open fields, I can put "000|245|255" and it would come up with the RGB code for it, and also the closest codes within, say, 25 points.

    Like this:

    "Search" 000|245|255

    "Found" 10pts form Pure Cyan (000|255|255)

    Where could I find the resources to research and find coding for something like that?

    Thank You!

    ~~Kitty~~

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: I need help with a search table!

    I understand wanting to do this on your own. How else do you learn, right? So are you wanting to learn Javascript, or a server-side scripting language such as PHP or ASP?

    How are you determining the values that go in the table in the first place?

    The simplest way to do it (whatever language you use) is to store the values you are putting in the table in an array and search through the array as needed.

  3. #3
    MrsKitty's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    2

    Re: I need help with a search table!

    Well, I keep seeing PHP, so I think that's it. Um, as far as the table, I made one in Microsoft Works Datasheet and it's good and all to manually look through my lists but it really bites when I have to find a "similar" value, such as in my first post. I am attempting to make an actual html table with all of the values in it, I would like to know if I can use a search engine of sorts to make it easier...

    Thank You jthane!

  4. #4
    richardwilliams's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2009
    Posts
    1

    Re: I need help with a search table!

    So, you want to find out, given Red, Green, Blue values, what's the name of a color that's closest to these values.

    Very good idea. I recommend learing some scripting language.

    Here is a suggestion about how to do this.

    Store the file that you have created of colors in .CSV format, at, say, C:/colors.csv. I will assume the file has the following format.

    Red,255,0,0
    Green,0,255,0
    Blue,0,0,255
    Pure Cyan,000,255,255
    ...
    The following script will do the job. It is written in biterscripting. The idea is to take each color from the above list, calculate the "distance" between the RGB values of that color and the input color. Whichever color is the closest, its name will be printed.

    Code:
    # SCRIPT ClosestColor
    # Input arguments
    var int inR, inG, inB
    
    set $wsep = ","
    
    var int shortest, distance
    var str output
    
    # Go thru the color list, find the color that is the closest.
    # We will set $shortest to the highest value possible
    set $shortest = 256+256+256
    var str colors ; cat "C:/colors.csv" > $colors
    while ($colors <> "")
    do
        var str color ; lex -e "1" $colors > $color
        var str name ; var int R, G, B
        set $name = { wex -e -p "1" $color }
        set $R = makeint(str({wex -e -p "2" $color}))
        set $G = makeint(str({wex -e -p "3" $color}))
        set $B = makeint(str({wex -e -p "4" $color}))
    
        var int distanceR, distanceG, distanceB
        set $distanceR = ($R-$inR)
        if ($distanceR < 0)
            set $distanceR = -1 * $distanceR
        endif
    
        set $distanceG = ($G-$inG)
        if ($distanceG < 0)
            set $distanceG = -1 * $distanceG
        endif
    
        set $distanceB = ($B-$inB)
        if ($distanceB < 0)
            set $distanceB = -1 * $distanceB
        endif
    
        set $distance = $distanceR+$distanceG+$distanceB
        if ($distance < $shortest)
        do
            set $shortest = $distance
            set $output = $name
        done
        endif
        
    done
    
    # The closest color name is in $output.
    echo $output
    Save this script in a file C:/Scripts/ClosestColor.txt and call it from biterscripting as follows.

    script ClosestColor.txt R(0) G(255) B(0)

    The above should produce "Green".

    I have tested this script.

    You can even run this script as part of your web site. If you don't have biterscripting, download free at

    http://www.biterscripting.com/install.html




    Richard



Tags for this Thread