-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
1 parent
28b93df
commit 066f7f7
Showing
15 changed files
with
265 additions
and
110 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
apps/web/prisma/migrations/20240531114647_add_gradient_type/migration.sql
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,2 @@ | ||
-- AlterEnum | ||
ALTER TYPE "NodeType" ADD VALUE 'GRADIENT'; |
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,58 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { hsv2rgb } from '../components/ColorPicker/ColorPicker.utils'; | ||
import { NodeWindow } from '../circuit/components/Node/Node'; | ||
import { FromHSV } from '../../../../packages/nodes/src/color/FromHSV/FromHSV'; | ||
import { ColorSchema, GradientSchema } from '@bitspace/schemas'; | ||
import { Gradient } from '@bitspace/nodes'; | ||
|
||
const defaultGradient: Zod.infer<ReturnType<typeof GradientSchema>> = { | ||
type: 'linear', | ||
colors: [ | ||
{ color: { hue: 0, saturation: 0, value: 0 }, position: 0 }, | ||
{ color: { hue: 0, saturation: 0, value: 0 }, position: 1 } | ||
], | ||
angle: 0 | ||
}; | ||
|
||
export const GradientWindow = ({ node }: { node: Gradient }) => { | ||
const [color, setColor] = | ||
useState<Zod.infer<ReturnType<typeof GradientSchema>>>(defaultGradient); | ||
|
||
useEffect(() => { | ||
const subscription = node.outputs.output.subscribe(value => { | ||
setColor(value as Zod.infer<ReturnType<typeof GradientSchema>>); | ||
}); | ||
|
||
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
}, [node]); | ||
|
||
const gradient = [ | ||
'linear-gradient(', | ||
`${color.angle}deg, `, | ||
`${color.colors | ||
.map(({ color }) => { | ||
const [r, g, b] = hsv2rgb( | ||
color.hue, | ||
color.saturation, | ||
color.value | ||
); | ||
return `rgb(${r}, ${g}, ${b})`; | ||
}) | ||
.join(', ')}`, | ||
')' | ||
].join(''); | ||
|
||
return ( | ||
<NodeWindow className="bg-transparent"> | ||
<div | ||
className="w-full h-[226px] rounded-full" | ||
style={{ | ||
background: gradient | ||
}} | ||
/> | ||
</NodeWindow> | ||
); | ||
}; |
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,56 @@ | ||
import { NodeType } from '../../types'; | ||
import { Input, Node, Output } from '@bitspace/circuit'; | ||
import { ColorSchema, GradientSchema, minMaxNumber } from '@bitspace/schemas'; | ||
import { combineLatest, map } from 'rxjs'; | ||
|
||
export class Gradient extends Node { | ||
static displayName = 'Gradient'; | ||
static type = NodeType.GRADIENT; | ||
|
||
inputs = { | ||
a: new Input({ | ||
name: 'A', | ||
type: ColorSchema(), | ||
defaultValue: { | ||
red: 0, | ||
green: 0, | ||
blue: 0 | ||
} | ||
}), | ||
b: new Input({ | ||
name: 'B', | ||
type: ColorSchema(), | ||
defaultValue: { | ||
red: 0, | ||
green: 0, | ||
blue: 0 | ||
} | ||
}), | ||
angle: new Input({ | ||
name: 'Angle', | ||
type: minMaxNumber(0, 360, true), | ||
defaultValue: 0 | ||
}) | ||
}; | ||
|
||
outputs = { | ||
output: new Output({ | ||
name: 'Output', | ||
type: GradientSchema(), | ||
observable: combineLatest([ | ||
this.inputs.a, | ||
this.inputs.b, | ||
this.inputs.angle | ||
]).pipe( | ||
map(([a, b, angle]) => ({ | ||
type: 'linear', | ||
colors: [ | ||
{ color: a, position: 0 }, | ||
{ color: b, position: 1 } | ||
], | ||
angle | ||
})) | ||
) | ||
}) | ||
}; | ||
} |
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
Oops, something went wrong.