From 28844324b98b0515df18abded01f6d19c0b522e0 Mon Sep 17 00:00:00 2001 From: iamhabbeboy Date: Thu, 27 Feb 2025 23:11:57 +0100 Subject: [PATCH 1/4] chore: add color gradients --- app.go | 37 ++++++++- frontend/dist/index.html | 4 +- frontend/src/pages/PlainArt.svelte | 120 ++++++++++++++++++----------- frontend/wailsjs/go/models.ts | 17 ++++ internal/api/unsplash.go | 7 ++ internal/service.go | 70 +++++++++++++---- 6 files changed, 187 insertions(+), 68 deletions(-) diff --git a/app.go b/app.go index f43b217..8326719 100644 --- a/app.go +++ b/app.go @@ -4,6 +4,7 @@ import ( "context" "desktop/internal" "desktop/internal/api" + "errors" "fmt" "log" "os" @@ -243,8 +244,16 @@ func deleteFilesWithPrefix(dir, prf string) error { return nil } -func (a *App) GetGradient() error { - err := internal.GenerateGradientImage() +func (a *App) GetGradientImage(c []string) error { + if len(c) == 0 { + return errors.New("no colors added") + } + + rgba1, err := internal.HexToRGBA(c[0]) + + rgba2, err := internal.HexToRGBA(c[1]) + + err = internal.GenerateGradientImage(rgba1, rgba2) if err != nil { return err } @@ -252,5 +261,29 @@ func (a *App) GetGradient() error { return nil } +func (a *App) GetHexToRGBA(color string) (api.RGBA, error) { + return internal.HexToRGBA(color) +} + +// func (ax *App) GGradient(color string) interface{} { +// +// r, g, b, a, err := internal.HexToRGBA(color) +// if err != nil { +// log.Fatal(err) +// } +// res := struct { +// R int `json:"r"` +// G int `json:"g"` +// B int `json:"b"` +// A int `json:"a"` +// }{ +// R: r, +// G: g, +// B: b, +// A: a, +// } +// return res +// } + // https://gist.github.com/stupidbodo/0db61fa874213a31dc57 - replacement for cronjob // https://gist.github.com/harubaru/f727cedacae336d1f7877c4bbe2196e1#model-overview diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 2e511b6..5a9e46f 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -10,8 +10,8 @@ --main-color: orange; } - - + +
diff --git a/frontend/src/pages/PlainArt.svelte b/frontend/src/pages/PlainArt.svelte index 1a0fe9f..7d1f0dc 100644 --- a/frontend/src/pages/PlainArt.svelte +++ b/frontend/src/pages/PlainArt.svelte @@ -1,8 +1,9 @@ - + + diff --git a/frontend/wailsjs/go/models.ts b/frontend/wailsjs/go/models.ts index f27dc47..588cc3a 100755 --- a/frontend/wailsjs/go/models.ts +++ b/frontend/wailsjs/go/models.ts @@ -1,3 +1,20 @@ +export namespace api { + + export class RGBA { + + + static createFrom(source: any = {}) { + return new RGBA(source); + } + + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + + } + } + +} + export namespace main { export class Conf { diff --git a/internal/api/unsplash.go b/internal/api/unsplash.go index 33522c8..149bd48 100644 --- a/internal/api/unsplash.go +++ b/internal/api/unsplash.go @@ -41,6 +41,13 @@ type ImageConfig struct { Path string } +type RGBA struct { + R int + G int + B int + A int +} + func NewUnsplashService(apikey string, path string) *UnleaseService { return &UnleaseService{ apikey: apikey, diff --git a/internal/service.go b/internal/service.go index 35ab6f6..51f08c9 100644 --- a/internal/service.go +++ b/internal/service.go @@ -92,11 +92,14 @@ func isImageFile(file string) bool { return false } -func GenerateGradientImage() error { +func GenerateGradientImage(c1 api.RGBA, c2 api.RGBA) error { w, h := 1900, 1200 dc := gg.NewContext(w, h) - stc := color.RGBA{255, 0, 0, 255} - endc := color.RGBA{0, 0, 255, 255} + // stc := color.RGBA{255, 0, 0, 255} + // endc := color.RGBA{0, 0, 255, 255} + + stc := color.RGBA{uint8(c1.R), uint8(c1.G), uint8(c1.B), uint8(c1.A)} + endc := color.RGBA{uint8(c1.R), uint8(c1.G), uint8(c1.B), uint8(c1.A)} for y := 0; y < h; y++ { t := float64(y) / float64(h) @@ -119,23 +122,56 @@ func GenerateGradientImage() error { return png.Encode(f, dc.Image()) } -func HexToRGB(hex string) (int, int, int, error) { - // Remove the '#' if present - hex = strings.TrimPrefix(hex, "#") +func HexToRGBA(hex string) (api.RGBA, error) { + var color api.RGBA - // Parse hex values - r, err := strconv.ParseInt(hex[0:2], 16, 32) - if err != nil { - return 0, 0, 0, err + // Remove the '#' if present + if len(hex) > 0 && hex[0] == '#' { + hex = hex[1:] } - g, err := strconv.ParseInt(hex[2:4], 16, 32) - if err != nil { - return 0, 0, 0, err + + // Handle different formats + switch len(hex) { + case 6: // #RRGGBB + hex += "FF" // Append full alpha (255) for consistency + case 8: // #RRGGBBAA + // Already in the right format + default: + return api.RGBA{}, fmt.Errorf("invalid hex color format: %s", hex) } - b, err := strconv.ParseInt(hex[4:6], 16, 32) - if err != nil { - return 0, 0, 0, err + + // Parse hex components + values := []int{0, 0, 0, 255} // Default to white and full opacity + for i := 0; i < 4; i++ { + val, err := strconv.ParseInt(hex[i*2:i*2+2], 16, 8) + if err != nil { + return api.RGBA{}, fmt.Errorf("error parsing hex color: %v", err) + } + values[i] = int(val) } - return int(r), int(g), int(b), nil + // Assign parsed values + color = api.RGBA{R: values[0], G: values[1], B: values[2], A: values[3]} + return color, nil } + +// func HexToRGB(hex string) (int, int, int, error) { +// // Remove the '#' if present +// hex = strings.TrimPrefix(hex, "#") +// +// // Parse hex values +// r, err := strconv.ParseInt(hex[0:2], 16, 32) +// if err != nil { +// return 0, 0, 0, err +// } +// g, err := strconv.ParseInt(hex[2:4], 16, 32) +// if err != nil { +// return 0, 0, 0, err +// } +// b, err := strconv.ParseInt(hex[4:6], 16, 32) +// if err != nil { +// return 0, 0, 0, err +// } +// +// return int(r), int(g), int(b), nil +// } From ea1df08d353bc7882732ffc14e27936c3e6d223f Mon Sep 17 00:00:00 2001 From: iamhabbeboy Date: Fri, 28 Feb 2025 04:38:18 +0100 Subject: [PATCH 2/4] chore: update plainart logic --- app.go | 13 ++--- frontend/dist/index.html | 2 +- frontend/src/pages/PlainArt.svelte | 61 ++++++++++++++----- internal/service.go | 94 ++++++++++++++++-------------- 4 files changed, 103 insertions(+), 67 deletions(-) diff --git a/app.go b/app.go index 8326719..9985be4 100644 --- a/app.go +++ b/app.go @@ -244,16 +244,12 @@ func deleteFilesWithPrefix(dir, prf string) error { return nil } -func (a *App) GetGradientImage(c []string) error { +func (a *App) GetGradientImage(c []api.RGBA) error { if len(c) == 0 { return errors.New("no colors added") } - rgba1, err := internal.HexToRGBA(c[0]) - - rgba2, err := internal.HexToRGBA(c[1]) - - err = internal.GenerateGradientImage(rgba1, rgba2) + err := internal.GenerateGradientImage(c[0], c[1]) if err != nil { return err } @@ -262,7 +258,10 @@ func (a *App) GetGradientImage(c []string) error { } func (a *App) GetHexToRGBA(color string) (api.RGBA, error) { - return internal.HexToRGBA(color) + fmt.Println(color) + r, _ := internal.HexToRGBA(color) + fmt.Println(r) + return api.RGBA{}, nil } // func (ax *App) GGradient(color string) interface{} { diff --git a/frontend/dist/index.html b/frontend/dist/index.html index 5a9e46f..3bd12f5 100644 --- a/frontend/dist/index.html +++ b/frontend/dist/index.html @@ -10,7 +10,7 @@ --main-color: orange; } - + diff --git a/frontend/src/pages/PlainArt.svelte b/frontend/src/pages/PlainArt.svelte index 7d1f0dc..778dd04 100644 --- a/frontend/src/pages/PlainArt.svelte +++ b/frontend/src/pages/PlainArt.svelte @@ -1,22 +1,22 @@ - + +
diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index d451b7e..ae20826 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -3,14 +3,25 @@ import Setting from './pages/Setting.svelte'; import PlainArt from './pages/PlainArt.svelte'; - import { Router, Route } from 'svelte-routing'; + import type { SvelteComponentTyped } from 'svelte'; + import { + Router as RouterComponent, + Route as RouteComponent, + } from 'svelte-routing'; + + const Router: typeof SvelteComponentTyped = RouterComponent; + const Route: typeof SvelteComponentTyped = RouteComponent; + import AbstractArt from './pages/AbstractArt.svelte'; + import Ai from './pages/AI.svelte'; export let url = '';
-
- + + + +
diff --git a/frontend/src/components/CloseIcon.svelte b/frontend/src/components/CloseIcon.svelte new file mode 100644 index 0000000..fc982cd --- /dev/null +++ b/frontend/src/components/CloseIcon.svelte @@ -0,0 +1,18 @@ + + + diff --git a/frontend/src/components/ErrorIcon.svelte b/frontend/src/components/ErrorIcon.svelte new file mode 100644 index 0000000..6ac54f8 --- /dev/null +++ b/frontend/src/components/ErrorIcon.svelte @@ -0,0 +1,19 @@ + + + diff --git a/frontend/src/components/InfoIcon.svelte b/frontend/src/components/InfoIcon.svelte new file mode 100644 index 0000000..4422eb1 --- /dev/null +++ b/frontend/src/components/InfoIcon.svelte @@ -0,0 +1,18 @@ + + + diff --git a/frontend/src/components/ListImages.svelte b/frontend/src/components/ListImages.svelte index 2418ff9..edf7fac 100644 --- a/frontend/src/components/ListImages.svelte +++ b/frontend/src/components/ListImages.svelte @@ -1,73 +1,31 @@ diff --git a/frontend/src/components/Navigation.svelte b/frontend/src/components/Navigation.svelte index 79da662..aed1e5a 100644 --- a/frontend/src/components/Navigation.svelte +++ b/frontend/src/components/Navigation.svelte @@ -10,11 +10,7 @@ import DownloadImage from '../../src/assets/images/download.svg'; import ConfigImage from '../../src/assets/images/config.svg'; - import PlainArtImage from '../../src/assets/images/plain.svg'; - - import AbstractArt from '../../src/assets/images/art.svg'; - - import AIArt from '../../src/assets/images/ai.svg'; + import { dispatcher } from '../../src/utilities/util'; let isLoading = true; @@ -23,8 +19,10 @@ async function downloadImages() { try { isLoading = true; - const res = await DownloadImages(); + dispatcher('downloading'); + await DownloadImages(); } catch (e) { + console.log(e); } finally { const result = await GetDownloadedImages(); images = result ?? []; @@ -50,7 +48,7 @@ class="mr-1 dark:brightness-0 dark:invert-[1]" /> Images - +
+ export let width = '1em'; + + + diff --git a/frontend/src/components/Toast.svelte b/frontend/src/components/Toast.svelte new file mode 100644 index 0000000..af8317d --- /dev/null +++ b/frontend/src/components/Toast.svelte @@ -0,0 +1,66 @@ + + + + + diff --git a/frontend/src/components/Toasts.svelte b/frontend/src/components/Toasts.svelte new file mode 100644 index 0000000..02395d7 --- /dev/null +++ b/frontend/src/components/Toasts.svelte @@ -0,0 +1,32 @@ + + +{#if $toasts} +
+ {#each $toasts as toast (toast.id)} + dismissToast(toast.id)}>{toast.message} + {/each} +
+{/if} + + diff --git a/frontend/src/pages/AI.svelte b/frontend/src/pages/AI.svelte new file mode 100644 index 0000000..06fe6f8 --- /dev/null +++ b/frontend/src/pages/AI.svelte @@ -0,0 +1,13 @@ + + +
+ +
+

Welcome to the AI Page

+

This is a template for your AI page.

+
+
\ No newline at end of file diff --git a/frontend/src/pages/AbstractArt.svelte b/frontend/src/pages/AbstractArt.svelte new file mode 100644 index 0000000..9cea05d --- /dev/null +++ b/frontend/src/pages/AbstractArt.svelte @@ -0,0 +1,13 @@ + + diff --git a/frontend/src/pages/Main.svelte b/frontend/src/pages/Main.svelte index 08b53fd..07a5619 100644 --- a/frontend/src/pages/Main.svelte +++ b/frontend/src/pages/Main.svelte @@ -1,45 +1,87 @@ - +
+ + {#if !isLoading && images.length === 0} +
+ +

+ No Images found in your library +

+

To get started click on the download button.

+
+ {/if} + {#if isLoading} +
+ +

Processing...

+
+ {:else} + + {/if} +
diff --git a/frontend/src/pages/PlainArt.svelte b/frontend/src/pages/PlainArt.svelte index 778dd04..2a18b40 100644 --- a/frontend/src/pages/PlainArt.svelte +++ b/frontend/src/pages/PlainArt.svelte @@ -71,57 +71,84 @@ } colors = [...colors, color]; }; + + const handleNewColor = (event: any) => { + colors = [...colors, event.target.value]; + };
+
+
+ + + + + +
+
+ +
+
+ skldfj +
+
+ skldfj +
+
+
- {#each commonColors as c, key} + {#each commonColors as c}
handleSelectColor(c)} on:keydown={() => handleSelectColor(c)} - class="mt-5 cursor-default transition-all hover:opacity-70 rounded-full pt-9 text-center w-[100px] h-[100px] ml-5" + class="mt-5 cursor-default border-2 transition-all hover:opacity-70 rounded-full pt-9 text-center w-[100px] h-[100px] ml-5" >
{/each} +
+ + +
-
- - - - -
- -
+
{#each colors as color}
(colors = colors.filter((c) => c !== color))} on:keydown={() => (colors = colors.filter((c) => c !== color))} style="background-color: {color}" - class="mt-5 cursor-default transition-all hover:opacity-70 rounded-full pt-9 text-center w-[100px] h-[100px] ml-5" + class="mt-5 cursor-default border-2 transition-all hover:opacity-70 rounded-full pt-9 text-center w-[100px] h-[100px] ml-5" >
{/each}
diff --git a/frontend/src/pages/Setting.svelte b/frontend/src/pages/Setting.svelte index a141b7e..858ede6 100644 --- a/frontend/src/pages/Setting.svelte +++ b/frontend/src/pages/Setting.svelte @@ -86,16 +86,18 @@

Configuration

Selected directory path

+ {defaultPath} +

+
+ Suggestions: + nature, + landscape, + lamborghini, + tokyo, + africa +
- + /> --> +