Skip to content

Instantly share code, notes, and snippets.

View cjmdaixi's full-sized avatar
🎯
Focusing

Jinming Chen cjmdaixi

🎯
Focusing
View GitHub Profile
@cjmdaixi
cjmdaixi / main.cpp
Created April 15, 2022 08:02 — forked from nus/main.cpp
An example of emscripten with WebSocket.
// $ em++ -lwebsocket.js -o index.html main.cpp
#include <emscripten/emscripten.h>
#include <emscripten/websocket.h>
#include <stdio.h>
EM_BOOL onopen(int eventType, const EmscriptenWebSocketOpenEvent *websocketEvent, void *userData) {
puts("onopen");
EMSCRIPTEN_RESULT result;
@cjmdaixi
cjmdaixi / gist:8f84430073136eee0c0b0f90a593b72f
Created July 21, 2016 08:28
Draw bezier curve smoothly between two points. Just like the curves in mind maps.
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
drawCurve(ctx, 100, 80, 0, 100);
function drawCurve(ctx, x1, y1, x2, y2){
ctx.beginPath();
ctx.moveTo(x1, y1);
ctx.bezierCurveTo((x1+x2)/2, y1, (x1+x2)/2, y2, x2, y2);
ctx.stroke();
}