Skip to content

Instantly share code, notes, and snippets.

View anuraghazra's full-sized avatar
:electron:
Learning

Anurag Hazra anuraghazra

:electron:
Learning
View GitHub Profile
@anuraghazra
anuraghazra / index.html
Created November 5, 2018 11:47
Long shadow
<canvas id="canvas"></canvas>
@anuraghazra
anuraghazra / variableBinding.js
Created November 23, 2018 06:28
Calling a variable inside of a function like a global variable but without polluting the global scope.
// Calling a variable inside of a function
// like a global variable but without polluting the global scope.
// main function
function setup() {
console.log(ADD);
console.log(SUB);
console.log(sum(100,50))
}
// init the variables in another function (you can hide the function in an external js file)
@anuraghazra
anuraghazra / license-badges.md
Created December 11, 2018 12:08 — forked from lukas-h/license-badges.md
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

@anuraghazra
anuraghazra / HappyHoli.js
Created March 21, 2019 15:23
Happy Holi 2019 | Brackets
// Happy Holi 2019
// BY ANURAG HAZRA
{{{{}}}} {{{{}}}} {{{{}}}}{{{{}}}} {{{{}}}}{{{{}}}}{{{{}}}} {{{{}}}}{{{{}}}}{{{{}}}} {{{{}}}} {{{{}}}}
{{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}}
{{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}}
{{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}}{{{{}}}}
{{{{}}}}{{{{}}}}{{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}}
{{{{}}}}{{{{}}}}{{{{}}}} {{{{}}}} {{{{}}}}{{{{}}}} {{{{}}}} {{{{}}}}{{{{}}}}{{{{}}}} {{{{}}}}{{{{}}}}{{{{}}}} {{{{}}}}
{{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}} {{{{}}}}
update() {
let vel = Vector.sub(this.pos, this.oldpos);
vel.mult(this.friction);
// if the point touches the ground set groundFriction
if (this.pos.y >= CANVAS_HEIGHT - this.radius && vel.magSq() > 0.000001) {
var m = vel.mag();
vel.x /= m;
vel.y /= m;
vel.mult(m * this.groundFriction);
@anuraghazra
anuraghazra / Dot.js
Created May 16, 2019 12:23
Rendering the dots.
render() {
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.arc(this.pos.x, this.pos.y, this.radius, 0, Math.PI * 2);
ctx.fill();
ctx.closePath();
}
constrain() {
if (this.pos.x > CANVAS_WIDTH - this.radius) {
this.pos.x = CANVAS_WIDTH - this.radius;
}
if (this.pos.x < this.radius) {
this.pos.x = this.radius;
}
if (this.pos.y > CANVAS_HEIGHT - this.radius) {
this.pos.y = CANVAS_HEIGHT - this.radius;
}
constrain() {
if (this.pos.x > CANVAS_WIDTH - this.radius) {
this.pos.x = CANVAS_WIDTH - this.radius;
}
if (this.pos.x < this.radius) {
this.pos.x = this.radius;
}
if (this.pos.y > CANVAS_HEIGHT - this.radius) {
this.pos.y = CANVAS_HEIGHT - this.radius;
}
class Stick {
constructor(p1, p2, length) {
this.startPoint = p1;
this.endPoint = p2;
this.stiffness = 2;
this.color = '#f5476a';
// if the length is not given then calculate the distance based on position
if (!length) {
this.length = this.startPoint.pos.dist(this.endPoint.pos);
update() {
// calculate the distance between two dots
let dx = this.endPoint.pos.x - this.startPoint.pos.x;
let dy = this.endPoint.pos.y - this.startPoint.pos.y;
// pythagoras theorem
let dist = Math.sqrt(dx * dx + dy * dy);
// calculate the resting distance betwen the dots
let diff = (this.length - dist) / dist * this.stiffness;
// getting the offset of the points