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.
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?
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i...
Create a PYTHON program that lets a user guess a number from 1 to 1,000: -i used random.randint(1,1000) -must give hints like (pick a lower/higher number) which i already did -tell the user when he has repeated a number (help) -the game only ends when you guess the number (help) -you loose $50 every failed attempt (done) ****I did it as a while loop -
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT