I've got a project I'm pretty pleased with, but am now looking for some optimization.
Things work the way I want/need them to using HSB color mode. I'm doing a multi-pass pixel scan and summing the results. The main goal is to generate a static output, but there is some value in animating the result also, and in any case it would be great if I could figure out how to speed things up a bit.
I've eliminated get() and set() successfully, but am now looking at refactoring using bitwise operations. Do I need to convert to RGB first, and if so, would the extra calculations cancel out any benefits?
I'm perfectly happy to show my code, but I thought I'd start with a basic question to see if I'm totally barking up a wrong tree.
I'm trying to better understand the underlying mechanisms behind blending colors. This discussion
here is informative.
Processing provides the build-in blendColor method. However, when I print the results of blended color values, and then use get() to verify, there are some discrepancies. These tend to be minor, but I'm curious as to their origin. Is it a rounding error, or is my code problematic? I have tried both BLEND and ADD modes.
Here is the test code:
color colorBG; // Colors must be assigned after colorMode.
color color1;
color color2;
void setup() {
size(200, 200);
noStroke();
// colorMode(HSB); // See if this changes things.
colorBG = color(0);
color1 = color(255, 10, 10, 100);
color2 = color(10, 10, 255, 100);
// Using the Processing function to get the resulting color (in hex). Parameter order is important.
println("Click the mouse to confirm these blended color values:\n");
println("Color1 over BG color: " + hex(blendColor(colorBG, color1, BLEND)));
println("Color2 over BG color: " + hex(blendColor(colorBG, color2, BLEND)));
color color3 = blendColor(colorBG, color1, BLEND);
This may be something well known, but I'm just now bumping into it. I've searched the reference and forum however, and am not seeing it. Will happily delete the question if it's a duplicate.
Why does P3D not allow for an alpha channel when using point()? Or is it supposed to, but doesn't on some systems? Is it a Processing thing, or a hardware thing, or what?
All other modes work as expected. Test code below confirms P3D shows a black point over the white one, when it should be invisible (as it indeed is in all other modes).
I'm trying to load a saved preferences file which resets a number of parameters. It works beautifully when I select a valid file, but crashes pretty consistently (not all the time) if I abort the file-select process, or if I choose an invalid file.
I'm using P5 1.5.1, OSX 10.6.8.
The condensed code below reproduces the problem on my system. Can anyone else confirm this behavior? Spot the problem, suggest a fix?
TIA,
RA
int x = 0; int y;
void draw() { // Proxy draw stuff here for debugging feedback.
This question is related to, but different from what is discussed
here.
If random() or noise() are not called in conjunction with randomSeed() or noiseSeed(), is there still a seed value at work behind the scenes? One that gets changed with each call? Or is the seedless process somehow completely different from the seeded one?
More to the point, if I'm playing with a non-seeded random or noisy sketch, I expect to get different results each time. But if I happen across a result that is particularly interesting, is there any way reproduce that result after the fact? That is, could some code be added which tracks how a random or noisy function got its start?
I do realize I could set a seed value from the get-go (even a randomized seed value), and print that to the console, so I'd know what seed had produced a given result. I was just wondering if there were any way to excavate the seed or genesis or ur-condition of random or noise without an explicitly specified seed. TIA.
For example, using Shiffman's 1D Perlin case below, how would I initialize the ellipse to
always start in the middle of the window at runtime, and then
smoothly proceed with its Perlin perambulations?
float xoff = 0.0;
float xincrement = 0.01;
void setup() {
size(200,200);
background(0);
frameRate(30);
smooth();
noStroke();
}
void draw()
{
// Create an alpha blended background
fill(0, 10);
rect(0,0,width,height);
//float n = random(0,width); // Try this line instead of noise
// Get a noise value based on xoff and scale it according to the window's width
float n = noise(xoff)*width;
// With each cycle, increment xoff
xoff += xincrement;
// Draw the ellipse at the value produced by perlin noise
This is driving me nuts, because there must be a simple way to do this. I'd like to toggle between loop() and noLoop() with a mouse click. I've tried booleans, I've looked at all the mouse functions in the reference, I've searched the forums and the wider web.
Specifically, while draw is running, I'd like to click the mouse and halt draw. Then I'd like to click the mouse again and resume. In other words, I'm looking for a "pause" feature (not to be confused with delay()). I can stop draw with a left click, and resume with a right click, but that won't work for my application. It needs to be a toggle with the left click only.