Commit de346dd6 authored by Aapeli's avatar Aapeli

Drew board and colours, set it up

parent 8a48e6d9
class Board {
// probably bad form to name somethign "colour" if there already is a "color"
Colour[][] bPixels;
int bWidth, bHeight;
Board(int w, int h, Colour bg) {
bWidth = w; bHeight = h;
bPixels = new Colour[w][h];
for (int y = 0; y < bHeight; y++) {
for (int x = 0; x < bWidth; x++) {
if (x == 50 && y == 50) {
println("created 50 50");
println(bPixels[x][y]);
}
bPixels[x][y] = new Colour(bg);
if (x == 50 && y == 50) {
println(bPixels[x][y]);
}
}
}
}
Colour getPixel(int x, int y) {
return bPixels[x][y];
}
void Draw() {
for (int y = 0; y < bHeight; y++) {
for (int x = 0; x < bWidth; x++) {
set(x, y, bPixels[x][y].getColor());
}
}
}
}
\ No newline at end of file
class Colour {
float r, g, b, a;
Colour(float rS, float gS, float bS, float aS) {
r = rS; g = gS; b = bS; a = aS;
}
Colour() {
r = 0; g = 0; b = 0; a = 0;
}
Colour(Colour c) {
r = c.r; g = c.g; b = c.b; a = c.a;
}
void darken(float rS, float gS, float bS, float aS) {
r += rS; g += gS; b += bS; a += aS;
}
void lighten(float rS, float gS, float bS, float aS) {
r -= rS; g -= gS; b -= bS; a -= aS;
}
void darken(Colour c) {
r += c.r; g += c.g; b += c.b; a += c.a;
}
Colour multiply(float p) {
return new Colour(r * p, g * p, b * p, a);
}
color getColor() {
return color(round(r * 255), round(g * 255), round(b * 255), round(a * 255));
}
}
\ No newline at end of file
float penX, penY;
Board board;
Colour penColour;
void setup() {
size(800, 500);
board = new Board(width, height, new Colour(0, 0, 0, 1));
penColour = new Colour(0, 0, 1, 1);
noSmooth();
penX = 50;
penY = 50;
}
void mouseMoved() {
penX = mouseX;
penY = mouseY;
drawCurrentPixel();
}
void draw () {
board.Draw();
}
void drawCurrentPixel() {
board.getPixel(round(penX), round(penY)).darken(penColour.multiply(0.5));
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment