Skip to content

Commit 6ee82c3

Browse files
committed
did some minor changes
1 parent 61c828b commit 6ee82c3

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h3># Drawing Board</h3>
4848
<label for="draw-tool">Tool: </label>
4949
<select name="draw-tool" id="draw-tool" value="brush">
5050
<option value="brush">Brush</option>
51-
<option value="gradientBrush">Gradient Brush</option>
51+
<option value="gradient_brush">Gradient Brush</option>
5252
<option value="eraser">Eraser</option>
5353
<option value="line">Line</option>
5454
</select>

src/renderers/RealDrawBoard/tools/gradientBrush.ts renamed to src/renderers/RealDrawBoard/tools/gradient_brush.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { RealDrawBoard } from '../RealDrawBoard';
22
import { Texture } from 'gpu.js';
3-
import { convertHSLToRGB } from '../../../util/convertForm';
4-
import { type } from 'os';
3+
import { convertHSLToRGB } from '../../../util/convertHSLToRGB';
54

6-
var hue: number = 0;
7-
var gradientColors: [number ,number ,number] = [ 1 ,1 ,1 ];
5+
let hue: number = 0;
6+
let gradientColors: [number ,number ,number] = [ 1 ,1 ,1 ];
87

9-
export const name = 'gradientBrush';
8+
export const name = 'gradient_brush';
109

1110
export function _startStroke(
1211
this: RealDrawBoard,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as brush from './brush';
22
import * as eraser from './eraser';
33
import * as line from './line';
4-
import * as gradientBrush from './gradientBrush';
4+
import * as gradient_brush from './gradient_brush';
55

66
export const tools = {
77
brush,
8-
gradientBrush,
8+
gradient_brush,
99
eraser,
1010
line
1111
}
1212

13-
export type Tool = 'brush' | 'gradientBrush' | 'eraser' | 'line';
13+
export type Tool = 'brush' | 'gradient_brush' | 'eraser' | 'line';

src/util/convertForm.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,43 +21,3 @@ export function convertCartesianPolar(x: number, y: number) {
2121
Math.atan2(y, x)
2222
]
2323
}
24-
25-
/**
26-
* Convert hsl Color into RGB color.
27-
* @param h color value ranges from 0 to 360.
28-
* @param s saturation value.
29-
* @param l brightness level.
30-
* @returns array containing r g and b value
31-
*/
32-
export function convertHSLToRGB(h: number, s: number, l: number) :[ number ,number ,number ] {
33-
34-
s /= 100;
35-
l /= 100;
36-
37-
var c: number = (1 - Math.abs(2 * l - 1)) * s;
38-
var x: number = c * (1 - Math.abs((h / 60) % 2 - 1));
39-
var m: number = l - c/2;
40-
var r: number = 0;
41-
var g: number = 0;
42-
var b: number = 0;
43-
44-
if (0 <= h && h < 60) {
45-
r = c; g = x; b = 0;
46-
} else if (60 <= h && h < 120) {
47-
r = x; g = c; b = 0;
48-
} else if (120 <= h && h < 180) {
49-
r = 0; g = c; b = x;
50-
} else if (180 <= h && h < 240) {
51-
r = 0; g = x; b = c;
52-
} else if (240 <= h && h < 300) {
53-
r = x; g = 0; b = c;
54-
} else if (300 <= h && h < 360) {
55-
r = c; g = 0; b = x;
56-
}
57-
58-
r = Math.round((r + m));
59-
g = Math.round((g + m));
60-
b = Math.round((b + m));
61-
62-
return [ r ,g ,b ];
63-
}

src/util/convertHSLToRGB.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Convert hsl Color into RGB color.
3+
* @param h color value ranges from 0 to 360.
4+
* @param s saturation value.
5+
* @param l brightness level.
6+
* @returns array containing r g and b value
7+
*/
8+
export function convertHSLToRGB(h: number, s: number, l: number) :[ number ,number ,number ] {
9+
10+
s /= 100;
11+
l /= 100;
12+
13+
let c: number = (1 - Math.abs(2 * l - 1)) * s;
14+
let x: number = c * (1 - Math.abs((h / 60) % 2 - 1));
15+
let m: number = l - c/2;
16+
let r: number = 0;
17+
let g: number = 0;
18+
let b: number = 0;
19+
20+
if (0 <= h && h < 60) {
21+
r = c; g = x; b = 0;
22+
} else if (60 <= h && h < 120) {
23+
r = x; g = c; b = 0;
24+
} else if (120 <= h && h < 180) {
25+
r = 0; g = c; b = x;
26+
} else if (180 <= h && h < 240) {
27+
r = 0; g = x; b = c;
28+
} else if (240 <= h && h < 300) {
29+
r = x; g = 0; b = c;
30+
} else if (300 <= h && h < 360) {
31+
r = c; g = 0; b = x;
32+
}
33+
34+
r = Math.round((r + m));
35+
g = Math.round((g + m));
36+
b = Math.round((b + m));
37+
38+
return [ r ,g ,b ];
39+
}

0 commit comments

Comments
 (0)