Created
May 6, 2014 14:55
-
-
Save hushin/96a7dcb196165858246f to your computer and use it in GitHub Desktop.
今日のJSFL 20140506
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
var uri = fl.scriptURI.replace(/[¥/][^¥/]*?$/,"/"); | |
// load Lo-Dash | |
fl.runScript(uri + "lodash.compat.js"); | |
var trace = fl.trace; | |
var clear = fl.outputPanel.clear; | |
function Point(x, y){ | |
this.x = x; | |
this.y = y; | |
} | |
function CurvePoint(anchor, ctr_pt2, ctr_pt3){ | |
this.anchor = anchor; | |
this.ctr_pt2 = ctr_pt2; | |
this.ctr_pt3 = ctr_pt3; | |
} | |
function CubicCurvePoint(anchor, ctr_pt2, ctr_pt3, ctr_pt4){ | |
this.anchor = anchor; | |
this.ctr_pt2 = ctr_pt2; | |
this.ctr_pt3 = ctr_pt3; | |
this.ctr_pt4 = ctr_pt3; | |
} | |
function drawStroke(point_arr){ | |
var path = fl.drawingLayer.newPath(); | |
_(point_arr).each(function(point){ | |
if (point instanceof Point){ | |
path.addPoint(point.x, point.y); | |
} else if (point instanceof CurvePoint) { | |
path.addCurve( | |
point.anchor.x, | |
point.anchor.y, | |
point.ctr_pt2.x, | |
point.ctr_pt2.y, | |
point.ctr_pt3.x, | |
point.ctr_pt3.y | |
); | |
} else if(point instanceof CubicCurvePoint) { | |
path.addCubicCurve( | |
point.anchor.x, | |
point.anchor.y, | |
point.ctr_pt2.x, | |
point.ctr_pt2.y, | |
point.ctr_pt3.x, | |
point.ctr_pt3.y, | |
point.ctr_pt4.x, | |
point.ctr_pt4.y | |
); | |
} | |
}); | |
path.makeShape(); | |
} | |
var MAX_WIDTH = 500; | |
var MAX_HEIGHT = 500; | |
// var dom = fl.getDocumentDOM(); | |
// dom.selectAll(); | |
// dom.setFillColor('#99CC3366'); | |
// dom.setStroke('#003300AA', 0.5, 'solid'); | |
function createRandomPoint() { | |
return new Point(_.random(MAX_WIDTH), _.random(MAX_HEIGHT)); | |
}; | |
var point_arr = _.range(3).map(function(){ | |
return createRandomPoint(); | |
}); | |
var c_point_arr = _.range(3).map(function(){ | |
return new CurvePoint( | |
createRandomPoint(), | |
createRandomPoint(), | |
createRandomPoint() | |
); | |
}); | |
var cc_point_arr = _.range(10).map(function(){ | |
return new CubicCurvePoint( | |
createRandomPoint(), | |
createRandomPoint(), | |
createRandomPoint(), | |
createRandomPoint() | |
); | |
}); | |
var all_path = _.shuffle(point_arr.concat(c_point_arr, cc_point_arr)); | |
trace(all_path); | |
drawStroke(all_path); | |
// TODO アニメーション化 | |
// TODO 色や線の太さなど分ける | |
// TODO いい感じに区切る | |
})(this); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment