Skip to content

Commit 6af9074

Browse files
committed
indented properly and avoided round function for conversion
1 parent 8d7e81d commit 6af9074

File tree

4 files changed

+39
-38
lines changed

4 files changed

+39
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ See [example](https://harshkhandeparkar.github.io/gpujs-real-renderer).
229229
- `brushColor` (*array*): The color of the brush in the corm `[red, green, blue]` where each of
230230
`red`, `green` and `blue` are between 0 and 1.
231231
- `eraserSize` (*number*): Size of the eraser.
232-
- `tool` ('brush' | 'gradient_brush' | 'eraser' | 'line'): The current tool used on the board. This tool can be set in the options or using the `changeTool` method.
232+
- `tool` ('brush' | 'rainbow_brush' | 'eraser' | 'line'): The current tool used on the board. This tool can be set in the options or using the `changeTool` method.
233233
234234
##### Options
235235
Since this is a child class of `RealRenderer`, all the options of `RealRender` are applicable here as well.
@@ -245,7 +245,7 @@ Apart from those, the following are additional options that can be passed on to
245245
246246
- `maxUndos`(*Number*) (Default: `15`): Determines the maximum possible undos. (Use a smaller number on devices with less RAM)
247247
248-
- `tool` (*'brush' | 'gradient_brush' | 'eraser' | 'line'*) (Default: `'brush'`): Determines which tool to use.
248+
- `tool` (*'brush' | 'rainbow_brush' | 'eraser' | 'line'*) (Default: `'brush'`): Determines which tool to use.
249249
250250
##### Methods
251251
Since this is a child class of `RealRenderer`, all the methods of `RealRender` are available here as well.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { convertHSLToRGB } from '../../../util/convertHSLToRGB';
55
let hue: number = 0;
66
let gradientColors: [number, number, number] = [1, 1, 1];
77

8-
export const name = 'gradient_brush';
8+
export const name = 'rainbow_brush';
99

1010
export function _startStroke(
1111
this: RealDrawBoard,
@@ -34,6 +34,7 @@ export function _doStroke(
3434
) {
3535
hue = (hue + 1) % 360;
3636
gradientColors = convertHSLToRGB(hue, 90, 40);
37+
console.log('r,g,b => ',gradientColors);
3738
this._plot(coords[0], coords[1], this.brushSize, gradientColors);
3839
this._stroke(coords[0], coords[1], this.brushSize, gradientColors, identifier);
3940
}
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 gradient_brush from './gradient_brush';
4+
import * as rainbow_brush from './rainbow_brush';
55

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

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

src/util/convertHSLToRGB.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
* @param h color value ranges from 0 to 360.
44
* @param s saturation value.
55
* @param l brightness level.
6-
* @returns array containing r g and b value
6+
* @return array containing r g and b value
77
*/
88
export function convertHSLToRGB(h: number, s: number, l: number): [number, number, number] {
99

10-
s /= 100;
11-
l /= 100;
10+
s /= 100;
11+
l /= 100;
1212

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;
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;
1919

20-
if (0 <= h && h < 60) {
21-
r = c; g = x; b = 0;
22-
}
23-
else if (60 <= h && h < 120) {
24-
r = x; g = c; b = 0;
25-
}
26-
else if (120 <= h && h < 180) {
27-
r = 0; g = c; b = x;
28-
}
29-
else if (180 <= h && h < 240) {
30-
r = 0; g = x; b = c;
31-
}
32-
else if (240 <= h && h < 300) {
33-
r = x; g = 0; b = c;
34-
}
35-
else if (300 <= h && h < 360) {
36-
r = c; g = 0; b = x;
37-
}
20+
if (0 <= h && h < 60) {
21+
r = c; g = x; b = 0;
22+
}
23+
else if (60 <= h && h < 120) {
24+
r = x; g = c; b = 0;
25+
}
26+
else if (120 <= h && h < 180) {
27+
r = 0; g = c; b = x;
28+
}
29+
else if (180 <= h && h < 240) {
30+
r = 0; g = x; b = c;
31+
}
32+
else if (240 <= h && h < 300) {
33+
r = x; g = 0; b = c;
34+
}
35+
else if (300 <= h && h < 360) {
36+
r = c; g = 0; b = x;
37+
}
3838

39-
r = Math.round(r + m);
40-
g = Math.round(g + m);
41-
b = Math.round(b + m);
42-
43-
return [r, g, b];
39+
r = (r + m);
40+
g = (g + m);
41+
b = (b + m);
42+
43+
return [r, g, b];
4444
}

0 commit comments

Comments
 (0)