Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Add Shopping List Item</title>
</head>
<body>
<form>
<div>
<label for="item">Enter Item</label>
<input type="text" id="item" autofocus>
@phuctvt
phuctvt / firework.js
Created February 9, 2020 05:04
Fireworks 2.0 (add target to each firework)
class Firework {
constructor() {
this.color = Hsl.random();
this.color.s = 100;
this.color.l = 70;
this.exploder = new Particle(width / 2, height, undefined, this.color);
this.target = new Vector(random(50, width - 50), random(0, 3 * height / 4));
this.exploder.vel = this.exploder.loc.getForceTo(this.target, gravity);
this.explodeParticles = [];
this.nOfParticles = random(30, 40);
@phuctvt
phuctvt / graph.js
Last active February 3, 2020 17:25
Initializing a force to move a particle to another point (at a top which this particle can fly up on before it going down) and has a gravity force impact on it. I believe it won't always 100% touch to the target point, it will has a distance but close to the target in some cases.
const c = document.querySelector('#canvas');
c.width = window.innerWidth;
c.height = window.innerHeight;
const w = c.width;
const h = c.height;
const ctx = c.getContext('2d');
function clear(color) {
ctx.save();
ctx.fillStyle = color || 'white';
@phuctvt
phuctvt / firework.js
Last active February 2, 2020 09:09
firework
class Firework {
constructor() {
let vel = new Vector(
random(0, 15) * (random(0, 1) ? -1 : 1),
random(-18, -10)
);
this.color = Hsl.random();
this.color.s = 100;
this.color.l = 70;
this.exploder = new Particle(w / 2, h, vel, this.color);
<!DOCTYPE html>
<html>
<head>
<title>Snow</title>
</head>
<body style="margin: 0;">
<canvas id="canvas"></canvas>
<script type="text/javascript" src="tool.js"></script>
<script type="text/javascript" src="vector.js"></script>
<script type="text/javascript" src="snow.js"></script>
@phuctvt
phuctvt / ball.js
Created January 31, 2020 09:29
moving ball
class Ball {
constructor(x, y) {
this.pos = new Vector(x, y);
this.r = 10;
this.vel = new Vector(10, 3);
this.forces = [];
}
draw(ctx) {
ctx.save();
@phuctvt
phuctvt / ball.js
Last active January 31, 2020 08:39
Easing functions demo
class Ball {
constructor(x, y, endX, endY, movingDuration) {
this.x = x;
this.y = y;
this.r = 10;
this.movingDuration = movingDuration; // millisecond
this.beginX = x;
this.beginY = y;
this.endX = endX;
this.endY = endY;
@phuctvt
phuctvt / board.js
Last active January 30, 2020 09:34
Minesweeper
function Board(size) {
this.x = 0;
this.y = 0;
this.offset = 5;
this.size = size;
this.cells = [];
this.numOfCells = 10;
this.cellSize = this.size / this.numOfCells;
this.numOfBombCells = 10;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
#include <iostream>
#include <string>
#include <vector>
#include <memory>
using namespace std;
class TwoDidemsionObject
{
public: virtual ~TwoDidemsionObject() {}
};