Skip to content

Commit

Permalink
refactor(webgl): update canvas texture gens
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 27, 2019
1 parent 5d868db commit da0fcb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions packages/webgl/src/textures/checkerboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { canvasPixels, swapRB } from "@thi.ng/pixel";
import { ARGB8888, canvasPixels } from "@thi.ng/pixel";

export interface CheckerboardOpts {
size: number;
Expand All @@ -17,20 +17,20 @@ export const checkerboard = (opts: Partial<CheckerboardOpts>) => {
...opts
};
const size = opts.size!;
const col1 = swapRB(opts.col1!);
const col2 = swapRB(opts.col2!);
const { canvas, ctx, img, pix } = canvasPixels(size);
const col1 = ARGB8888.toABGR(opts.col1!);
const col2 = ARGB8888.toABGR(opts.col2!);
const { canvas, ctx, img, pixels } = canvasPixels(size);
for (let y = 0, i = 0; y < size; y++) {
for (let x = 0; x < size; x++, i++) {
pix[i] = (y & 1) ^ (x & 1) ? col1 : col2;
pixels[i] = (y & 1) ^ (x & 1) ? col1 : col2;
}
}
if (opts.corners) {
const corners = opts.cornerCols!.map(swapRB);
pix[0] = corners[0];
pix[size - 1] = corners[1];
pix[pix.length - size] = corners[2];
pix[pix.length - 1] = corners[3];
const corners = opts.cornerCols!.map(ARGB8888.toABGR);
pixels[0] = corners[0];
pixels[size - 1] = corners[1];
pixels[pixels.length - size] = corners[2];
pixels[pixels.length - 1] = corners[3];
}
ctx.putImageData(img, 0, 0);
return canvas;
Expand Down
10 changes: 5 additions & 5 deletions packages/webgl/src/textures/stripes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { canvasPixels, swapRB } from "@thi.ng/pixel";
import { ARGB8888, canvasPixels } from "@thi.ng/pixel";

export interface StripeOpts {
size: number;
Expand All @@ -15,13 +15,13 @@ export const stripes = (opts: Partial<StripeOpts>) => {
...opts
};
const size = opts.size!;
const col1 = swapRB(opts.col1!);
const col2 = swapRB(opts.col2!);
const { canvas, ctx, img, pix } = opts.horizontal
const col1 = ARGB8888.toABGR(opts.col1!);
const col2 = ARGB8888.toABGR(opts.col2!);
const { canvas, ctx, img, pixels } = opts.horizontal
? canvasPixels(1, size)
: canvasPixels(size, 1);
for (let x = size; --x >= 0; ) {
pix[x] = x & 1 ? col1 : col2;
pixels[x] = x & 1 ? col1 : col2;
}
ctx.putImageData(img, 0, 0);
return canvas;
Expand Down

0 comments on commit da0fcb2

Please sign in to comment.