xxxxxxxxxx
69
// Extract the colour values from a palette strip.
// G Edwards, 01 Aug 2019
let imageName = "coal-loader-palette-trimmed.png";
let imageURL = "https://modulostudio.s3-ap-southeast-2.amazonaws.com/images/coal-loader-palette-trimmed.png";
let img = null;
// Load the image in the preload() function, waits until complete.
function preload() {
prt("Loading", imageURL);
img = loadImage(imageURL, () => prt("Loaded ok"), () => prt("Load failed"));
//img = loadImage(imageName, () => prt("Loaded ok"), () => prt("Load failed"));
}
// Not much to do in setup()
function setup() {
createCanvas(1350,150);
}
function draw() {
background(color(128));
// img = createImage(imageURL);
image(img, 0, 30);
writer = createWriter("paletteList.txt");
let offset = 8;
let step = 15.34; // trial and error number. Palette image must have been scaled.
for( let n = 0; n < 85; n++) {
strokeWeight(3);
stroke(255,0,0);
let xx = n * step + offset;
point(xx, 45); // put a point on the palette cell, to check our positioning
let clr = get(xx, 40); // get the cell colour - avoid the point of course !
fill(clr); // draw a square to confirm colours are correct
noStroke();
square(n*step + 2, 12, 12);
let hexColour = (n+1).toString() + ":" + hex(red(clr),2) + hex(green(clr),2) + hex(blue(clr),2);
prt(hexColour);
writer.print(hexColour);
}
writer.close();
noLoop();
}
function prt(args) {
console.log(args);
}