Skip to content

Commit

Permalink
Quantimat
Browse files Browse the repository at this point in the history
  • Loading branch information
Affolter Matias committed May 15, 2024
1 parent 2ab9d04 commit ddc0b6f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 66 deletions.
2 changes: 1 addition & 1 deletion client/chunk_10.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/chunk_15.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/chunk_7.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ var LOAD_FILES_USEFUL = ["/src/fonts/normative/index.css"].concat(["illusion.jpg
var LOAD_FILES_STATIC = ["sfx/md/hero_decorative-celebration-02", "sfx/md/navigation_selection-complete-celebration", "sfx/md/navigation_transition-left", "sfx/md/state-change_confirm-down", "sfx/md/ui_lock", "sfx/md/ui_unlock", "sfx/md/ui_scan", "sfx/md/alert_high-intensity", "sfx/md/navigation_transition-right", "voice/cn/accessing_memory", "voice/cn/complete", "voice/cn/please_wait", "voice/cn/data_upload", "voice/cn/processing", "voice/cn/enhanced", "voice/cn/rewriting_deep_layer_protocols", "voice/cn/vision_activated", "voice/cn/vision_deactivated", "voice/cn/filtering", "music/redeclipse/track_09"].map(F_SND).concat(["presentation", "tutorial", "create", "enhanced", "pixelated", "upload", "share1", "joke1", "create", "enhanced", "pixelated", "presentation", "presentation2", "sponsors", "tutorial", "upload", "labintro", "share2", "share3", "share4", "share5", "share6", "share7", "joke2", "joke3", "joke4", "joke5", "joke6", "joke7", "joke8", "joke9", "joke10", "joke11"].map(F_VID));

// Cache names
var REQUIRED_CACHE = "unless-update-cache-v1025-required";
var USEFUL_CACHE = "unless-update-cache-v1025-useful";
var STATIC_CACHE = "unless-update-cache-v1025-static";
var OTHER_CACHE = "unless-update-cache-v1025-other";
var REQUIRED_CACHE = "unless-update-cache-v1026-required";
var USEFUL_CACHE = "unless-update-cache-v1026-useful";
var STATIC_CACHE = "unless-update-cache-v1026-static";
var OTHER_CACHE = "unless-update-cache-v1026-other";

// Regular expressions for chunk matching
var MAIN_CHILD_CHUNK_REGEX = /chunk_(main_[a-z0-9]+)\.min\.js$/i;
Expand Down
24 changes: 9 additions & 15 deletions src/js/components/canvaspixels/utils/SuperMasterMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,27 +804,21 @@ const SuperMasterMeta = {


let { pxl_current_opacity, pxl_current_color_uint32 } = meta.super_state.get_state();
const first_drawn_pixel = _paint_or_select_hover_pxl_indexes[0];
const last_drawn_pixel = _paint_or_select_hover_pxl_indexes[_paint_or_select_hover_pxl_indexes.size-1];
const closing_path_line = meta.super_state.shape_creator.from_line(first_drawn_pixel, last_drawn_pixel);
_paint_or_select_hover_pxl_indexes = new SetFixed(Array.from(_paint_or_select_hover_pxl_indexes.indexes).concat(closing_path_line));
_paint_or_select_hover_pxl_indexes = meta.super_state.shape_creator.from_path(_paint_or_select_hover_pxl_indexes, _paint_or_select_hover_pxl_indexes);

_paint_or_select_hover_pxl_indexes.clear();
meta.super_state.paint_shape(_paint_or_select_hover_pxl_indexes.indexes, pxl_current_color_uint32, pxl_current_opacity,
meta.super_state.paint_shape(meta.super_state.shape_creator.from_path(_paint_or_select_hover_pxl_indexes.indexes), pxl_current_color_uint32, pxl_current_opacity,
{
_last_action_timestamp: Date.now()
},
() => {this.update_canvas();}
() => {

_paint_or_select_hover_pxl_indexes.clear();
this.update_canvas();
}
);

}else if(_paint_or_select_hover_pxl_indexes.size > 0 && tool === "SELECT PATH") {

const first_drawn_pixel = _paint_or_select_hover_pxl_indexes[0];
const last_drawn_pixel = _paint_or_select_hover_pxl_indexes[_paint_or_select_hover_pxl_indexes.size-1];
const closing_path_line = meta.super_state.shape_creator.from_line(first_drawn_pixel, last_drawn_pixel);
_paint_or_select_hover_pxl_indexes = new SetFixed(Array.from(_paint_or_select_hover_pxl_indexes.indexes).concat(closing_path_line));
_paint_or_select_hover_pxl_indexes = meta.super_state.shape_creator.from_path(_paint_or_select_hover_pxl_indexes, _paint_or_select_hover_pxl_indexes);
const _paint_or_select_hover_pxl_indexes_final = meta.super_state.shape_creator.from_path(_paint_or_select_hover_pxl_indexes.indexes);

if(select_mode === "REPLACE") {

Expand All @@ -833,14 +827,14 @@ const SuperMasterMeta = {

if(select_mode === "ADD" || select_mode === "REPLACE") {

_paint_or_select_hover_pxl_indexes.forEach(function(pxl) {
_paint_or_select_hover_pxl_indexes_final.forEach(function(pxl) {

_pxl_indexes_of_selection.add(pxl);
});

}else {

_paint_or_select_hover_pxl_indexes.forEach(function(pxl) {
_paint_or_select_hover_pxl_indexes_final.forEach(function(pxl) {

_pxl_indexes_of_selection.delete(pxl);
});
Expand Down
90 changes: 50 additions & 40 deletions src/js/components/canvaspixels/utils/SuperState.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,34 +179,42 @@ class CreateShape {
}
from_path(path_indexes, onto){
"use strict";
onto = typeof onto == "undefined" ? new SetFixed(this.width*this.height): onto;
onto = typeof onto === "undefined" ? new SetFixed(this.width * this.height) : onto;

this.context.lineWidth = 1;
this.context.clearRect(0, 0, this.width, this.height);
this.context.linewidth = 1;

let start_x = 0, start_y = 0;
path_indexes.forEach( (pxl_index, index) => {
this.context.save(); // Save current state

const x = pxl_index % this.width|0;
const y = (pxl_index - x|0) / this.width|0;
let i = 0;
path_indexes.forEach((pxl_index) => {
const x = pxl_index % this.width;
const y = Math.floor(pxl_index / this.width);

if((index|0) == 0) {

this.context.moveTo(x|0, y|0);
if (i === 0) {
this.context.moveTo(x, y);
this.context.beginPath();
start_x = x | 0;
start_y = y | 0;
}else {

this.context.lineTo(x|0, y|0);
} else {
this.context.lineTo(x, y);
}

i++;
});

this.context.strokeStyle = "#ffffffff";
this.context.fillStyle = "#ffffffff";
this.context.stroke();
this.context.fill();


if (i > 0) {
this.from_line(path_indexes[0], path_indexes[path_indexes.length-1], new Set()).forEach((pxl_index) => {
const x = pxl_index % this.width;
const y = Math.floor(pxl_index / this.width);
this.context.lineTo(x, y);
});
//this.context.closePath(); // Close the path to properly fill and stroke the shape
this.context.strokeStyle = "rgba(255, 255, 255, 1)";
this.context.fillStyle = "rgba(255, 255, 255, 1)";
this.context.fill();
this.context.stroke();
}

//this.context.restore(); // Restore original state after drawing is complete

return this.get_shadow_indexes_from_canvas_context(this.context, onto);
}
Expand All @@ -230,17 +238,17 @@ class CreateShape {

if((c.primary.x|0) == (c.secondary.x|0) && (c.primary.y|0) == (c.secondary.y|0)) { break; }

e2 = (2 * err) | 0;
e2 = err + err | 0;

if ((e2|0) > (-dy|0)) {

err = (err-dy)|0;
c.primary.x = (c.primary.x+sx)|0;
err = err-dy|0;
c.primary.x = c.primary.x+sx|0;
}
if ((e2|0) < (dx|0)) {

err = (err+dx)|0;
c.primary.y = (c.primary.y+sy)|0;
err = err+dx|0;
c.primary.y = c.primary.y+sy|0;
}
}
}else {
Expand All @@ -250,17 +258,17 @@ class CreateShape {

if((c.primary.x|0) == (c.secondary.x|0) && (c.primary.y|0) == (c.secondary.y|0)) { break; }

e2 = (2 * err) | 0;
e2 = err + err | 0;

if ((e2|0) > (-dy|0)) {

err = (err-dy)|0;
c.primary.x = (c.primary.x+sx)|0;
err = err-dy|0;
c.primary.x = c.primary.x+sx|0;
}
if ((e2|0) < (dx|0)) {

err = (err+dx)|0;
c.primary.y = (c.primary.y+sy)|0;
err = err+dx|0;
c.primary.y = c.primary.y+sy|0;
}
}
}
Expand Down Expand Up @@ -307,25 +315,27 @@ class CreateShape {
to = to | 0;
onto = typeof onto == "undefined" ? new SetFixed(this.width*this.height): onto;
let c = this.get_opposite_coordinates(this.width|0, from|0, to|0);
let ellipse_width = Math.abs(c.primary.x - c.secondary.x|0) + 1 | 0;
let ellipse_height = Math.abs(c.primary.y - c.secondary.y|0) + 1 | 0;
const ellipse_top_left_x = Math.max(c.primary.x, c.secondary.x|0) - (ellipse_width - 1|0) | 0;
const ellipse_top_left_y = Math.max(c.primary.y, c.secondary.y|0) - (ellipse_height - 1|0) | 0;
let ellipse_width = Math.abs(c.primary.x - c.secondary.x) + 1;
let ellipse_height = Math.abs(c.primary.y - c.secondary.y) + 1;
const ellipse_top_left_x = Math.max(c.primary.x, c.secondary.x) - (ellipse_width - 1);
const ellipse_top_left_y = Math.max(c.primary.y, c.secondary.y) - (ellipse_height - 1);

let ellipse_rayon_x = ellipse_width / 2;
let ellipse_rayon_y = ellipse_height / 2;
const ellipse_middle_x = ellipse_rayon_x + ellipse_top_left_x;
const ellipse_middle_y = ellipse_rayon_y + ellipse_top_left_y;
const ellipse_middle_x = ellipse_top_left_x + ellipse_rayon_x;
const ellipse_middle_y = ellipse_top_left_y + ellipse_rayon_y;

this.context.lineWidth = 1;
this.context.clearRect(0, 0, this.width|0, this.height|0);
this.context.clearRect(0, 0, this.width, this.height);
this.context.save(); // Save current state
this.context.translate(ellipse_middle_x, ellipse_middle_y);
this.context.rotate(0);
this.context.scale(ellipse_rayon_x, ellipse_rayon_y);
this.context.beginPath(); // Start a new path for the arc
this.context.arc(0, 0, 1, 0, 2 * Math.PI);
this.context.restore(); // Restore original state

this.context.fillStyle = "#ffffffff";
this.context.strokeStyle = "#ffffffff";
this.context.fillStyle = "rgba(255, 255, 255, 1)"; // White with full opacity
this.context.strokeStyle = "rgba(255, 255, 255, 1)";
this.context.stroke();
this.context.fill();

Expand Down
8 changes: 4 additions & 4 deletions src/js/utils/quantimat/QuantiMat.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ QuantiMat.prototype.process_threshold = function(t) {
"use strict";

t = (t | 0) >>> 0;
const exponent = 1.15;
function calculateN(t, max) {
// Apply a power scale to 't'. The exponent (e.g., 0.5) determines the curve's shape.
const exponent = 1.5;
const scaledT = Math.pow(t, exponent)-t;

// Calculate n using the scaled value of t
return fr(scaledT / max);
}

var max = Math.pow(100, 1.5) - 100;
var max = Math.pow(100, exponent) - 100;
var weight_applied_to_color_usage_difference = calculateN(t, max); // Ensure higher precision when low color (high threshold)
var index_merged = false;
var latest_colors = [];
Expand All @@ -479,9 +479,9 @@ QuantiMat.prototype.process_threshold = function(t) {
var color_n_in_cluster = 0;
var threshold = 0;

var baseFactor = 16.0;
var baseFactor = 12.0;
var lowUsedFactor = 6.0; // Adjust this value to control sensitivity to usage percent differences
var distanceUsageFactor = 2.0; // Adjust this value to emphasize the effect of one color being more dominant
var distanceUsageFactor = -6.0; // Adjust this value to emphasize the effect of one color being more dominant
var totalFactor = baseFactor + lowUsedFactor + distanceUsageFactor;

weighted_threshold_skin_skin = fr(weighted_threshold * SAME_SKIN_COLOR_MATCH_MULTIPLY);
Expand Down

0 comments on commit ddc0b6f

Please sign in to comment.