-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
675 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import SketchWrapper from 'components/SketchWrapper' | ||
import { NextPage } from 'next' | ||
import { ColorValue, Draw, Setup } from 'types/CustomP5' | ||
|
||
const MyNewSketch: NextPage = () => { | ||
const width: number = 2048 | ||
const height: number = 2048 | ||
const dimensions: number[] = [width, height] | ||
const padding: number[] = [40] | ||
const background: ColorValue = [255, 253, 252] | ||
|
||
const setup: Setup = p5 => { | ||
p5.colorMode(p5.HSB) | ||
} | ||
|
||
const draw: Draw = p5 => { | ||
p5.noLoop() | ||
// Set stroke color to white | ||
p5.stroke(0, 255, 255) | ||
p5.strokeWeight(6) | ||
|
||
// create an array with a length of TWO_PI. | ||
const circleArray = Array.from({ length: p5.TWO_PI * 10.1 }) | ||
|
||
// For each point in the array, calculate the cartesian coordinates to draw a point. | ||
circleArray.forEach((_, i) => { | ||
const a = i * 0.1 | ||
const r = p5.width / 3 | ||
const x = r * Math.cos(a) + p5.width / 2 | ||
const y = r * Math.sin(a) + p5.height / 2 | ||
|
||
p5.point(x, y) | ||
}) | ||
} | ||
|
||
return ( | ||
<SketchWrapper | ||
setup={setup} | ||
draw={draw} | ||
dimensions={dimensions} | ||
padding={padding} | ||
background={background} | ||
/> | ||
) | ||
} | ||
|
||
export default MyNewSketch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export type PaperSize = 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | ||
|
||
export interface PaperSizes { | ||
[key: string]: number[] | ||
} | ||
|
||
// Sizes are for 96 DPI | ||
const paperSizes: PaperSizes = { | ||
A0: [3179, 4494], | ||
|
||
A1: [2245, 3179], | ||
|
||
A2: [1587, 2245], | ||
|
||
A3: [1123, 1587], | ||
|
||
A4: [794, 1123], | ||
} | ||
|
||
export const getDimensions = (paperSize: PaperSize) => paperSizes[paperSize] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Graphics } from 'p5' | ||
import type { P5 } from 'types/CustomP5' | ||
|
||
const createGrain = (p5: P5, opacity: number = 10): Graphics => { | ||
const grain = p5.createGraphics(p5.width, p5.height) | ||
grain.loadPixels() | ||
Array.from({ length: p5.width }, (_, i) => { | ||
Array.from({ length: p5.height }, (_, j) => { | ||
grain.set(i, j, p5.color(p5.random(255), opacity)) | ||
}) | ||
}) | ||
grain.updatePixels() | ||
|
||
return grain | ||
} | ||
|
||
export default createGrain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const createGrid = (rows: number, cols: number = rows) => { | ||
const points: number[][] = [] | ||
|
||
Array.from({ length: rows }, (_, u) => | ||
Array.from({ length: cols }, (_, v) => { | ||
const x = u / (rows - 1) | ||
const y = v / (cols - 1) | ||
points.push([x, y]) | ||
}) | ||
) | ||
|
||
return points | ||
} | ||
|
||
export default createGrid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Color, Graphics } from 'p5' | ||
import type { ColorValue, P5 } from 'types/CustomP5' | ||
const createOverlay = ( | ||
p5: P5, | ||
background: ColorValue = [255, 253, 252], | ||
margin: number = p5.width * 0.1 | ||
): Graphics => { | ||
let overlay = p5.createGraphics(p5.width, p5.height) | ||
overlay.background(background as unknown as Color) | ||
overlay.erase() | ||
overlay.rect(margin, margin, p5.width - margin * 2, p5.height - margin * 2) | ||
overlay.noErase() | ||
|
||
return overlay | ||
} | ||
|
||
export default createOverlay |
Oops, something went wrong.