fogleman/primitive

Limiting the Colour Palette

robbiebarrat opened this issue · 11 comments

Is there any way to specify a list of available colours? E.g. if I only wanted it to draw with primary colours; (red, yellow, and blue), could I specify this?

Would it be able to learn to mix the available colours and better approximate an image that uses more colours?

I'm totally open to all solutions; even the extremely hacky - thanks.

Hacky:

Before returning a color on this line...

https://github.com/fogleman/primitive/blob/master/primitive/core.go#L33

...return a different color instead, perhaps by choosing the nearest from a palette.

For example, you can add this snippet before the return statement:

if r > 128 {
	r = 255
} else {
	r = 0
}
if g > 128 {
	g = 255
} else {
	g = 0
}
if b > 128 {
	b = 255
} else {
	b = 0
}```

...and it does a decent job. (best if you let it choose alpha with `-a 0`)

woah; that's really clever - thank you!

Sorry; i'm super new to go, but those changes don't seem to have any affect; here's my code:

        r := clampInt(int(rsum/count)>>8, 0, 255)
        g := clampInt(int(gsum/count)>>8, 0, 255)
        b := clampInt(int(bsum/count)>>8, 0, 255)

        if r > b && r > g {
                r = 255
                g = 0
                b = 0
        } else {
                r = 0
        }
        if g > r && g > b {
                g = 255
                r = 0
                b = 0
        } else {
                g = 0
        }
        if b > r && b > g {
                b = 255
                g = 0
                r = 0
        } else {
                b = 0
        }
        alpha = 50

        myslice := []int{r,g,b,alpha}
        fmt.Printf("%#v\n", myslice)

        return Color{r, g, b, alpha}

i imported fmt at the top and everything; do i have to recompile the program or something for it to change? This is literally the first time i've ever used go...

Use go run main.go instead of primitive

I've been doing that - as a test i tried changing that last line to return Color{255, 0, 0, alpha}, in hopes that it would return a red image, but it returned a normal multicoloured image instead...

Dunno dude, it worked for me.

Could you please detail what commands you ran after editing the file?

Did you just do vi core.go - do your edits - cd .. and then go run main.go (with arguments ofc)? Nothing else?

Yeah that's it. Show me what you tried.

I'm at work right now but once i get home in a few hours I'll post a comment with my whole core.go file and the stuff I've tried.

Thanks x100 for helping me out

Hi! I've the same problem as @robbiebarrat - sollution that you add in comment above have no effect, but what I'm trying to do is convert monochromatic, grey-scalled image into also monochromatic picture, but e.g. red-scalled (I'm not sure if such thing even exist in english 😃 )

@robbiebarrat, @fogleman - did you find sollution that worked for you guys?

EDIT:
Sorry for comment, but I found after some times what I was doing wrong. All magic is to build application inside the go workspace and run command go install in directory where main.go is.