From: Cameron Ball Date: Thu, 23 Jul 2015 08:39:34 +0000 (+0800) Subject: Saving and more fun features X-Git-Url: http://cameron1729.xyz/?p=pixel-calc.git;a=commitdiff_plain;h=3211592f0814af71b441c3df9d6df7dbf4e540a6 Saving and more fun features --- diff --git a/.gitignore b/.gitignore index 80f408e..3637fa8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ nbproject/ +uploads/ diff --git a/public_html/breakdown.html b/public_html/breakdown.html index cb9689a..bd7909a 100644 --- a/public_html/breakdown.html +++ b/public_html/breakdown.html @@ -28,22 +28,58 @@ clear: both; } - .sprite td.line-left { + .line-left { border-left: 2px solid transparent; } + + .line-right { + border-right: 2px solid transparent; + } - .sprite td.line-top { + .line-top { border-top: 2px solid transparent; } - .sprite.measurements td.line-left { + .line-bottom { + border-bottom: 2px solid transparent; + } + + .sprite.measurements .line-left { border-left: 2px solid black; } - .sprite.measurements td.line-top { + .sprite.measurements .line-right { + border-right: 2px solid black; + } + + .sprite.measurements .line-top { border-top: 2px solid black; } + .sprite.measurements .line-bottom { + border-bottom: 2px solid black; + } + + .sprite.measurements .dimension-top { + transform: translate(50%, -50%); + } + + .sprite.measurements .dimension-bottom { + transform: translate(50%, 50%); + } + + .sprite.measurements .dimension-left { + transform: translateY(50%); + } + + .sprite.measurements .dimension-right { + transform: translateY(50%); + } + + .sprite.measurements .dimension-left .line-left, .sprite.measurements .dimension-right .line-right { + height: 100%; + } + .sprite .height { visibility: hidden; padding-left: 5px; @@ -57,6 +93,10 @@ .sprite.measurements .height, .sprite.measurements .width { visibility: visible; } + + .sprite .grid { + border: 1px solid red; + } /*.sprite { float: left; @@ -72,7 +112,6 @@
@@ -92,27 +131,72 @@
-

Dimensions

+

Summary

-
 
+
+

Cost of materials

+ + + + + + + + + + + + + + + +
Wood
Paint
+ +

Value of materials used

+ + + + + + + + + + + + + +
Wood
Paint
+ +

Profit @ % Markup

+ + + + + + + + + +
Sell price
Less materials
+ +
-

Paint

+

Materials Breakdown

+

Paint

-

Wood

+

Paint

-
- nice meme :] -
@@ -122,20 +206,32 @@ var width = $(".sprite:first table tr:first td").length; $(sprite).find('tr').each(function() { - $(this).append(""); + $(this).append(""); }); + $(sprite).find('tr:first td:last').append('
'); + $(sprite).find('tr:first td:last').addClass('dimension-top'); + + $(sprite).find('tr:last td:last').append('
'); + $(sprite).find('tr:last td:last').addClass('dimension-bottom'); + $(sprite).find('tr').each(function(){ - $(this).find('td').eq(0).before(''); + $(this).find('td').eq(0).before(''); }); for (var i=0; i<$(sprite).find("tr:last td").length; i++) { - var cells = cells ? cells + '' : ''; + var cells = cells ? cells + '' : ''; } - cells += ""; + cells += ""; $(sprite).find("tr:last").after(cells); - $(sprite).find("tr:first td:last").after("") + $(sprite).find('tr:nth-last-child(2) td:nth-last-child(2)').append('
'); + $(sprite).find('tr:nth-last-child(2) td:nth-last-child(2)').addClass('dimension-left'); + + $(sprite).find('tr:nth-last-child(2) td:first').append('
'); + $(sprite).find('tr:nth-last-child(2) td:first').addClass('dimension-right'); + + $(sprite).find("tr:first td:last").after("") }; padSprite($(".measurements")); @@ -170,6 +266,25 @@ var colour = $(this).attr('colour'); $("." + colour).toggleClass("highlighted"); }); + + function nextTab(elem) { + $(elem + ' li.active') + .next() + .find('a[data-toggle="tab"]') + .click(); + } + + $(document).keypress(function(e) { + if(e.which == 110) { + var active = $(".nav li.active"); + var tabs = active.parent().children(); + tabs.eq((tabs.index(active) + 1) % tabs.length).find('a[data-toggle="tab"]').click(); + } + + if(e.which == 103) { + $(".sprite tr td:not(.added)").toggleClass("grid"); + } + }); diff --git a/public_html/index.html b/public_html/index.html index 8dc8c4f..170c692 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -17,6 +17,7 @@ and open the template in the editor. Wood size (for nxn enter n):
Wood length:
Wood cost/length:
+ Markup % as int:
diff --git a/public_html/upload.php b/public_html/upload.php index 777c5f7..a37b476 100644 --- a/public_html/upload.php +++ b/public_html/upload.php @@ -129,7 +129,8 @@ function count_pixels($array) { } function lumber_breakdown($cost_per_length, $wood_length, $wood_size, $num_blocks) { - $lengths_required = ceil($num_blocks*$wood_size/$wood_length); + $lumber_percent = $num_blocks*$wood_size/$wood_length; + $lengths_required = ceil($lumber_percent); $total_lumber_cost = $lengths_required * $cost_per_length; return array_to_table( @@ -137,20 +138,25 @@ function lumber_breakdown($cost_per_length, $wood_length, $wood_size, $num_block array( 'Num blocks', 'No of ' . $wood_length . 'm lengths required', - 'Cost @ ' . $cost_per_length . ' per length' + '% used', + 'Cost @ ' . $cost_per_length . ' per length', + '% Price' ), array( $num_blocks, $lengths_required, - $total_lumber_cost + round($lumber_percent,4), + $total_lumber_cost, + round($lumber_percent*$cost_per_length,4) ) ) ); } -function lumber_cost($cost_per_length, $wood_length, $wood_size, $num_blocks) { - $lengths_required = ceil($num_blocks*$wood_size/$wood_length); - return $lengths_required * $cost_per_length; +function lumber_cost($cost_per_length, $wood_length, $wood_size, $num_blocks, $percent_cost = FALSE) { + $percent = $num_blocks*$wood_size/$wood_length; + $lengths_required = ceil($percent); + return $percent_cost ? $percent * $cost_per_length : $lengths_required * $cost_per_length; } function colour_count($array, $colour_map = NULL) { @@ -199,11 +205,12 @@ function colour_breakdown($colour_count, $block_size, $can_coverage, $coats, $co foreach($colour_count as $colour => $count) { $can_percent = $count * $block_size * $block_size * $coats / $can_coverage; $num_needed = ceil($can_percent); + $running_cost_percent = isset($running_cost_percent) ? $running_cost_percent + $can_percent*end($discount_matrix) : $can_percent*end($discount_matrix); if(isset($colour_names[$colour])) - $output .= '' . $colour_names[$colour] . '' . $num_needed . '' . $can_percent . '' . $cost_per_can*$num_needed . '' . $can_percent * $cost_per_can . ''; + $output .= '' . $colour_names[$colour] . '' . $num_needed . '' . round($can_percent,4) . '' . $cost_per_can*$num_needed . '' . round($can_percent * $cost_per_can,4) . ''; } - $output .= ''; + $output .= '' . $total_cans . ''. $total_cans*$cost_per_can . '' . round($running_cost_percent, 4) . ''; return $output; } @@ -221,10 +228,26 @@ function spray_can_cost($colour_count, $block_size, $can_coverage, $coats, $disc $cost_per_can = $cost; } - return $percent_cost ? end($discount_matrix)*$total_cans : $total_cans*$cost_per_can; + return round($percent_cost ? end($discount_matrix)*$total_cans : $total_cans*$cost_per_can,4); } -if(isset($_POST["submit"])) { +if(isset($_POST["submit"]) || isset($_GET['sprite'])) { + if(isset($_POST['submit'])) { + if(isset($_FILES['fileToUpload'])) { + $image = $_FILES['fileToUpload']['tmp_name']; + } + + if(isset($_POST['sprite'])) { + $image = "uploads/" . $_POST['sprite'] . '.png'; + } + } + + if(isset($_GET['sprite'])) { + $image = 'uploads/' . $_GET['sprite'] . '.png'; + } + + $hash = substr(md5_file($image), 0, 8); + $ironlak_colours = array( "532f18" => "Earth", "753e00" => "Swiss", @@ -329,30 +352,47 @@ if(isset($_POST["submit"])) { 5 => 7.95 // 0-5 cans ); - $pixel_array = image_to_array($_FILES["fileToUpload"]["tmp_name"]); - $sprite_width_cm = count($pixel_array[0]) * $_POST['wood_size'] * 100 . "cm"; - $sprite_height_cm = count($pixel_array) * $_POST['wood_size'] * 100 . "cm"; + if(isset($_POST['submit'])) { + $vars['wood_size'] = $_POST['wood_size']; + $vars['wood_length'] = $_POST['wood_length']; + $vars['wood_cost'] = $_POST['wood_cost']; + $vars['markup'] = $_POST['markup']; + } elseif(file_exists('uploads/'.$hash.'.txt')) { + $vars= unserialize(file_get_contents('uploads/'.$hash.'.txt')); + } + + $pixel_array = image_to_array($image); + $sprite_width_cm = count($pixel_array[0]) * $vars['wood_size'] * 100 . "cm"; + $sprite_height_cm = count($pixel_array) * $vars['wood_size'] * 100 . "cm"; $colour_map = generate_colourmap($pixel_array, $ironlak_colours); $original_sprite = array_to_sprite($pixel_array); $ironlak_sprite = array_to_sprite($pixel_array, $colour_map); - $lumber_breakdown = lumber_breakdown($_POST['wood_cost'], $_POST['wood_length'], $_POST['wood_size'], count_pixels($pixel_array)); + $lumber_breakdown = lumber_breakdown($vars['wood_cost'], $vars['wood_length'], $vars['wood_size'], count_pixels($pixel_array)); $original_colour_table = colour_count_table(colour_count($pixel_array)); $ironlak_colour_table = colour_count_table(colour_count($pixel_array, $colour_map)); - $spray_can_breakdown = colour_breakdown(colour_count($pixel_array, $colour_map), $_POST['wood_size'], 2.2, 3, $ironlak_colours, $discount_matrix); + $spray_can_breakdown = colour_breakdown(colour_count($pixel_array, $colour_map), $vars['wood_size'], 2.2, 3, $ironlak_colours, $discount_matrix); - $cost_of_cans = spray_can_cost(colour_count($pixel_array, $colour_map), $_POST['wood_size'], 2.2, 3, $discount_matrix); - $value_of_can_used = spray_can_cost(colour_count($pixel_array, $colour_map), $_POST['wood_size'], 2.2, 3, $discount_matrix, TRUE); -// echo $original_sprite; -// echo $original_colour_table; -// -// echo $ironlak_sprite; -// echo $ironlak_colour_table; -// -// echo $lumber_breakdown; -// echo $spray_can_breakdown; + $cost_of_cans = spray_can_cost(colour_count($pixel_array, $colour_map), $vars['wood_size'], 2.2, 3, $discount_matrix); + $value_of_can_used = spray_can_cost(colour_count($pixel_array, $colour_map), $vars['wood_size'], 2.2, 3, $discount_matrix, TRUE); + $cost_of_lumber = lumber_cost($vars['wood_cost'], $vars['wood_length'], $vars['wood_size'], count_pixels($pixel_array)); + $value_of_lumber_used = lumber_cost($vars['wood_cost'], $vars['wood_length'], $vars['wood_size'], count_pixels($pixel_array), TRUE); + + $markup = $vars['markup']; + + $filename = 'uploads/' . $hash . '.png'; + + if(!file_exists($filename)) { + move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $filename); + $fp = fopen('uploads/'. $hash . '.txt', 'w'); + fwrite($fp, serialize($vars)); + } + + if(!isset($_GET['sprite'])) { + header("location: upload.php?sprite=$hash"); + } require_once('./breakdown.html'); }