-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
9 changed files
with
325 additions
and
42 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
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,44 @@ | ||
import { pixelProcessor } from "./helpers" | ||
import Victor from "victor" | ||
|
||
const spiral = (config, data) => { | ||
const getPixel = pixelProcessor(config, data) | ||
let r = 5 | ||
let a = 0 | ||
const cx = config.width / 2 | ||
const cy = config.height / 2 | ||
let points = [] | ||
|
||
points.push(new Victor(cx, config.height - cy)) | ||
|
||
let x = cx, | ||
y = cy | ||
let radius = 1 | ||
let theta = 0 | ||
|
||
while (x > 0 && y > 0 && x < config.width && y < config.height) { | ||
const z = getPixel(x, y) | ||
r = config.Amplitude * z * 0.02 * config.Spacing | ||
a += z / config.Frequency | ||
|
||
let tempradius = radius + Math.sin(a) * r | ||
|
||
points.push( | ||
new Victor( | ||
cx + tempradius * Math.sin(theta), | ||
config.height - (cy + tempradius * Math.cos(theta)), | ||
), | ||
) | ||
|
||
let incr = Math.asin(1 / radius) | ||
radius += incr * config.Spacing | ||
theta += incr | ||
|
||
x = Math.floor(cx + radius * Math.sin(theta)) | ||
y = Math.floor(cy + radius * Math.cos(theta)) | ||
} | ||
|
||
return points | ||
} | ||
|
||
export default spiral |
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,38 @@ | ||
import { pixelProcessor, joinLines } from "./helpers" | ||
import Victor from "victor" | ||
|
||
const springs = (config, data) => { | ||
const getPixel = pixelProcessor(config, data) | ||
const direction = config.Direction == "clockwise" ? 1 : -1 | ||
const pi = Math.PI | ||
const freq = ((config.Frequency * config.LineCount) / 2000) * direction | ||
const amplitude = config.Amplitude / config.LineCount | ||
const incr_x = config.Sampling | ||
const incr_y = Math.floor(config.height / config.LineCount) | ||
const lines = [] | ||
|
||
for (let y = 0; y < config.height; y += incr_y) { | ||
let line = [] | ||
let phase = 0 | ||
|
||
for (let x = 0; x <= config.width; x += incr_x) { | ||
let a = amplitude * getPixel(x, y) | ||
|
||
phase += freq | ||
if (phase > pi) phase -= 2 * pi | ||
|
||
line.push( | ||
new Victor( | ||
x + a * Math.cos(phase), | ||
config.height - (y + a * Math.sin(phase)), | ||
), | ||
) | ||
} | ||
|
||
lines.push(line) | ||
} | ||
|
||
return joinLines(lines) | ||
} | ||
|
||
export default springs |
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 |
---|---|---|
@@ -1,9 +1,61 @@ | ||
import squiggle from "./squiggle" | ||
import sawtooth from "./sawtooth" | ||
import spiral from "./spiral" | ||
import springs from "./springs" | ||
import squiggle from "./squiggle" | ||
import polyspiral from "./polyspiral" | ||
import waves from "./waves" | ||
|
||
export const subtypes = { | ||
squiggle, | ||
sawtooth, | ||
polyspiral, | ||
Squiggle: { | ||
algorithm: squiggle, | ||
settings: [ | ||
"imageFrequency", | ||
"imageLineCount", | ||
"imageAmplitude", | ||
"imageSampling", | ||
"imageModulation", | ||
], | ||
}, | ||
Spiral: { | ||
algorithm: spiral, | ||
settings: ["imageFrequency", "imageAmplitude", "imageSpacing"], | ||
}, | ||
"Polygon Spiral": { | ||
algorithm: polyspiral, | ||
settings: [ | ||
"imageFrequency", | ||
"imagePolygon", | ||
"imageLineCount", | ||
"imageAmplitude", | ||
"imageSpacing", | ||
], | ||
}, | ||
Sawtooth: { | ||
algorithm: sawtooth, | ||
settings: [ | ||
"imageFrequency", | ||
"imageLineCount", | ||
"imageAmplitude", | ||
"imageSpacing", | ||
], | ||
}, | ||
Springs: { | ||
algorithm: springs, | ||
settings: [ | ||
"imageFrequency", | ||
"imageLineCount", | ||
"imageAmplitude", | ||
"imageSampling", | ||
"imageDirection", | ||
], | ||
}, | ||
Waves: { | ||
algorithm: waves, | ||
settings: ["imageAngle", "imageStepSize"], | ||
}, | ||
} | ||
|
||
// some protection against bad data | ||
export const getSubtype = (subtype) => { | ||
return subtypes[subtype] || subtypes['Squiggle'] | ||
} |
Oops, something went wrong.