Question

In: Computer Science

I need assistance in making a simple html and php script that lets a user explor...

I need assistance in making a simple html and php script that lets a user explor the RGB color specturum. It should be able to use 6 buttons (R+,G+,B+,R-,G-,B-) that when pressed, add or subtract 2 points (ranging from 0-255) of that color from the RGB ratio. The new RGB color is then displayed in a small window/box at the bottom of the page for the user to see. This should allow the user to explore all the different colors by changing the amount of R(red), G(green), and B(blue) amounts. If theres anything I can do to help please let me know, thank you!

Solutions

Expert Solution

<?php
session_start();
if (!isset($_GET['action']))
{
    $_SESSION["R"] = 0;
    $_SESSION["G"] = 0;
    $_SESSION["B"] = 244;

}

function checkLimit(int $a)
{
    if ($a >= 0 && $a <= 255)
    {
        return True;
    }
    return False;
}
if (isset($_GET['action']))
{

    if ($_GET['action'] == 'R+')
    {
        if (checkLimit($_SESSION["R"] + 2))
        {
            $_SESSION["R"] = $_SESSION["R"] + 2;
        }

    }
    elseif ($_GET['action'] == 'G+')
    {
        if (checkLimit($_SESSION["G"] + 2))
        {
            $_SESSION["G"] = $_SESSION["G"] + 2;
        }

    }
    elseif ($_GET['action'] == 'B+')
    {
        if (checkLimit($_SESSION["B"] + 2))
        {
            $_SESSION["B"] = $_SESSION["B"] + 2;
        }
    }
    elseif ($_GET['action'] == 'R-')
    {
        if (checkLimit($_SESSION["R"] - 2))
        {
            $_SESSION["R"] = $_SESSION["R"] - 2;
        }
    }
    elseif ($_GET['action'] == 'G-')
    {
        if (checkLimit($_SESSION["G"] - 2))
        {
            $_SESSION["G"] = $_SESSION["G"] - 2;
        }
    }
    else
    {
        if (checkLimit($_SESSION["B"] - 2))
        {
            $_SESSION["B"] = $_SESSION["B"] - 2;
        }
    }

}

?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Colors</title>
    <link rel="stylesheet" href="../../lit/genstyle.css" type="text/css">
    <style>
      div.formcont { text-align: center; }
      div.ctlrow { text-align: center; width: 100%; height: 2.5em; }
      div.ctlrow div { display: inline-block; }
      form input { text-align: center; }
      form input.direction { width: 3em; height: 100%; }
      form input.pct { width: 3em; height: 50%; }
      form input.set { width: auto; height: 50%; }
      div.setarea { height: 3em; }
      div.setarea div { height: 1em; padding-top: 1em; }
      .red { background-color: rgb(90%,50%,50%); }
      .green { background-color: rgb(50%,90%,50%); }
      .blue { background-color: rgb(50%,50%,90%); }
      div.colblock { width: 50%; height: 2em;
          margin-left: auto; margin-right: auto; margin-top: 3em;
          text-align: center; padding-top: 1em;
      }
    </style>
  </head>
  <body>
   <h1>Colors</h1>
  <form method="GET" action="">
  <div class="formcont">
    <div class="ctlrow">
      <input type="submit" class="direction red" name="action" value="R+">
      <input type="submit" class="direction green" name="action" value="G+">
      <input type="submit" class="direction blue" name="action" value="B+">
 
      <input type="submit" class="direction red" name="action" value="R-">
      <input type="submit" class="direction green" name="action" value="G-">
      <input type="submit" class="direction blue" name="action" value="B-">
    </div>
  

    <div class="colblock" style="background-color: rgb(<?php echo $_SESSION["R"]; ?>, <?php echo $_SESSION["G"]; ?>, <?php echo $_SESSION["B"]; ?>); color: black">  RGB(<?php echo $_SESSION["R"]; ?>, <?php echo $_SESSION["G"]; ?>, <?php echo $_SESSION["B"]; ?>)</div>
  </div>
</form>  </body>
</html>

Related Solutions

I already have a database in phpMyAdmin and need to create an html/php "SEARCH" page to...
I already have a database in phpMyAdmin and need to create an html/php "SEARCH" page to retrieve the information from the database on to my localhost. Please post a php/html code that will create a search page and return the data from my phpmyadmin database. The 3 items I have on the database are first_name, last_name and birth_day.
how to read a csv file in php and make a html table? I can't use...
how to read a csv file in php and make a html table? I can't use the PHP function fgetcsv. I can use explode. I can't put a php inside a php. Acme,Walmart,Ross,BJs,Target,Marshalls,Foot Locker,Giant,Charming Charlie 142,160,28,10,5,3,60,0.28,3167 175,180,18,8,4,1,12,0.43,4033 129,132,13,6,3,1,41,0.33,1471 138,140,17,7,3,1,22,0.46,3204 232,240,25,8,4,3,5,2.05,3613 135,140,18,7,4,3,9,0.57,3028 150,160,20,8,4,3,18,4.00,3131 207,225,22,8,4,2,16,2.22,5158 271,285,30,10,5,2,30,0.53,5702 89,90,10,5,3,1,43,0.30,2054 153,157,22,8,3,3,18,0.38,4127 87,90,16,7,3,1,50,0.65,1445 234,238,25,8,4,2,2,1.61,2087 106,116,20,8,4,1,13,0.22,2818 175,180,22,8,4,2,15,2.06,3917 165,170,17,8,4,2,33,0.46,2220 166,170,23,9,4,2,37,0.27,3498 136,140,19,7,3,1,22,0.63,3607 <!DOCTYPE html> <html> <head>    <meta charset="utf-8">    <title>Stores</title>    <link rel="stylesheet" href="style.css"> </head> <body> <h1>Stores</h1> <?php <table> <tr> <th>Acme</th> <th>Walmart</th> <th>Ross</th> <th>BJs</th> <th>Target</th> <th>Marshalls</th> <th>Foot Locker</th>...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
write a script named compute.sh that is used to do simple arithmetic for the user. There...
write a script named compute.sh that is used to do simple arithmetic for the user. There should be no command line arguments. Instead, all values from the user should be prompted for and read in to the script using the read command. Specifically, you need to ask the user for two integers and an operation string. The operation should be "add", "sub", "mul", "div", or "exp", for addition, subtraction, multiplication, division, and exponentiation, respectively. Your script should take the two...
needing assistance with writing an HTML doc with JavaScript. Making and Age range calculator -two independent...
needing assistance with writing an HTML doc with JavaScript. Making and Age range calculator -two independent buttons on the screen. Each button will ask them for their age. A teenager is someone who is ages 13 to 19. Someone who is younger or older than this age range is not a teenager. •The first button will check to see if someone is a teenager. This should use a logical AND operator. •The secons button will check to see if someone...
lets say i make a PYTHON code that lets a user guess a number between 1-1000,...
lets say i make a PYTHON code that lets a user guess a number between 1-1000, every failed attempt you get a hint (go lower or go higher) how can i penalize the user if they dont follow the hints, example ( go higher!... your next pick: a smaller number... 2 you loose $100 for not following hint) 2 and the user has unlimited attempts, until he guesses the number, this is made using random.randint(1,1000) function THE ONLY THING IM...
Using PHP and MYSQL and with a simple customer database, how can I create a simple...
Using PHP and MYSQL and with a simple customer database, how can I create a simple log in and registration system for an ecommerce site
I am working on making a simple grade book that will take user input like name...
I am working on making a simple grade book that will take user input like name and grade and then return the name and grade of multiple inputs when the person quits the program. Here is the code that I have been working on. This is in Python 3. I can get one line to work but it gives me an error. Here is what it is supposed to look like: These are just examples billy 100 greg 60 jane...
Need this in java .Create a simple login screen in java That lets people sign in...
Need this in java .Create a simple login screen in java That lets people sign in to the emergency room. It needs to ask for name, social,and DOB. Once all the information is received it then display the info back to them if any info is is missing have the program prompt the user to re enter their information.
Hello I need some assistance with these questions I need not so long answers but not...
Hello I need some assistance with these questions I need not so long answers but not too short please Give some examples of How much decisions. What are the implicit costs of having an Airbnb in your neighborhood? What is marginal analysis? What is marginal cost? Under what conditions do marginal costs increase?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT