Stuck at number 96

Hi Any Forumsuys

I'm stuck at challenge 96 of picrel using C, when test(191, 191, 191) is ran, it outputs a hsl color of value 0°, 0, 0. Seems function calc_l is always returning 0.0 for some reason. Any help is highly appreciated :(

Here's the files:
header file: pastebin.com/Ui4hzxSp
c file: pastebin.com/QusYRmss
app file (for testing): pastebin.com/NcQ5KWXF

I'm using this for reference (values and formulas): rapidtables.com/convert/color/rgb-to-hsl.html

Attached: mongolian_basket_weaving_code_challenges.png (3840x2160, 1.61M)

Other urls found in this thread:

pastebin.com/zeLsxSUv
pastebin.com/5SxJFdj2
pastebin.com/wfcTAuXA
hslpicker.com/#808080
pastebin.com/rkTi36wL
pastebin.com/Cz0X9DBa
pastebin.com/AXcY22jT
twitter.com/NSFWRedditImage

i can't help you aside from recommending you just use hex codes but rolling

fuck. reroll.

Nope, you will work on 83 and you will be happy.

roll

roller

fuck

r

roll

Forgot to mention updated function signatures in earlier post. Anyway: a few general C tips that you desperately need.
Will start looking into the actual problem now.
// ALWAYS use parentheses around macro arguments (linebreaks added by
// clang-format, just ignore that)
#define CMAX(r, g, b) \
((r) > (g) ? (r) > (b) ? (r) : (b) : (g) > (b) ? (g) : (b))
#define CMIN(r, g, b) \
((r) < (g) ? (r) < (b) ? (r) : (b) : (g) < (b) ? (g) : (b))
#define CDELTA(max, min) ((max) - (min))

HSL_color rgb_to_hsl(RGB_color rgb);
void rgb_to_hsl2(RGB_color *rgb, HSL_color *hsl);

void foo() {
// small structs such as these can be passed by value
// (see modified function signature above)
RGB_color rgb = {.r = r, .g = g, .b = b};
HSL_color hsl = rgb_to_hsl(rgb);
// or via pointers to stack memory
HSL_color hsl2;
rgb_to_hsl2(&rgb, &hsl);
// If this doesn't yet make sense to you: keep going, it will.
}

Thanks for the help user!

Update: managed to solve the problem in OP using the macros, now the problem is actually making the conversion from hsl back to rgb.
Here's the updated files:
pastebin.com/zeLsxSUv
pastebin.com/5SxJFdj2
pastebin.com/wfcTAuXA

(nvm the extra comments and printfs, copied everything real quick just so you don't waste your time with stuff that has been solved already, again, many thanks!)

roll

Complimentary is just the opposite colour on the colour wheel.

Looks like an interesting one. I think you should go for it. Me on the other hand, I'll reroll if I land on 83.

>now the problem is actually making the conversion from hsl back to rgb
What's the expected output? What do you get instead?

for example, for input (191,191,191) i should be receiving around (189,189,189), but am receiving (255,255,255) instead.

Output from above example:
```
rgb(191, 191, 191)
hsl(0.000000°, 0.000000, 74.000000)
hsl(180.000000°, 0.000000, 74.000000)
rgb(255, 255, 255)
```

I'm basically using app.c as a little test suite, and then i use this site: hslpicker.com/#808080 to check if the conversions make sense

fuck it

ooh mama

I suspect your memcpy logic may be at fault. What I did was replace it with this and I get (188, 188, 188) for (191, 191, 191):
struct raw_rgb {
float r;
float g;
float b;
};

static struct raw_rgb get_raw_rgb(HSL_color *hsl) {
float c = round((1 - fabs((2 * hsl->l) - 1)) * hsl->s) / 100;
float x = round(c * (1 - fabs(((int)(hsl->h / BASEDEG) % 2) - 1)));

if (hsl->h >= 0 && hsl->h h >= 60 && hsl->h h >= 120 && hsl->h h >= 180 && hsl->h h >= 240 && hsl->h h >= 300 && hsl->h l) - 1)) * hsl->s) / 100;
float x = round(c * (1 - fabs(((int)(hsl->h / BASEDEG) % 2) - 1)));
float m = round(hsl->l - (c / 2));

printf("THE H HELLL: %f\n", (2 * hsl->l));

// printf("C OVER 2: %f %f\n", hsl->l - ((c / 100) / 2), c / 100);

// printf("AAAAAAAAAAAA: %f\n", (1 - fabs((2 * hsl->l) - 1)) * hsl->s);
printf("QWEQOWEQeq: %f %f %f --- %f %f %f\n", c, x, m, hsl->h, hsl->s,
hsl->l);

// printf("HUUUUURR: %f\n", (x + m) * 255);
struct raw_rgb raw = get_raw_rgb(hsl);

rgb->r = ((raw.r + m) * 255) / 100;
rgb->g = ((raw.g + m) * 255) / 100;
rgb->b = ((raw.b + m) * 255) / 100;

return rgb;
}

Purely mechanical transformation, didn't think about colors or anything at all.

Roll

Managed to get it working! (well mostly, last test case is a bit iffy, but i also just gave it some random numbers, so... yea).

Here's the updated files (needs some extra cleanup, but works):
pastebin.com/rkTi36wL
pastebin.com/Cz0X9DBa
pastebin.com/AXcY22jT

Many thanks for the help anons, have picrel as a token of my gratitude!

Attached: 1639225414220.jpg (1262x825, 286.68K)

ez

pub struct Color { red: u8, green: u8, blue: u8 }

pub fn complementary_color(color: Color) -> Color {
Color {
red: 255 - color.red,
green: 255 - color.green,
blue: 255 - color.blue
}
}