Skip to content

Commit

Permalink
Add a pre-commit hook configuration to check YAML and whitespace.
Browse files Browse the repository at this point in the history
These are minor, but avoids those coming up during reviews at all.

Signed-off-by: Diego Elio Pettenò <[email protected]>
  • Loading branch information
Flameeyes committed May 30, 2020
1 parent 2077d83 commit f70ac1a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ bundles
*.DS_Store
.eggs
dist
**/*.egg-info
**/*.egg-info
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ repos:
rev: latest
hooks:
- id: reuse
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
2 changes: 1 addition & 1 deletion examples/server/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
<h1>LED color picker demo!</h1>
<canvas id="colorPicker" height="300px" width="300px"></canvas>
</body>
</html>
</html>
17 changes: 8 additions & 9 deletions examples/server/static/led_color_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ctx.height = 300;

function drawColorPicker() {
/**
* Color picker inspired by:
* Color picker inspired by:
* https://medium.com/@bantic/hand-coding-a-color-wheel-with-canvas-78256c9d7d43
*/
let radius = 150;
Expand All @@ -18,30 +18,30 @@ function drawColorPicker() {

for (let x = -radius; x < radius; x++) {
for (let y = -radius; y < radius; y++) {

let [r, phi] = xy2polar(x, y);

if (r > radius) {
// skip all (x,y) coordinates that are outside of the circle
continue;
}

let deg = rad2deg(phi);

// Figure out the starting index of this pixel in the image data array.
let rowLength = 2*radius;
let adjustedX = x + radius; // convert x from [-50, 50] to [0, 100] (the coordinates of the image data array)
let adjustedY = y + radius; // convert y from [-50, 50] to [0, 100] (the coordinates of the image data array)
let pixelWidth = 4; // each pixel requires 4 slots in the data array
let index = (adjustedX + (adjustedY * rowLength)) * pixelWidth;

let hue = deg;
let saturation = r / radius;
let value = 1.0;

let [red, green, blue] = hsv2rgb(hue, saturation, value);
let alpha = 255;

data[index] = red;
data[index+1] = green;
data[index+2] = blue;
Expand Down Expand Up @@ -127,4 +127,3 @@ function getCursorPosition(canvas, event) {

drawColorPicker();
canvas.addEventListener('mousedown', onColorPick);

0 comments on commit f70ac1a

Please sign in to comment.