//hey folks I just put this together for something I was making - it's a pretty simple thing to do but I'm sure this job gets repeated a lot so thought I'd post it- please let me have any criticism or corrections
A simple question: Is resize() supposed to be able to make images larger or not? The below code causes the code to apparently not compile. There is no error in the console but the app window doesn't open. Changing to resize smaller or commenting the line causes it to work fine. The reference makes no mention of this restriction. Thanks, Tom
in
this thread I asked about good implementations for heatmapping. Well I did some digging and the below is my implementation of Shepard's method. It is based on the explanation from
this excellent site so most credit is to the authors there.
I wrote the below heat mapping function. It works reasonably well but sometimes gives me an out of memory error. I wonder is anyone has any suggestions for optimisation. I'm also controlling the fall off of the points a bit brutally with a multiplier (called fallOff). I wonder if this should also be some kind of logarithmic function? Cheers folks, hopefully this thread will expand a bit and we can get good solid simple solution!
I'm working on a sketch which is about encoding books as sequences of colours where each pixel value corresponds to a single char from the text. So 'a' gives a hue value of 97 for example. In my sketch I set the colorMode(HSB, 255) then populate part of the pixels array with the char values from a string. What's happening though is that when I read the values back out of the pixels array some of them are correct but some aren't. For example a sequence of chars which should read 'projects' reads 'prnjdbtr'. So some characters are correct but some are out by -1. I assume that this must be something to do with the setting for colorMode()? What's very confusing is that if I try the same process in RGB space and extract the red channel it works perfectly. I must be missing something obvious but if anyone could give me a nudge I'd really appreciate it. Code below.
String msg;
boolean useHue=true;
void setup() {
size(500, 500);
//load some text - content isn't important in this context
msg= "It has been a decade since Will Holland aka Quantic released his first album on Tru Thoughts. Twelve albums later and Quantic has a vast discography; funky, soulful vibes with the Quantic Soul Orchestra, Flowering Inferno's reggae infused dub, cumbia with The Combo Barbaro, and more. The Best Of Quantic album highlights the stunning range of his work, bringing together some of the biggest tracks from across his many projects.";
if (useHue) colorMode(HSB, 255);
}
void draw() {
background(0);
int x=0;
int y=0;
//set pixels with char values from the string, the sketch encodes text as a hue values
loadPixels();
for (int i=0;i<msg.length();i++) {
color aColor =color(msg.charAt(i), 255, 255);
pixels[i]=aColor;
}
updatePixels();
x=0;
y=0;
loadPixels();
for (int i=0;i<msg.length();i++) {
//get the colour at this pixel index - this SHOULD be the same as the char value of msg at the same index.
color aColor= pixels[i];
//here's the weird thing - in RGB colour space this works (by extracting the red channel ) but if we use hue then SOME of the char values come out as you'd expect but some have a char value of one less than the should be! eek! any thoughts?
if (useHue) {
println(i+ " value from pixels array: "+(char)hue(aColor)+ " value from original string "+msg.charAt(i));
}
else {
println(i+ " value from pixels array: "+(char)red(aColor)+ " value from original string "+msg.charAt(i));