Skip to content

Instantly share code, notes, and snippets.

View paulkaplan's full-sized avatar

Paul Kaplan paulkaplan

View GitHub Profile
@paulkaplan
paulkaplan / colorTempToRGB.js
Last active March 4, 2024 10:29
Color Temperature to RGB
// From http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
// Start with a temperature, in Kelvin, somewhere between 1000 and 40000. (Other values may work,
// but I can't make any promises about the quality of the algorithm's estimates above 40000 K.)
function colorTemperatureToRGB(kelvin){
var temp = kelvin / 100;
@paulkaplan
paulkaplan / fabricBezierCurve.js
Last active February 2, 2024 08:30
Cubic bezier curves with fabric.js renderer
var CubicBezier = function(canvas, opts){
if(!opts) opts = {};
this.start = opts.start || new Vec2(100,100);
this.end = opts.end || new Vec2(400, 400);
this.c1 = opts.c1 || new Vec2(100, 300);
this.c2 = opts.c2 || new Vec2(300, 100);
this.curve = new fabric.Path( this.toSVGPath() );
@paulkaplan
paulkaplan / README.md
Created January 10, 2018 19:43 — forked from eweitnauer/README.md
Dominant Baseline Style

Demonstrates the effect of dominant baseline for each of its possible values on text positioning in an SVG.

Each browser/ mobile browser seems to handle these a bit differently. Here are some issues:

  • Retrieving bounding boxes only works correctly after the font is loaded (and there is no easy way to find out when this happens)
  • The bounding box width does not reflect the actual extent of a text, but how far it advances the cursor. That means that in an italic letter 'f' in many fonts, part of the f will actually lie outside of the bounding box
  • The baseline-shift style does not work in FF
  • dominant-baseline values are interpreted different among browsers

All in all its best just use 'alphabetical' (which is consistent across browsers) and do any further vertical positioning by manually by using the x,y or dx,dy or the transform attributes. Also, if one needs to find out about the actual bounds of a text, one cannot rely on the getBBox() or the getBoundingClientRect() DOM methods, but has to use

@paulkaplan
paulkaplan / IllustratorHandles.js
Created July 21, 2013 21:43
Interactive Bezier curves with Illustrator style handles
var Curve = function(points, canvas){
this.points = points.map( function(p){ return new Point(p); })
this.points[0].setFirst();
this.points[this.points.length-1].setLast();
// create the underlying beziers
this.beziers = [];
for(var n=0; n<this.points.length-1; n++){
@paulkaplan
paulkaplan / ascii_stl_writer.js
Last active November 17, 2021 17:32
ascii_stl_writer.js
// Written by Paul Kaplan
var AsciiStlWriter = (function() {
// ASCI STL files
function stringifyVector(vec){
return ""+vec.x+" "+vec.y+" "+vec.z;
}
function stringifyVertex(vec){
@paulkaplan
paulkaplan / binary_stl_writer.js
Last active November 17, 2021 17:32
Writing binary and ascii STL files in Javascript
// Written by Paul Kaplan
var BinaryStlWriter = (function() {
var that = {};
var writeVector = function(dataview, offset, vector, isLittleEndian) {
offset = writeFloat(dataview, offset, vector.x, isLittleEndian);
offset = writeFloat(dataview, offset, vector.y, isLittleEndian);
return writeFloat(dataview, offset, vector.z, isLittleEndian);
};
@paulkaplan
paulkaplan / gist:5770247
Last active October 12, 2021 01:43
Orbit Controls with momentum and damping for THREE.js
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
*
* customized for momentum (zoom and phi/delta) by paulkaplan
*/
THREE.OrbitControls = function ( object, domElement ) {
@paulkaplan
paulkaplan / STLFileSaver.js
Last active September 14, 2020 13:44
Create an ASCII STL file from a THREE.js mesh that can be saved save from browser and 3D printed
/*
Paul Kaplan, @ifitdidntwork
Create an ASCII STL file from a THREE.js mesh
that can be saved save from browser and 3D printed
--------------------------------------------------
See further explanation here:
http://buildaweso.me/project/2013/2/25/converting-threejs-objects-to-stl-files
--------------------------------------------------
Saving the file out of the browser is done using FileSaver.js
@paulkaplan
paulkaplan / Shapeoko_mm.pp
Last active January 26, 2018 21:55
Vectric configuration file for Shapeoko (mm, with arcs)
+================================================
+
+ Vectric machine output configuration file
+
+================================================
+
+ History
+
+ Who When What
+ ======== ========== ===========================
@paulkaplan
paulkaplan / shapeKeysToJSON.py
Last active November 16, 2017 21:40
Blender Shape Keys to JSON
#http://stackoverflow.com/questions/7553726/blender-how-to-export-shape-keys-using-python
#and three js blender exporter
import bpy
import json
# monkeypatch the json encoder to truncate floats
# http://stackoverflow.com/questions/1447287/format-floats-with-standard-json-module
from json import encoder
encoder.FLOAT_REPR = lambda o: format(o, '.15g')