Skip to content

Commit

Permalink
newage core
Browse files Browse the repository at this point in the history
  • Loading branch information
theshock committed Feb 5, 2012
1 parent 3e0c7eb commit 1857636
Show file tree
Hide file tree
Showing 12 changed files with 235 additions and 566 deletions.
File renamed without changes.
46 changes: 23 additions & 23 deletions Source/Core/Curves.js → Archive/Utils/Curves.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
---
name: "EC"
name: "Utils.ExtendedCurves"
description: "Curves with dynamic width and color"
Expand All @@ -16,7 +16,7 @@ requires:
- Inner.TimingFunctions
- Context2D
provides: EC
provides: Utils.ExtendedCurves
...
*/
Expand All @@ -27,39 +27,41 @@ new function () {
The following text contains bad code and due to it's code it should not be readed by ANYONE!
*/

var Color = LibCanvas.Utils.Color,
TimingFunctions = LibCanvas.Inner.TimingFunctions,
var Transition = atom.Transition,
Color = atom.Color,
Point = LibCanvas.Point;

var EC = {};

/** @returns {atom.Color} */
EC.getColor = function (color) {
return new Color(color || [0,0,0,1]);
};

EC.getPoints = function (prevPos, pos, width, inverted) {
var w = pos.x-prevPos.x,
h = pos.y-prevPos.y,
dist = Math.hypotenuse(w, h);
var sin = h / dist,
cos = w / dist;
var dx = sin * width,
dist = Math.hypotenuse(w, h),

sin = h / dist,
cos = w / dist,

dx = sin * width,
dy = cos * width;

return [new Point(pos.x + dx, pos.y + dy*inverted),
new Point(pos.x - dx, pos.y - dy*inverted)];
return [
new Point(pos.x + dx, pos.y + dy*inverted),
new Point(pos.x - dx, pos.y - dy*inverted)
];
};

EC.getGradientFunction = function (attr) {
switch (typeof attr.gradient) {
case 'undefined' :
return Function.lambda( EC.getColor(attr.color) );
break;
return atom.fn.lambda( EC.getColor(attr.color) );

case 'function' :
return attr.gradient;
break;

default :
var gradient = { fn: attr.gradient.fn || 'linear' };
Expand All @@ -74,20 +76,19 @@ EC.getGradientFunction = function (attr) {
var diff = gradient.from.diff( gradient.to );

return function (t) {
var factor = TimingFunctions.count(gradient.fn, t);
var factor = Transition.get(gradient.fn)(t);
return gradient.from.shift( diff.clone().mul(factor) ).toString();
};
break;
}
};

EC.getWidthFunction = function (attr) {
attr.width = attr.width || 1;
switch (typeof attr.width) {
case 'number' : return Function.lambda(attr.width);
case 'number' : return atom.fn.lambda(attr.width);
case 'function': return attr.width;
case 'object' : return EC.getWidthFunction.range( attr.width );
default: throw new Error('LibCanvas.Context2D.drawCurve -- unexpected type of width');
default: throw new TypeError('LibCanvas.Context2D.drawCurve -- unexpected type of width');
}
};

Expand All @@ -97,7 +98,7 @@ EC.getWidthFunction.range = function (width) {
}
var diff = width.to - width.from;
return function(t){
return width.from + diff * TimingFunctions.count(width.fn || 'linear', t);
return width.from + diff * Transition.get(width.fn || 'linear')(t);
}
};

Expand Down Expand Up @@ -141,9 +142,7 @@ LibCanvas.Context2D.prototype.drawCurve = function (obj) {
drawPoints , prevDrawPoints ,
width , color, prevColor, style;

var add = function (a, b) {
return a + b;
};
var add = function (a, b) { return a + b };

prevContorolPoint = curveFunction(points, -step);

Expand All @@ -155,6 +154,7 @@ LibCanvas.Context2D.prototype.drawCurve = function (obj) {
drawPoints = EC.getPoints(prevContorolPoint, controlPoint, width, invertedMultipler);

if (t >= step) {
// #todo: reduce is part of array, not color
if ( EC.getColor(prevColor).diff(color).reduce(add) > 150 ) {
style = this.createLinearGradient(prevContorolPoint, controlPoint);
style.addColorStop(0, prevColor);
Expand Down
44 changes: 21 additions & 23 deletions Source/Core/Context2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var office = {
all : function (type, style) {
this.save();
if (style) this.set(type + 'Style', style);
this[type + 'Rect'](this.getFullRectangle());
this[type + 'Rect'](this.rectangle);
this.restore();
return this;
},
Expand Down Expand Up @@ -61,25 +61,6 @@ var office = {
}
};

var accessors = {};
[ 'fillStyle','font','globalAlpha','globalCompositeOperation','lineCap',
'lineJoin','lineWidth','miterLimit','shadowOffsetX','shadowOffsetY',
'shadowBlur','shadowColor','strokeStyle','textAlign','textBaseline'
].forEach(function (property) {
atom.accessors.define(accessors, property, {
set: function (value) {
try {
this.ctx2d[property] = value;
} catch (e) {
throw TypeError('Exception while setting «' + property + '» to «' + value + '»: ' + e.message);
}
},
get: function () {
return this.ctx2d[property];
}
})
});

var constants =
/** @lends LibCanvas.Context2D */
{
Expand Down Expand Up @@ -153,8 +134,6 @@ var Context2D = declare( 'LibCanvas.Context2D',
{
own: constants,

mixin: declare(accessors),

proto: {
initialize : function (canvas) {
if (canvas instanceof CanvasRenderingContext2D) {
Expand Down Expand Up @@ -217,7 +196,7 @@ var Context2D = declare( 'LibCanvas.Context2D',
var args = [canvas, 0, 0];
if (resize) args.push(width, height);

var clone = Buffer(width, height, true);
var clone = LibCanvas.buffer(width, height, true);
clone.ctx.original('drawImage', args);
return clone;
},
Expand Down Expand Up @@ -874,6 +853,25 @@ var Context2D = declare( 'LibCanvas.Context2D',
}
});


[ 'fillStyle','font','globalAlpha','globalCompositeOperation','lineCap',
'lineJoin','lineWidth','miterLimit','shadowOffsetX','shadowOffsetY',
'shadowBlur','shadowColor','strokeStyle','textAlign','textBaseline'
].forEach(function (property) {
atom.accessors.define(Context2D.prototype, property, {
set: function (value) {
try {
this.ctx2d[property] = value;
} catch (e) {
throw TypeError('Exception while setting «' + property + '» to «' + value + '»: ' + e.message);
}
},
get: function () {
return this.ctx2d[property];
}
})
});

var addColorStop = function () {
var orig = document
.createElement('canvas')
Expand Down
25 changes: 4 additions & 21 deletions Source/Core/Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,18 @@ var Geometry = declare( 'LibCanvas.Geometry',
* @augments Class.Events.prototype
*/
{
mixin: [ Events.Mixin ],
own: {
invoke: function (obj) {
if (obj == null) throw new TypeError( 'element is not geometry' );

return (typeof obj == 'object' && obj[0] instanceof this) ?
obj[0] : (obj instanceof this ? obj : new this(obj));
},
invoke: declare.castArguments,
from : function (obj) {
return this(obj);
}
},
proto: {
initialize : function () {
this.events = new Events(this);
if (arguments.length) this.set.apply(this, arguments);
},
invertDirection: function (distance, reverse) {
distance = Point( distance );
var multi = reverse ? -1 : 1;
return new Point(
distance.x * multi,
distance.y * multi
);
},
move : function (distance, reverse) {
this.events.fire('move', [this.invertDirection(distance, reverse)]);
return this;
},
toString: Function.lambda('[object LibCanvas.Geometry]')
cast: function (args) {
return this.constructor.castArguments(args);
}
}
});
124 changes: 0 additions & 124 deletions Source/Core/Invoker.js

This file was deleted.

Loading

0 comments on commit 1857636

Please sign in to comment.