Skip to content

Commit

Permalink
v.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
johappel committed Aug 14, 2024
1 parent 1d6d494 commit e540dfe
Show file tree
Hide file tree
Showing 9 changed files with 1,883 additions and 30 deletions.
71 changes: 71 additions & 0 deletions class_post_it_colors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class Post_Color
{

public function __construct($post_id) {
return $this->get_post_it_color($post_id);
}
function generate_post_it_colors() {
// Überprüfe, ob die Farben bereits in der wp_options gespeichert sind
$colors = get_option('post_it_colors');

// Wenn noch keine Farben vorhanden sind, generiere 12 Farben
if (!$colors) {
$colors = [];
for ($i = 0; $i < 12; $i++) {
$colors[] = $this->generate_contrast_color();
}
// Speichere die generierten Farben in wp_options
update_option('post_it_colors', $colors);
}

return $colors;
}

function generate_contrast_color() {
// Helligkeit der Farben für gute Lesbarkeit mit schwarzer Schrift
$min_brightness = 130;

do {
// Generiere eine zufällige Farbe
$color = sprintf('#%02X%02X%02X', mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
// Berechne die Helligkeit der Farbe
$brightness = $this->calculate_brightness($color);
} while ($brightness < $min_brightness);

return $color;
}

function calculate_brightness($hex) {
// Entferne das "#" Zeichen, wenn vorhanden
$hex = str_replace('#', '', $hex);

// Wandle HEX in RGB um
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));

// Berechne die Helligkeit (simplifiziert)
return ($r * 299 + $g * 587 + $b * 114) / 1000;
}

function get_post_it_color($post_id) {
// Überprüfe, ob die Farbe bereits als Meta-Information gespeichert ist
$color = get_post_meta($post_id, '_post_it_color', true);

if (!$color) {
// Hol die Liste der 12 Farben
$colors = $this->generate_post_it_colors();

// Wähle eine zufällige Farbe aus
$color = $colors[array_rand($colors)];

// Speichere die Farbe als Post-Meta
update_post_meta($post_id, '_post_it_color', $color);
}

return $color;
}

}
17 changes: 17 additions & 0 deletions css/colors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
:root{
--textcolor: var(--theme-palette-color-3);
--background: var(--theme-palette-color-7);
--buttoncolor: var(--theme-palette-color-1);
--buttontext: var(--theme-palette-color-6);
--inverse: var(--theme-palette-color-4);
--akcent: var(--theme-palette-color-2);
--akcent2: var(--theme-palette-color-5);
--background1: var(--theme-palette-color-6);
--background2: var(--theme-palette-color-8);
--modal-background: rgba(0,0,0,0.4);
--bordercolor: var(--theme-palette-color-2);
--bordercolor2: var(--theme-palette-color-9);
--gray: #d3d3d3;

}

Loading

0 comments on commit e540dfe

Please sign in to comment.