Skip to content

Commit

Permalink
Merge pull request #42 from brittni-and-the-polar-bear/22-create-basi…
Browse files Browse the repository at this point in the history
…c-color-classes

22 create basic color classes
  • Loading branch information
azurepolarbear authored Jan 7, 2024
2 parents 4d0a973 + 1cd035a commit a6d5e72
Show file tree
Hide file tree
Showing 37 changed files with 1,196 additions and 149 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ A template for new brittni and the polar bear generative art projects using [Typ
The source code of this project is licensed under the [GNU Affero General Public Version 3.0 License](https://www.gnu.org/licenses/agpl-3.0.en.html). The full text of the license can be found in the LICENSE file of the root directory.

The visual outputs of this distribution of the source code are licensed under the [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License](https://creativecommons.org/licenses/by-nc-nd/4.0/). The full text of the license can be found in the OUTPUT-LICENSE file of the root directory.

# Resources

## Color Names

[Color Namer](https://colornamer.robertcooper.me/)

## Color Collections

[coolors](https://coolors.co/)
7 changes: 5 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Brittni Watkins.
* Copyright (C) 2023-2024 Brittni Watkins.
*
* This file is a part of brittni and the polar bear's Generative Art Project Template,
* which is released under the GNU Affero General Public License, Version 3.0.
Expand All @@ -15,7 +15,7 @@
* See the GNU Affero General Public License for more details.
*/

import type { JestConfigWithTsJest } from 'ts-jest';
import type {JestConfigWithTsJest} from 'ts-jest';

const config: JestConfigWithTsJest = {
collectCoverage: true,
Expand All @@ -27,6 +27,9 @@ const config: JestConfigWithTsJest = {
'^assets': '<rootDir>/assets',
'^color$': '<rootDir>/src/common/color',
'^color/factory$': '<rootDir>/src/common/color/factory',
'^color/factory/collection$': '<rootDir>/src/common/color/factory/collection',
'^all-colors': '<rootDir>/src/common/color/factory/collection/colors',
'^all-collections': '<rootDir>/src/common/color/factory/collection/collections',
'^p5-lib$': '<rootDir>/src/common/p5',
'^random$': '<rootDir>/src/common/random',
'^range$': '<rootDir>/src/common/range',
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
"build": "echo '(1/2): Removing old output'; sh ./scripts/delete-out.sh; echo '(2/2): Building project'; rollup --config",

"start": "echo '(1/2): Removing old output'; sh ./scripts/delete-out.sh; echo '(2/2): Building project and starting development server'; rollup --config --watch",

"example:color-grid:build": "sh ./scripts/color-grid.sh",
"example:color-grid:start": "sh ./scripts/color-grid.sh -d true"
"example:color-grid:build": "sh ./scripts/rollup.sh -p ./examples/color/color-grid.ts -d false",
"example:color-grid:start": "sh ./scripts/rollup.sh -p ./examples/color/color-grid.ts -d true",
"example:100-days:build": "sh ./scripts/rollup.sh -p projects/100-days/100-days-progress.ts -d false",
"example:100-days:start": "sh ./scripts/rollup.sh -p projects/100-days/100-days-progress.ts -d true",
"project:genuary-1:build": "sh ./scripts/rollup.sh -p ./projects/genuary-2024/1-particles-lots-of-them/sketch.ts -d false",
"project:genuary-1:start": "sh ./scripts/rollup.sh -p ./projects/genuary-2024/1-particles-lots-of-them/sketch.ts -d true",
"project:genuary-2:build": "sh ./scripts/rollup.sh -p ./projects/genuary-2024/2-no-palettes/sketch.ts -d false",
"project:genuary-2:start": "sh ./scripts/rollup.sh -p ./projects/genuary-2024/2-no-palettes/sketch.ts -d true"
},
"repository": {
"type": "git",
Expand Down
58 changes: 58 additions & 0 deletions projects/100-days/100-days-progress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2023-2024 Brittni Watkins.
*
* This file is a part of brittni and the polar bear's Generative Art Project Template,
* which is released under the GNU Affero General Public License, Version 3.0.
* You may not use this file except in compliance with the license.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. See LICENSE or go to
* https://www.gnu.org/licenses/agpl-3.0.en.html for full license details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*/

import {sketch} from "sketch";
import {Color, getSingleDimensionIndex} from "common";

sketch.setup = (): void => {
sketch.createCanvas(500, 500);
}

sketch.draw = (): void => {
const complete: number = 6;
const rows: number = 10;
const cols: number = 10;
const black: Color = new Color(sketch.color('#000'));
const green: Color = new Color(sketch.color('#228B22'));
const white: Color = new Color(sketch.color('#F0F8F8'));
const boxWidth: number = sketch.width / cols;
const boxHeight: number = sketch.height / rows;
sketch.background(255);
sketch.stroke(black.color);
sketch.strokeWeight(3);

for (let row: number = 0; row < rows; row++) {
const y: number = boxHeight * row;

for (let col: number = 0; col < cols; col++) {
const x: number = boxWidth * col;
const index: number | undefined = getSingleDimensionIndex(row, col, rows, cols);

if (typeof index === 'number' && index < complete) {
sketch.fill(green.color);
} else {
sketch.fill(white.color);
}

sketch.rect(x, y, boxWidth, boxHeight);
}
}
}

sketch.resizeCanvas = (): void => {
return;
}
138 changes: 138 additions & 0 deletions projects/genuary-2024/1-particles-lots-of-them/sketch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2024 Brittni Watkins.
*
* This file is a part of brittni and the polar bear's Generative Art Project Template,
* which is released under the GNU Affero General Public License, Version 3.0.
* You may not use this file except in compliance with the license.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. See LICENSE or go to
* https://www.gnu.org/licenses/agpl-3.0.en.html for full license details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*/

import {sketch} from 'sketch';
import {Color, P5Lib, randomFloat, randomInt, SketchContext} from 'common';

let c1: Color;
let c2: Color;
let c3: Color;

let p1: P5Lib.Vector;
let p2: P5Lib.Vector;
let p3: P5Lib.Vector;

let p1Rate: P5Lib.Vector;
let p2Rate: P5Lib.Vector;
let p3Rate: P5Lib.Vector;

let points: P5Lib.Vector[] = [];
let pointRates: P5Lib.Vector[] = [];

sketch.setup = (): void => {
sketch.createCanvas(sketch.windowWidth, sketch.windowHeight);
SketchContext.initialize(sketch);

c1 = new Color(sketch.color(randomInt(0, 255), randomInt(0, 255), randomInt(0, 255)));
c2 = new Color(sketch.color(randomInt(0, 255), randomInt(0, 255), randomInt(0, 255)));
c3 = new Color(sketch.color(randomInt(0, 255), randomInt(0, 255), randomInt(0, 255)));

p1 = new P5Lib.Vector(randomFloat(0, sketch.width), randomFloat(0, sketch.height));
p2 = new P5Lib.Vector(randomFloat(0, sketch.width), randomFloat(0, sketch.height));
p3 = new P5Lib.Vector(randomFloat(0, sketch.width), randomFloat(0, sketch.height));

p1Rate = new P5Lib.Vector(randomFloat(-3, 3), randomFloat(-3, 3));
p2Rate = new P5Lib.Vector(randomFloat(-3, 3), randomFloat(-3, 3));
p3Rate = new P5Lib.Vector(randomFloat(-3, 3), randomFloat(-3, 3));

for (let i: number = 0; i < 5_000; i++) {
points.push(new P5Lib.Vector(randomFloat(0, sketch.width), randomFloat(0, sketch.height)));
pointRates.push(new P5Lib.Vector(randomFloat(-3, 3), randomFloat(-3, 3)));
}
}

sketch.draw = (): void => {
sketch.fill(0, 100);
sketch.rect(-10, -10, sketch.width + 10, sketch.height + 10);

const pc1: PointAndColor = {
point: p1,
color: c1
}

const pc2: PointAndColor = {
point: p2,
color: c2
}

const pc3: PointAndColor = {
point: p3,
color: c3
}

points.forEach((p: P5Lib.Vector, index: number): void => {
let c: Color = calculateColor(new P5Lib.Vector(p.x, p.y), pc1, pc2, pc3);
sketch.fill(c.color);
sketch.noStroke();
sketch.ellipse(p.x, p.y, 3, 3);
let rate: P5Lib.Vector = pointRates[index];
moveVector(p, rate);
});

moveVector(p1, p1Rate);
moveVector(p2, p2Rate);
moveVector(p3, p3Rate);
console.log(sketch.frameRate());
}

type PointAndColor = {
point: P5Lib.Vector,
color: Color
};

function calculateColor(point: P5Lib.Vector,
p1: PointAndColor,
p2: PointAndColor,
p3: PointAndColor): Color {
const dist1: number = sketch.dist(point.x, point.y, p1.point.x, p1.point.y);
const dist2: number = sketch.dist(point.x, point.y, p2.point.x, p2.point.y);
const dist3: number = sketch.dist(point.x, point.y, p3.point.x, p3.point.y);
const maxDist: number = sketch.max(sketch.max(dist1, dist2), dist3);

const r: number = (p1.color.red * ((maxDist - dist1) / maxDist))
+ (p2.color.red * ((maxDist - dist2) / maxDist))
+ (p3.color.red * ((maxDist - dist3) / maxDist));
const g: number = (p1.color.green * ((maxDist - dist1) / maxDist))
+ (p2.color.green * ((maxDist - dist2) / maxDist))
+ (p3.color.green * ((maxDist - dist3) / maxDist));
const b: number = (p1.color.blue * ((maxDist - dist1) / maxDist))
+ (p2.color.blue * ((maxDist - dist2) / maxDist))
+ (p3.color.blue * ((maxDist - dist3) / maxDist));

return new Color(sketch.color(r, g, b));
}

function moveVector(v: P5Lib.Vector, vRate: P5Lib.Vector) {
let x: number = v.x;
let y: number = v.y;
x += vRate.x
y += vRate.y;

if (x > sketch.width) {
x = 0;
} else if (x < 0) {
x = sketch.width;
}

if (y > sketch.height) {
y = 0;
} else if (y < 0) {
y = sketch.height;
}

v.set(x, y);
}
78 changes: 78 additions & 0 deletions projects/genuary-2024/2-no-palettes/sketch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (C) 2024 Brittni Watkins.
*
* This file is a part of brittni and the polar bear's Generative Art Project Template,
* which is released under the GNU Affero General Public License, Version 3.0.
* You may not use this file except in compliance with the license.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. See LICENSE or go to
* https://www.gnu.org/licenses/agpl-3.0.en.html for full license details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*/

import {sketch} from 'sketch';
import {P5Lib, randomFloat, randomInt, SketchContext} from 'common';

type ColorLine = {
p1: P5Lib.Vector,
p2: P5Lib.Vector,
h1: number,
h2: number,
numSections: number
};

const lines: ColorLine[] = [];

sketch.setup = (): void => {
sketch.createCanvas(sketch.windowWidth, sketch.windowHeight);
SketchContext.initialize(sketch);

const count: number = randomInt(20, 500);
const spacing: number = sketch.width / count;
const start: number = spacing / 2.0;

for (let i: number = 0; i < count; i++) {
const x1: number = randomFloat(0, sketch.width);
const y1: number = (i * spacing) + start + randomFloat(-spacing, spacing);
const x2: number = randomFloat(0, sketch.width);
const y2: number = (i * spacing) + start + randomFloat(-spacing, spacing);
const h1: number = randomInt(0, 360);
const h2: number = randomInt(0, 360);
const s: number = randomInt(5, 20);
lines.push({
p1: (new P5Lib.Vector(x1, y1)),
p2: (new P5Lib.Vector(x2, y2)),
h1: h1,
h2: h2,
numSections: s
});
}
}

sketch.draw = (): void => {
sketch.background(0);

for (let line of lines) {
displayLine(line);
}
}

function displayLine(line: ColorLine): void {
let start: P5Lib.Vector = line.p1.copy();
let end: P5Lib.Vector;

for (let i: number = 1; i <= line.numSections; i++) {
let colorPercentage: number = (i - 1) * (1.0 / line.numSections);
let percentage: number = i * (1.0 / line.numSections);
end = P5Lib.Vector.lerp(line.p1, line.p2, percentage);
let currentHue: number = Math.floor(sketch.lerp(line.h1, line.h2, colorPercentage));
sketch.stroke(sketch.color(`hsl(${currentHue}, 100%, 50%)`));
sketch.line(start.x, start.y, end.x, end.y);
start.set(end);
}
}
17 changes: 12 additions & 5 deletions scripts/color-grid.sh → scripts/rollup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2023 Brittni Watkins.
# Copyright (C) 2023-2024 Brittni Watkins.
#
# This file is a part of brittni and the polar bear's Generative Art Project Template,
# which is released under the GNU Affero General Public License, Version 3.0.
Expand All @@ -15,15 +15,22 @@
# See the GNU Affero General Public License for more details.
#

while getopts d: flag
while getopts d:p: flag
do
case "${flag}" in
d) dev=${OPTARG};;
p) sketchPath=${OPTARG};;
*) dev="false";;
esac
done

echo 'Starting the /examples/color/color-grid.ts example.';
if [ -z "$sketchPath" ]
then
echo 'Missing sketch path. Using default path ./src/sketch.ts';
sketchPath='./src/sketch.ts';
fi

echo "Starting the $sketchPath example.";

echo '(1/2): Removing old output';

Expand All @@ -32,8 +39,8 @@ sh ./scripts/delete-out.sh
if [ "$dev" == "true" ]
then
echo '(2/2): Building project and starting development server';
rollup --config --input ./examples/color/color-grid.ts --watch;
rollup --config --input $sketchPath --watch;
else
echo '(2/2): Building project';
rollup --config --input ./examples/color/color-grid.ts;
rollup --config --input $sketchPath;
fi
Loading

0 comments on commit a6d5e72

Please sign in to comment.