Skip to content

Instantly share code, notes, and snippets.

View harpreetkhalsagtbit's full-sized avatar

Harpreet Singh harpreetkhalsagtbit

View GitHub Profile
@harpreetkhalsagtbit
harpreetkhalsagtbit / circle-using-algo-in-canvas.js
Last active July 20, 2024 19:14
Circle Using Equations - Canvas API
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
function drawPixel(x1, y1, x2, y2, color) {
ctx.beginPath()
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.strokeStyle = color;
ctx.stroke();
ctx.closePath()
}
@harpreetkhalsagtbit
harpreetkhalsagtbit / canvas-circle.js
Last active July 20, 2024 18:47
canvas-circle.js
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
function drawCircle(x1, y1, x2, y2, color) {
ctx.beginPath()
ctx.arc(100, 100, 50, 0, 2 * Math.PI);
ctx.lineWidth = 2;
ctx.strokeStyle = color;
ctx.stroke();
<svg width="200" height="200">
<circle r="50" cx="100" cy="100" stroke="red" stroke-width="2" />
</svg>
@harpreetkhalsagtbit
harpreetkhalsagtbit / Bresenhams-Line-Algorithm-canvas-api.js
Last active July 20, 2024 18:37
Bresenham's Line Algorithm canvas api
// code taken from
// https://stackoverflow.com/a/50625904
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
function BMFastPixelArtLine(ctx, x1, y1, x2, y2) {
x1 = Math.round(x1);
y1 = Math.round(y1);
x2 = Math.round(x2);
y2 = Math.round(y2);
@harpreetkhalsagtbit
harpreetkhalsagtbit / canvas-line.js
Last active July 20, 2024 18:24
canvas-line.js
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
function drawLine(x1, y1, x2, y2, color) {
ctx.beginPath()
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.lineWidth = 2;
ctx.strokeStyle = color;
ctx.stroke();
<svg width="200" height="200">
<line x1="50" y1="50" x2="150" y2="150" stroke="red" stroke-width="2" />
</svg>
@harpreetkhalsagtbit
harpreetkhalsagtbit / vite-config-with-separate-json-bundle.js
Created August 19, 2023 17:02
vite-config-with-separate-json-bundle.js
import { resolve } from 'node:path'
import libAssetsPlugin from '@laynezh/vite-plugin-lib-assets'
import { terser } from 'rollup-plugin-terser';
import { defineConfig } from 'vite'
// https://vitejs.dev/config/
export default defineConfig(() => ({
plugins: [
@harpreetkhalsagtbit
harpreetkhalsagtbit / package.json
Created May 3, 2023 18:29
design-system-react
{
"name": "design-system-react",
"version": "1.0.5",
"description": "",
"main": "dist/index.js",
"module": "dist/index.modern.js",
"source": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "",
@harpreetkhalsagtbit
harpreetkhalsagtbit / package.json
Last active April 29, 2023 16:31
create-react-lib-using-microbundle
{
"name": "design-system-react",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"module": "dist/index.modern.js",
"source": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "microbundle --jsx React.createElement --jsxFragment React.Fragment --no-compress",
// Run using quokka - vscode
// Arrays
var init = [1,2,3,4,5]
var [a,b,c] = init
// for a, b, c map one to one and skip rest
a
b
c