From ae53f1a2c4ab3238358142eeeebd185957fde623 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Thu, 16 Jul 2015 16:45:10 +0800 Subject: [PATCH] Calculate paint cost --- public_html/upload.php | 224 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 219 insertions(+), 5 deletions(-) diff --git a/public_html/upload.php b/public_html/upload.php index 22321d6..cf1e765 100644 --- a/public_html/upload.php +++ b/public_html/upload.php @@ -6,6 +6,12 @@ .highlighted { background-color: blue; } + + .sprite { + float: left; + margin-right: 20px; + } + @@ -16,13 +22,141 @@ // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { + $ironlak_colours = array( + "532f18" => "Earth", + "753e00" => "Swiss", + "be854b" => "Mocha", + "e5ba83" => "Cuppa", + "f9e6c4" => "Irwin", + "fcf2e0" => "Fraser", + + "be854b" => "Acacia", + "e5b53a" => "Tanami", + "f5d29c" => "Oat", + "ffdc01" => "Blaze", + "ffe04e" => "Pineapple Park", + "fffac4" => "Sorbet", + + "de791b" => "Dieci Poes", + "f47d31" => "Halloween", + "f58427" => "Tues Afterburn", + "faae5d" => "Bowen", + "fdd29d" => "Smoothie", + "fcbc5e" => "Eureka", + "fed378" => "Butter", + "feefbb" => "Bondi", + + "571b1e" => "Sirum Black-Red", + "8b0a02" => "Matador", + "d20d44" => "Soviet", + "e51a23" => "Autumn", + "cd4552" => "Isla Rose", + "f2797e" => "Guava", + + "9c0159" => "Moberry", + "ea4498" => "Flirt", + "f38ab4" => "Potion", + "f6aec4" => "Delicious", + "f9cbd7" => "Crush", + "be76ad" => "Dusk", + "dd9ba5" => "Fantasia", + "fde6e0" => "Teegs Love", + + "7e3e98" => "Pose Sushi", + "592049" => "Venom", + "78486a" => "Vino", + "c2739d" => "Furious", + "d4aed1" => "Gypsy", + + "0a024e" => "Panther", + "62609a" => "Eggplant", + "7f76b7" => "Phantom", + "7d81be" => "Sofles Violence", + "8ba4d4" => "Granny", + + "231f20" => "Augor's Blackout", + "00447b" => "Midnight", + "0068a9" => "Phat1's True Royal", + "0082c8" => "Smurf", + "00aeef" => "Enue's Bonggg!", + "78bde8" => "Torquay", + "89d3f4" => "Atmosphere", + "b9e1f7" => "Ozone", + + "006b6e" => "Neverland", + "007b85" => "Hunter", + "00b5cb" => "Reef", + "2abdb1" => "Frazetta", + "8fd1c5" => "Linz Iceberg", + "c0e3da" => "Placid", + "70c6a2" => "Jante", + + "006224" => "Huey", + "3f9537" => "Field", + "6cb43f" => "Cameleon", + "b3d78b" => "Reals Sublime", + "e6eebc" => "Whizbang", + + "514e25" => "Askew's Olivia", + "677717" => "Guacamole", + "9ea615" => "Gangrene", + "ac9601" => "Banos Asbestos", + "d4d110" => "Kryptonite", + "f4eb0a" => "Keen", + "fcf26f" => "Nitro", + + "434c3d" => "Lazy Grey", + "a0a1a5" => "Battleship", + "c5c6c8" => "Washington", + "f0f1f2" => "Smoulder", + + "a29161" => "Gold", + "a8a9ad" => "Bright Chrome", + + "ffffff" => "Whitest Possible", + "000000" => "Blackest Possible" + ); + + function colourDiff($rgb1, $rgb2) { + $red1 = hexdec(substr($rgb1,0,2)); + $green1 = hexdec(substr($rgb1,2,2)); + $blue1 = hexdec(substr($rgb1,4,2)); + + $red2 = hexdec(substr($rgb2,0,2)); + $green2 = hexdec(substr($rgb2,2,2)); + $blue2 = hexdec(substr($rgb2,4,2)); + + return abs($red1 - $red2) + abs($green1 - $green2) + abs($blue1 - $blue2) ; + } + + function closest_colour($rgb, array $colours) { + $smallest_diff = 766; + $closest = 'none'; + + foreach($colours as $hex => $name) + { + if(colourDiff($rgb, $hex) < $smallest_diff) { + $smallest_diff = colourDiff($rgb, $hex); + $closest = $hex; + } + } + + return $closest; + } + $cost_per_length = $_POST['wood_cost']; $wood_length = $_POST['wood_length']; $wood_size = $_POST['wood_size']; + $num_cans = 0; $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { $colour_count = array(); + $icolour_count = array(); $image = imagecreatefrompng($_FILES["fileToUpload"]["tmp_name"]); + $ironlak_sprite = array(); + + echo "
Original sprite:
"; + echo ""; for($i=0; $i<$check[1]; $i++) { echo ''; @@ -44,11 +178,38 @@ if(isset($_POST["submit"])) { } else { echo ""; } + + $ironlak_sprite[$i][$j] = closest_colour($hex, $ironlak_colours); } echo ''; } - echo '
'; + echo '
'; + + echo "
Ironlak sprite:
"; + echo ""; + for($i=0; $i<$check[1]; $i++) { + echo ''; + for($j=0; $j<$check[0]; $j++) { + $rgb = imagecolorsforindex($image, imagecolorat($image, $j, $i)); + $r = $rgb['red']; + $g = $rgb['green']; + $b = $rgb['blue']; + $a = $rgb['alpha']; + $ihex = $ironlak_sprite[$i][$j]; + if($a == 127) $ihex = "ffffff"; + + if($a == 0) { + echo ""; + $icolour_count[$ihex] = isset($icolour_count[$ihex]) ? $icolour_count[$ihex]+1 : 1; + } else { + echo ""; + } + } + echo ''; + } + echo '
'; + echo '
'; $total_blocks = array_sum($colour_count); $lengths_required = ceil($total_blocks*$wood_size/$wood_length); echo '
'; @@ -60,7 +221,7 @@ if(isset($_POST["submit"])) { echo '

'; - echo 'Cost breakdown
'; + echo 'Wood cost breakdown
'; echo ' @@ -74,20 +235,73 @@ if(isset($_POST["submit"])) {
Total blocks
'; + $wood_cost = $lengths_required * $cost_per_length; + $paint_cost = 0; + echo '

'; - echo 'Colour breakdown
'; + echo 'Colour cost breakdown

'; + echo '
Original colour table:
'; echo ' - + '; foreach($colour_count as $colour => $qty) { echo ""; } - echo '
Colour RGBQuantityNum blucks
$colour$qty
'; + echo '
'; + + echo '
Ironlak colour table:
'; + + echo ' + + + + + + '; + foreach($icolour_count as $colour => $qty) { + echo ""; + $num_cans+=+ceil(($qty * ($wood_size * $wood_size))/2.2); + } + + echo '
ColourNameCoverage (m^2)Cans needed
" . $ironlak_colours[$colour] . "" . $qty * ($wood_size * $wood_size) . "" . ceil(($qty * ($wood_size * $wood_size))/2.2) . "
'; + + echo '
'; + echo '
'; + + echo 'Paint cost:
'; + + $cost_per_can = 6.36; + if($num_cans <= 199 ) { + $cost_per_can = 6.60; + } + + if($num_cans <= 59 ) { + $cost_per_can = 6.76; + } + + if($num_cans <= 35 ) { + $cost_per_can = 7; + } + + if($num_cans <= 11 ) { + $cost_per_can = 7.16; + } + + if($num_cans <= 5 ) { + $cost_per_can = 7.65; + } + $paint_cost = $num_cans * $cost_per_can; + echo "$num_cans cans @ $cost_per_can each: $paint_cost"; + echo '

'; + + $total_cost = $wood_cost + $paint_cost; + echo '
Total cost (wood+paint): ' . $total_cost . '
'; + } } ?> -- 2.11.0