Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limiting the Colour Palette #70

Open
robbiebarrat opened this issue Nov 30, 2017 · 11 comments
Open

Limiting the Colour Palette #70

robbiebarrat opened this issue Nov 30, 2017 · 11 comments

Comments

@robbiebarrat
Copy link

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.

@fogleman
Copy link
Owner

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`)

@robbiebarrat
Copy link
Author

woah; that's really clever - thank you!

@robbiebarrat
Copy link
Author

robbiebarrat commented Nov 30, 2017

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...

@robbiebarrat robbiebarrat reopened this Nov 30, 2017
@fogleman
Copy link
Owner

Use go run main.go instead of primitive

@robbiebarrat
Copy link
Author

robbiebarrat commented Nov 30, 2017

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...

@robbiebarrat
Copy link
Author

??

@fogleman
Copy link
Owner

fogleman commented Dec 4, 2017

Dunno dude, it worked for me.

@robbiebarrat
Copy link
Author

robbiebarrat commented Dec 4, 2017

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?

@fogleman
Copy link
Owner

fogleman commented Dec 4, 2017

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

@robbiebarrat
Copy link
Author

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

@kajfasz
Copy link

kajfasz commented Jul 8, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants