-
Notifications
You must be signed in to change notification settings - Fork 9
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
19 changed files
with
286 additions
and
256 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
.cache | ||
dist | ||
dist | ||
public |
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
File renamed without changes.
File renamed without changes.
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,13 +1,16 @@ | ||
{ | ||
"name": "react-artboard", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"author": "Matt Kane <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"clean": "rm dist/bundle.js", | ||
"start": "parcel src/index.html --host 0.0.0.0", | ||
"build-prod": "parcel build src/index.html" | ||
"clean": "rm dist/*", | ||
"start": "parcel example/index.html --host 0.0.0.0 --out-dir public", | ||
"build-example": "parcel build example/index.html --out-dir public", | ||
"build-library": "parcel build src/index.ts", | ||
"typegen": "tsc --emitDeclarationOnly --declaration" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
|
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 was deleted.
Oops, something went wrong.
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,3 @@ | ||
export * from "./tools/brush/useBrush"; | ||
export * from "./components/Artboard"; | ||
export * from "./utils/pointUtils"; |
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,3 @@ | ||
export * from "./tools/brush/useBrush"; | ||
export * from "./components/Artboard"; | ||
export * from "./utils/pointUtils"; |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
import { Point } from "../../utils/pointUtils"; | ||
export declare function varyColour(sourceColour: string, varyBrightness: number): any; | ||
export interface Bristle { | ||
distance: number; | ||
thickness: number; | ||
colour: string; | ||
} | ||
export declare const rotatePoint: (distance: number, angle: number, origin: Point) => Point; | ||
export declare const getBearing: (origin: Point, destination: Point) => number; | ||
export declare const getNewAngle: (origin: Point, destination: Point, oldAngle?: number) => number; | ||
export declare const angleDiff: (angleA: number, angleB: number) => number; |
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,50 @@ | ||
import tinycolor from "tinycolor2"; | ||
import { Point } from "../../utils/pointUtils"; | ||
|
||
export function varyColour(sourceColour: string, varyBrightness: number) { | ||
const amount = Math.round(Math.random() * varyBrightness); | ||
const alpha = 1 - Math.random() / 4; | ||
const colour = tinycolor(sourceColour); | ||
const varied = colour.darken(amount - varyBrightness / 2).setAlpha(alpha); | ||
return varied.toPercentageRgbString(); | ||
} | ||
|
||
export interface Bristle { | ||
distance: number; | ||
thickness: number; | ||
colour: string; | ||
} | ||
|
||
export const rotatePoint = ( | ||
distance: number, | ||
angle: number, | ||
origin: Point | ||
): Point => [ | ||
origin[0] + distance * Math.cos(angle), | ||
origin[1] + distance * Math.sin(angle), | ||
]; | ||
|
||
export const getBearing = (origin: Point, destination: Point) => | ||
(Math.atan2(destination[1] - origin[1], destination[0] - origin[0]) - | ||
Math.PI / 2) % | ||
(Math.PI * 2); | ||
|
||
export const getNewAngle = ( | ||
origin: Point, | ||
destination: Point, | ||
oldAngle?: number | ||
): number => { | ||
const bearing = getBearing(origin, destination); | ||
if (typeof oldAngle === "undefined") { | ||
return bearing; | ||
} | ||
return oldAngle - angleDiff(oldAngle, bearing); | ||
}; | ||
|
||
export const angleDiff = (angleA: number, angleB: number) => { | ||
const twoPi = Math.PI * 2; | ||
const diff = | ||
((angleA - (angleB > 0 ? angleB : angleB + twoPi) + Math.PI) % twoPi) - | ||
Math.PI; | ||
return diff < -Math.PI ? diff + twoPi : diff; | ||
}; |
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,8 @@ | ||
import { Bristle } from "./brushHelpers"; | ||
import { ToolHandlers } from "../../components/Artboard"; | ||
export declare type Brush = Array<Bristle>; | ||
export interface UseBrushProps { | ||
color?: string; | ||
strokeWidth?: number; | ||
} | ||
export declare function useBrush({ color, strokeWidth, }: UseBrushProps): ToolHandlers; |
Oops, something went wrong.