Modeling2.html
From 2013.igem.org
(Difference between revisions)
Line 102: | Line 102: | ||
var dieHeadingY = 20; | var dieHeadingY = 20; | ||
+ | |||
+ | |||
+ | var arrow = function(X, Y, graphX, graphY){ | ||
+ | /* These never change*/ | ||
+ | this.graphX = graphX; | ||
+ | this.graphY = graphY; | ||
+ | /*X, Y are locations where the function will be evaluated */ | ||
+ | this.functionX = function(x, y) { | ||
+ | return y - x; | ||
+ | }; | ||
+ | this.functionY = function(x, y) { | ||
+ | return thetaPlay*y*(x - 1); /*y; */ | ||
+ | }; | ||
+ | |||
+ | |||
+ | this.calculate = function(){ | ||
+ | this.lengthX = this.functionX(X, Y); | ||
+ | this.lengthY = this.functionY(X, Y); | ||
+ | this.length = sqrt( pow(this.lengthX, 2) + pow(this.lengthY, 2)); | ||
+ | if (this.lengthX >= 0) { | ||
+ | this.theta = atan(this.lengthY / this.lengthX); | ||
+ | } | ||
+ | else{ | ||
+ | this.theta = atan(this.lengthY / this.lengthX) + 3.1415; | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | this.drawOn = function(maxLength) { | ||
+ | strokeWeight(1); stroke(0, 0, 0); | ||
+ | var alpha = 36*(3.1415/180); | ||
+ | var scaledLength=(this.length / maxLength)*boxHeight; // Box height scales arrow length | ||
+ | var endX = this.graphX + scaledLength*cos(this.theta)/2; | ||
+ | var endY = this.graphY - scaledLength*sin(this.theta)/2; | ||
+ | line(this.graphX - scaledLength*cos(this.theta)/2, this.graphY + scaledLength*sin(this.theta)/2, endX, endY); | ||
+ | triangle(endX, endY, endX + cos(3.1415 + this.theta - alpha/2)*triLength, endY - sin(3.1415 + this.theta - alpha/2)*triLength, endX + cos(3.1415 + this.theta + alpha/2)*triLength, endY - sin(3.1415 + this.theta + alpha/2)*triLength); | ||
+ | }; | ||
+ | |||
+ | }; | ||
var drawHeader = function(x, y, heading){ | var drawHeader = function(x, y, heading){ |
Revision as of 22:42, 27 September 2013