All pastes #425919 Raw Edit

Mine

public text v1 · immutable
·published 2007-04-05 20:05 UTC
rendered paste body
var is_metric = false;
var air_temp_low, air_temp_high, air_velocity_low, air_velocity_high;
var airtemp = 40, radtemp = 20, humidity = 50, velocity = .1, activity = 1, clothing = 1, pmvResult, ppdResult;

function set_metric() {
	air_temp_low = 10;
	air_temp_high = 20;	
}

function set_english() {
	air_temp_low = 0;
	air_temp_high = 90;
}

if (is_metric) {
	set_metric();
}
else {
	set_english();
}
	
function round_to_tenths(num) {
	return Math.round(num * 10) / 10;
}

this.onEnterFrame = function (){
	var air_temp_slider = (scroll0.slider._x + 152) / 304;
	airtemp = radtemp = textbox0.text = Math.round(air_temp_low + ((air_temp_high - air_temp_low) * air_temp_slider));
	CalculatePMV();
}

function CalculatePMV()
{
	// requires the following globals
	// airtemp, radtemp, humidity, velocity, activity, clothing, pmvResult, pmdResult
	// modifies the following 2 globals pmvResult, pmdResult
    var pa, icl, m, w, mw, fcl, hcn, hcf, taa, tra, tcl, tcla, p1, p2, p3, p4, p5, xn, xf, eps, hc, hl1, hl2, hl3, hl4, hl5, hl6, ts, n, result;
    if (!is_metric) { // do conversions
		// convert c to f
		airtemp = radtemp = Math.round((airtemp - 32) / 1.8);
		// convert ft/m to m/s
		velocity = (velocity * 0.3048) / 60;
	}
	
    pa = humidity * 10 * Math.exp(16.6536 - 4030.18 / (airtemp + 235));
    icl = 0.155 * clothing;
    m = activity * 58.15;
    w = 0;
    mw = m - w;
    if (icl < 0.078) {
        fcl = 1 + 1.29 * icl;
    }
    else {
        fcl = 1.05 + 0.645 * icl;
    }


    hcf = 12.1 * Math.sqrt(velocity);
    taa = airtemp + 273;
    tra = radtemp + 273;
    tcla = taa + (35.5 - airtemp) / (3.5 * (6.45 * icl + 0.1));
    p1 = icl * fcl;
    p2 = p1 * 3.96;
    p3 = p1 * 100;
    p4 = p1 * taa;
    p5 = 308.7 - 0.028 * mw + p2 * Math.pow(tra / 100, 4);
    xn = tcla / 100;
    xf = xn;
    eps = 0.00015;
    n = 0;
    while (n < 50) 
    {
        xf = (xf + xn) / 2;
        hcn = 2.38 * Math.pow(Math.abs(100 * xf - taa), 0.25);
        if (hcf > hcn) 
        {
            hc = hcf;
        }
        else 
        {
            hc = hcn;
        }


        xn = (p5 + p4 * hc - p2 * Math.pow(xf, 4)) / (100 + p3 * hc);
        if (Math.abs(xn - xf) < eps) 
        {
            break;
        }

        ++n;
    }

    tcl = 100 * xn - 273;
    hl1 = 0.00305 * (5733 - 6.99 * mw - pa);
    if (mw > 58.15) {
        hl2 = 0.42 * (mw - 58.15);
    }
    else {
        hl2 = 0;
    }


    hl3 = 1.7e-005 * m * (5867 - pa);
    hl4 = 0.0014 * m * (34 - airtemp);
    hl5 = 3.96 * fcl * (Math.pow(xn, 4) - Math.pow(tra / 100, 4));
    hl6 = fcl * hc * (tcl - airtemp);
    ts = 0.303 * Math.exp(-0.036 * m) + 0.028;
    result = ts * (mw - hl1 - hl2 - hl3 - hl4 - hl5 - hl6);
    pmvResult = Math.round(result * 10) / 10;
    if (pmvResult < -3) {
        pmvResult = -3;
    }

    if (pmvResult > 3) {
        pmvResult = 3;
    }

    //pmv._x = 20 + (pmvResult + 3) / 6 * 410;
    result = 100 - 95 * Math.exp(-0.03353 * Math.pow(pmvResult, 4) - 0.2179 * Math.pow(pmvResult, 2));
    result = Math.round(result * 10) / 10;
    if (result > 100) 
    {
        result = 100;
    }

    if (result < 0) 
    {
        result = 0;
    }

    ppdResult = result + "%";
	
	_root.output0.text = pmvResult;
	_root.output1.text = ppdResult;
	var result_slider = Math.round((result / 100) * 150);
	if (pmvResult >= 0) {
		tempbar_mc.slider_mc._x = result_slider;
	} else {
		tempbar_mc.slider_mc._x = result_slider * -1;
	}
}



/*
f = false;
_global.doAnimation = true;
fromAnimation = "neutral";
toAnimation = "neutral";
this.onEnterFrame = function (){

	myTA = Math.round((100-scroll0.scrollvalue*100)-30);
	myTR = Math.round((100 - scroll1.scrollvalue * 100)-30);
	myRH = Math.round(100 - scroll2.scrollvalue * 100);
	myVEL = (Math.round(6000 - scroll3.scrollvalue * 6000)*0.1);
	myMET = (Math.round(40 - scroll4.scrollvalue * 40)*0.1);
	myCLO = (Math.round(30 - scroll5.scrollvalue * 30)*0.1);
	
	if(f){
		textbox0.text = 5;//(myTA * 1.8) + 32;
		textbox1.text = (myTR * 1.8) + 32;
		textbox2.text = myRH;
		textbox3.text = myVEL;
		textbox4.text = myMET;
		textbox5.text = myCLO;
	} else {
		textbox0.text = myTA;
		textbox1.text = myTR;
		textbox2.text = myRH;
		textbox3.text = myVEL;
		textbox4.text = myMET;
		textbox5.text = myCLO;
	}
	textbox0.text = scroll0.scrollvalue;
	humidity=myRH;
	airtemp=myTA;
	clothing=myCLO;
	radtemp=myTR;
	velocity=myVEL;
	activity=myMET;
	
	
	
		pa = humidity * 10 * Math.exp(16.6536 - 4030.18 / (airtemp + 235));
		icl = 0.155 * clothing;
		m = activity * 58.15;
		w = 0;
		mw = m - w;
		if (icl < 0.078) 
		{
			fcl = 1 + 1.29 * icl;
		}
		else 
		{
			fcl = 1.05 + 0.645 * icl;
		}
	
	
		hcf = 12.1 * Math.sqrt(velocity);
		taa = airtemp + 273;
		tra = radtemp + 273;
		tcla = taa + (35.5 - airtemp) / (3.5 * (6.45 * icl + 0.1));
		p1 = icl * fcl;
		p2 = p1 * 3.96;
		p3 = p1 * 100;
		p4 = p1 * taa;
		p5 = 308.7 - 0.028 * mw + p2 * Math.pow(tra / 100, 4);
		xn = tcla / 100;
		xf = xn;
		eps = 0.00015;
		n = 0;
		while (n < 50) 
		{
			xf = (xf + xn) / 2;
			hcn = 2.38 * Math.pow(Math.abs(100 * xf - taa), 0.25);
			if (hcf > hcn) 
			{
				hc = hcf;
			}
			else 
			{
				hc = hcn;
			}
	
	
			xn = (p5 + p4 * hc - p2 * Math.pow(xf, 4)) / (100 + p3 * hc);
			if (Math.abs(xn - xf) < eps) 
			{
				break;
			}
	
			++n;
		}
	
		tcl = 100 * xn - 273;
		hl1 = 0.00305 * (5733 - 6.99 * mw - pa);
		if (mw > 58.15) 
		{
			hl2 = 0.42 * (mw - 58.15);
		}
		else 
		{
			hl2 = 0;
		}
	
	
		hl3 = 1.7e-005 * m * (5867 - pa);
		hl4 = 0.0014 * m * (34 - airtemp);
		hl5 = 3.96 * fcl * (Math.pow(xn, 4) - Math.pow(tra / 100, 4));
		hl6 = fcl * hc * (tcl - airtemp);
		ts = 0.303 * Math.exp(-0.036 * m) + 0.028;
		result = ts * (mw - hl1 - hl2 - hl3 - hl4 - hl5 - hl6);
		pmvResult = Math.round(result * 10) / 10;
		if (pmvResult < -3) 
		{
			pmvResult = -3;
		}
	
		if (pmvResult > 3) 
		{
			pmvResult = 3;
		}
		result = 100 - 95 * Math.exp(-0.03353 * Math.pow(pmvResult, 4) - 0.2179 * Math.pow(pmvResult, 2));
		result = Math.round(result * 10) / 10;
		if (result > 100) 
		{
			result = 100;
		}
	
		if (result < 0) 
		{
			result = 0;
		}
	
		ppdResult = result + "%";
		result = (pmvResult + 3) / 6;
		if (result < 0.5) 
		{
			result = Math.round((0 - (0.5 - result)) * 60) / 10;
		}
		else 
		{
			result = Math.round((result - 0.5) * 60) / 10;
		}
	
	
		if (result < -3) 
		{
			result = -3;
		}
	
		if (result > 3) 
		{
			result = 3;
		}
	
		
	myPMV=pmvResult;
	myPPD=ppdResult;
	output0.text = myPMV;
	output1.text = myPPD;
	
	var myColor:Color = new Color(_level0.fanny_normal);
	
	
	if (myPMV > 1) {
		myRed=Math.round(myPMV * 85);
		myColor.setRGB(255 * 65536 + (255-myRed)*256 + (255-myRed));
		toAnimation = "hot"
		}
	else if (myPMV < -1){
		myBlue=Math.round(Math.abs(myPMV * 85));
		myColor.setRGB((255-myBlue)*65536 + (255-myBlue)*256 + 255);
		toAnimation = "cold";
		}
	else {
		myBlue=Math.round(Math.abs(myPMV * 45));
		myColor.setRGB((255-myBlue)*65536 + (255-myBlue)*256 + 255);
		toAnimation = "neutral";
	}
	//trace(myPMV);
	this.tempbar_mc.setslider(myPMV);
	if(_global.doAnimation){
		var animation = toAnimation + "from" + fromAnimation;
		
		if(toAnimation != fromAnimation){
			trace(animation);
			fanny_normal.gotoAndPlay(animation);
			fromAnimation = toAnimation;
		}
	}
	
}
*/
stop();