mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
aligning to the tests of Daniel Rosenwasser
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
/// <reference path="snapsvg.d.ts" />
|
||||
|
||||
function tester1() {
|
||||
var paper = Snap("#content");
|
||||
|
||||
var i = 0;
|
||||
var n = 1000000;
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
|
||||
paper.click((ev) => { var x = ev.clientX; }, this)
|
||||
|
||||
redrawLoop();
|
||||
|
||||
function redrawLoop(): void {
|
||||
if (i < n) {
|
||||
setTimeout(redrawLoop, 50 + Math.random() * 50);
|
||||
drawDrop();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
function drawDrop(): void {
|
||||
//var c = paper.circle(window.innerWidth * Math.random(), window.innerHeight * Math.random(), 50);
|
||||
var radius = 25;
|
||||
var c = paper.circle(x + radius * Math.random() - radius*2, y + radius * Math.random() - radius, radius*2);
|
||||
c.animate({ r: 0 }, 1000, Mina.bounce, () => c.remove());
|
||||
}
|
||||
}
|
||||
|
||||
function tester2() {
|
||||
var m1 = Snap.Matrix(1,2,3,4,5,6);
|
||||
|
||||
m1.add(m1).add(m1);
|
||||
|
||||
var m2 = Snap.Matrix(0,0,0,0,0,0);
|
||||
m2.add(1,-1,1,-1,1,-1).add(-1,1,-1,1,-1,1);
|
||||
|
||||
var m3 = Snap.Matrix(1,1,1,1,1,1);
|
||||
m3.add(Snap.Matrix(0,0,0,0,0,0)).add(m2);
|
||||
|
||||
console.log(m1.toString());
|
||||
console.log(m2.toString());
|
||||
console.log(m3.toString());
|
||||
}
|
||||
|
||||
function tester3() {
|
||||
// true
|
||||
console.log(Snap.deg(Snap.rad(Snap.deg(Math.PI))) === Snap.deg(Snap.rad(180)));
|
||||
|
||||
var colorString = "#BADA55";
|
||||
var rgb = Snap.getRGB(colorString);
|
||||
var col = Snap.color(colorString);
|
||||
var hsl = Snap.rgb2hsl(rgb.r, rgb.g, rgb.b);
|
||||
var hsb = Snap.rgb2hsb(rgb.r, rgb.g, rgb.b);
|
||||
|
||||
// all true
|
||||
console.log(rgb.r === col.r && rgb.g === col.g && rgb.b === col.b && rgb.hex === col.hex);
|
||||
console.log(hsl.h === hsb.h);
|
||||
console.log(hsl.h === col.h && hsl.s === col.s && hsb.b === col.v);
|
||||
console.log(!col.error);
|
||||
}
|
||||
|
||||
function tester4() {
|
||||
console.log("tester4");
|
||||
var paper = Snap(800,600);
|
||||
var bbox = paper.getBBox();
|
||||
|
||||
console.log("cx: " + bbox.cx);
|
||||
console.log("cy: " + bbox.cy);
|
||||
console.log("h: " + bbox.h);
|
||||
console.log("height: " + bbox.height);
|
||||
console.log("path: " + bbox.path);
|
||||
console.log("r0: " + bbox.r0);
|
||||
console.log("r1: " + bbox.r1);
|
||||
console.log("r2: " + bbox.r2);
|
||||
console.log("vb: " + bbox.vb);
|
||||
console.log("w: " + bbox.w);
|
||||
console.log("width: " + bbox.width);
|
||||
console.log("x2: " + bbox.x2);
|
||||
console.log("x: " + bbox.x);
|
||||
console.log("y2: " + bbox.y2);
|
||||
console.log("y: " + bbox.y);
|
||||
}
|
||||
|
||||
function tester5() {
|
||||
var sideLength = 100;
|
||||
var papel = Snap(1000, 1000);
|
||||
var square = papel.rect(100, 100, sideLength, sideLength, 10, 10);
|
||||
|
||||
function updater(newSideLength: number) {
|
||||
square.attr({ x: newSideLength, y: newSideLength });
|
||||
}
|
||||
|
||||
function easer(iArdlyKnowEr: number) {
|
||||
return iArdlyKnowEr * iArdlyKnowEr;
|
||||
}
|
||||
|
||||
Snap.animate(sideLength, sideLength + 100, updater, 1500 /*ms*/);
|
||||
setTimeout(500, () => { Snap.animate(sideLength + 100,
|
||||
0,
|
||||
updater,
|
||||
100 /*ms*/,
|
||||
easer,
|
||||
square.remove); });
|
||||
}
|
||||
|
||||
function tester6() {
|
||||
var path: snapsvg.PathStatic = Snap.path;
|
||||
// bboxing
|
||||
var b1 = path.bezierBBox(0, 0, 0, 0, 100, 100, 100, 100);
|
||||
var b2 = path.bezierBBox(50, 50, 50, 50, 150, 150, 150, 150);
|
||||
var b3 = path.bezierBBox(100, 100, 100, 100, 200, 200, 200, 200);
|
||||
|
||||
// all true
|
||||
console.log(path.isBBoxIntersect(b1, b2));
|
||||
console.log(path.isBBoxIntersect(b1, b3));
|
||||
console.log(path.isPointInsideBBox(b1, 50, 50));
|
||||
console.log(path.isPointInsideBBox(b2, 50, 50));
|
||||
console.log(!path.isPointInsideBBox(b3, 50, 50));
|
||||
}
|
||||
|
||||
//$(function () {
|
||||
// tester1();
|
||||
//});
|
||||
|
||||
//tester2();
|
||||
//tester3();
|
||||
//tester4();
|
||||
//tester5();
|
||||
//tester6();
|
||||
Vendored
+19
-7
@@ -80,7 +80,8 @@ declare module Snap {
|
||||
export function animate(from:Array<number>,to:Array<number>,setter:Function,duration:number,easing?:(num:number)=>number,callback?:()=>void):Mina.MinaAnimation;
|
||||
export function animation(attr:Object,duration:number,easing?:(num:number)=>number,callback?:()=>void):Snap.Animation;
|
||||
|
||||
export function color(clr:string):Object;export function getRGB(color:string):Object;
|
||||
export function color(clr:string):Object;
|
||||
export function getRGB(color:string):RGB;
|
||||
export function hsb(h:number,s:number,b:number):HSB;
|
||||
export function hsl(h:number,s:number,l:number):HSL;
|
||||
export function rgb(r:number,g:number,b:number):RGB;
|
||||
@@ -246,22 +247,33 @@ declare module Snap {
|
||||
selectAll(query ?:string):Snap.Set;
|
||||
}
|
||||
|
||||
|
||||
export interface Matrix {
|
||||
add(a:number,b:number,c:number,d:number,e:number,f:number):void;
|
||||
add(matrix:Matrix):void;
|
||||
add(a:number,b:number,c:number,d:number,e:number,f:number):Matrix;
|
||||
add(matrix:Matrix):Matrix;
|
||||
clone():Matrix;
|
||||
determinant():number;
|
||||
invert():Matrix;
|
||||
rotate(a:number,x:number,y:number):void;
|
||||
scale(x:number,y?:number,cx?:number,cy?:number):void;
|
||||
split():Object;
|
||||
rotate(a:number,x:number,y:number):Matrix;
|
||||
scale(x:number,y?:number,cx?:number,cy?:number):Matrix;
|
||||
split():ExplicitTransform;
|
||||
toTransformString():string;
|
||||
translate(x:number,y:number):void;
|
||||
translate(x:number,y:number):Matrix;
|
||||
x(x:number,y:number):number;
|
||||
y(x:number,y:number):number;
|
||||
|
||||
}
|
||||
|
||||
interface ExplicitTransform {
|
||||
dx: number;
|
||||
dy: number;
|
||||
scalex: number;
|
||||
scaley: number;
|
||||
shear: number;
|
||||
rotate: number;
|
||||
isSimple: boolean;
|
||||
}
|
||||
|
||||
interface Paper extends Snap.Element {
|
||||
|
||||
clear():void;
|
||||
|
||||
Reference in New Issue
Block a user