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

Problems with Python and JavaScript #22

Open
JaysonP65132 opened this issue Jun 29, 2024 · 1 comment
Open

Problems with Python and JavaScript #22

JaysonP65132 opened this issue Jun 29, 2024 · 1 comment

Comments

@JaysonP65132
Copy link

I am having trouble with Mixbox on Programiz, a Python I used the following code.
`import mixbox

rgb1 = (0, 33, 133) # blue
rgb2 = (252, 211, 0) # yellow
t = 0.5 # mixing ratio

rgb_mix = mixbox.lerp(rgb1,rgb2,t)

print(rgb_mix)`

But this is what I recieved.

`ERROR!
Traceback (most recent call last):
File "<main.py>", line 3, in
ModuleNotFoundError: No module named 'mixbox'

=== Code Exited With Errors ===`

Alternatively, I was tying to make Mixbox mix multiple colors work in a JavaScript Compiler. Programiz does that too, but I also used Tynker, since it has an HTML extension. I was able to make the simple usage work on a HTML. This is my code.
`var rgb1 = "rgb(0, 33, 133)"; // blue
var rgb2 = "rgb(252, 211, 0)"; // yellow
var t = 0.5; // mixing ratio

var mixed = mixbox.lerp(rgb1, rgb2, t);

console.log(mixed);`
It successfully filled the screen with the mix result. But when I tried to add the following code on the main JavaScript

`var z1 = mixbox.rgbToLatent(rgb1);
var z2 = mixbox.rgbToLatent(rgb2);
var z3 = mixbox.rgbToLatent(rgb3);

var zMix = new Array(mixbox.LATENT_SIZE);

for (var i = 0; i < zMix.length; i++) { // mix:
zMix[i] = (0.3z1[i] + // 30% of rgb1
0.6
z2[i] + // 60% of rgb2
0.1*z3[i]); // 10% of rgb3
}

var rgbMix = mixbox.latentToRgb(zMix);`

nothing happens. Same thing with Python. I additionally installed Mixbox in a command line, but it couldn't help with code. If you can help me make both of these work, I will be very thankful

@cheunste
Copy link

cheunste commented Jul 7, 2024

ModuleNotFoundError: No module named 'mixbox'

You're getting that error because programiz doesn't recognize mixbox as a library. You need to have mixbox installed from the pip package manager via running the pip install pymixbox command in command line and as python will not come with mixbox. Although I doubt you can do a pip install on programiz or most online python interpreter. But either way, you need to have mixbox installed before you can use it.

For the javascript item, it works for me after I define rgb3. So the following three color mix works for me.

let rgb1= 'rgb(7,67,153)'; //cyan
let rgb2= 'rgb(203,17,132)'; //magenta
let rgb3= 'rgb(245,199,1)'; //yellow

var z1 = mixbox.rgbToLatent(rgb1);
var z2 = mixbox.rgbToLatent(rgb2);
var z3 = mixbox.rgbToLatent(rgb3);

var zMix = new Array(mixbox.LATENT_SIZE);

for (var i = 0; i < zMix.length; i++) { // mix:
zMix[i] = (0.3*z1[i] + // 30% of rgb1
0.6*z2[i] + // 60% of rgb2
0.1*z3[i]); // 10% of rgb3
}

var rgbMix = mixbox.latentToRgb(zMix);

Furthermore, that javascript code of yours might have been copied from the example, but it wouldn't have worked as it is also missing the * after the 0.3 and 0.6. So it should have been

for (var i = 0; i < zMix.length; i++) { // mix:
zMix[i] = (0.3*z1[i] + // 30% of rgb1
0.6*z2[i] + // 60% of rgb2
0.1*z3[i]); // 10% of rgb3
}

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

2 participants