Skip to content

Commit

Permalink
replaced "~~" with Math.floor()
Browse files Browse the repository at this point in the history
  • Loading branch information
Osterie committed Jan 23, 2023
1 parent 2cf434f commit 46aeb1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
5 changes: 0 additions & 5 deletions color_function/library/classdefinitions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//IMPROVEMENT AREAS

//5 It might be more efficient to use a single method to handle the hue, saturation, and lightness calculations, instead of having separate methods for each in the Square class.


class Square {
constructor(ctx, xpos, ypos, hue, saturation, lightness, square_size) {
this.xpos = xpos;
Expand Down
28 changes: 12 additions & 16 deletions color_function/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

const c = console.log.bind(console);

const get_hue_expression = document.getElementById("hue_expression");
const get_saturation_expression = document.getElementById("saturation_expression");
const get_lightness_expression = document.getElementById("lightness_expression");
const get_size_lower = document.getElementById("size_lower");
const get_size_upper = document.getElementById("size_upper");
const get_pixel_ratio = document.getElementById("pixel_ratio");
const get_upscale_button = document.getElementById("upscale");
const get_hue_expression = document.querySelector("#hue_expression");
const get_saturation_expression = document.querySelector("#saturation_expression");
const get_lightness_expression = document.querySelector("#lightness_expression");
const get_size_lower = document.querySelector("#size_lower");
const get_size_upper = document.querySelector("#size_upper");
const get_pixel_ratio = document.querySelector("#pixel_ratio");
const get_upscale_button = document.querySelector("#upscale");

get_hue_expression.addEventListener("change", function () {
hue_expression = get_hue_expression.value;
Expand All @@ -33,8 +33,8 @@ get_lightness_expression.addEventListener("change", function () {

get_pixel_ratio.addEventListener("change", function () {
pixel_ratio = +get_pixel_ratio.value;
size_upper = ~~(+get_size_upper.value / pixel_ratio);
size_lower = ~~(+get_size_lower.value / pixel_ratio);
size_upper = Math.floor(+get_size_upper.value / pixel_ratio);
size_lower = Math.floor(+get_size_lower.value / pixel_ratio);
distance_left_x_zooming = size_lower
distance_top_y_zooming = size_lower
matrix_squares.create_squares(size_lower, size_lower, size_upper, size_upper, pixel_ratio)
Expand All @@ -43,9 +43,7 @@ get_pixel_ratio.addEventListener("change", function () {

get_size_lower.addEventListener("change", function () {
let old_size = size_lower
size_lower = ~~(+get_size_lower.value / pixel_ratio);


size_lower = Math.floor(+get_size_lower.value / pixel_ratio);
const absolute_width = canvas.width / (size_upper - size_lower + index_zero);
var distance_from_top_left = (absolute_width) * (old_size - size_lower)
var image_size = ((absolute_width) * (size_upper - old_size + index_zero ))
Expand All @@ -59,14 +57,12 @@ get_size_lower.addEventListener("change", function () {

get_size_upper.addEventListener("change", function () {
let old_size = size_upper
size_upper = ~~(+get_size_upper.value / pixel_ratio);
size_upper = Math.floor(+get_size_upper.value / pixel_ratio);

const absolute_width = canvas.width / (size_upper - size_lower + index_zero);
var image_size = ((absolute_width) * (old_size - size_lower + index_zero))
ctx.drawImage(resizing_img, 0, 0, image_size, image_size);



matrix_squares.change_size(size_lower, size_upper, old_size, 'higher');
update_images(canvas)
});
Expand All @@ -78,7 +74,7 @@ get_upscale_button.addEventListener("click", function () {

//-----------------------Canvas-----------------------------

let canvas = document.getElementById("canvas");
let canvas = document.querySelector("#canvas");
const ctx = canvas.getContext("2d", { alpha: false });

//Check class for these settings!
Expand Down

0 comments on commit 46aeb1a

Please sign in to comment.