<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>Whendle spikes - day and night</title>
	<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js" type="text/javascript"></script>
	<script src="../whendle/api/whendle.js" type="text/javascript"></script>
	<script src="../whendle/api/time.js" type="text/javascript"></script>
	<script>
$.trace = function() { console.log($A(arguments).join(' ')); }

document.observe('dom:loaded', function() {
	document.dec = 0.0;
	document.tau = 0.0;

	wire_adjuster($('link1'), $('declination'), function(value) { document.dec = value; });
	wire_adjuster($('link2'), $('hour-angle'), function(value) { document.tau = (value * 60) / 4; });

	draw($('canvas'));
});

function wire_adjuster(source, target, on_change) {
	source.observe('click', function() {
		var visible = target.visible();
		$$('.selection').each(function(el) { el.hide() });
		if (!visible) {
			target.setStyle({
				display: 'block',
				top: (this.viewportOffset().top + 4) + 'px',
				left: (this.viewportOffset().left - 8) + 'px'
			});
		}
	});
	
	target.observe('click', function(e) {
		if (e.srcElement == this) return;
		var v = e.srcElement.innerHTML;
		this.hide();
		on_change(parseFloat(v));
		draw($('canvas'));
		source.next('.reading').innerHTML = v;
	});
}


function draw(canvas) {
	var dec = document.dec;
	var tau = document.tau;

	var img = new Image();
	img.onload = function() {
		draw_daynight(this, dec, tau);
	}
	img.src = 'map-surface.jpg';
}


function draw_daynight(map, dec, tau) {
	var canvas = $('canvas');
	var bounds = { left: 0, top: 0, right: canvas.width, bottom: canvas.height }
	var ctx = canvas.getContext('2d');
	
	draw_map(ctx, map);
	draw_sun(ctx, dec, tau);
	draw_terminator(ctx, dec, tau);
}


function draw_map(ctx, map) {
	var canvas = ctx.canvas;
	ctx.drawImage(map, 0, 0);
	
	// equator
	ctx.lineWidth = 2;
	ctx.strokeStyle = 'rgba(255, 255, 255, 0.33)';

	ctx.beginPath();
	ctx.moveTo(0, (canvas.height / 2) - 1);
	ctx.lineTo(canvas.width, (canvas.height / 2) - 1);
	ctx.stroke();	
}

function draw_sun(ctx, dec, tau) {
	var canvas = ctx.canvas;
	var radius = Math.floor(canvas.width / 120);

	ctx.lineWidth = 2;
	ctx.fillStyle = 'rgba(255, 255, 255, 0.5)';
	ctx.strokeStyle = 'rgba(240, 120, 0, 0.5)';

	var longitude = (tau * (canvas.width / 360)) + 1;
	var latitude = (dec * (canvas.height / 180)) + 1;

	ctx.beginPath();
	ctx.arc(
		(canvas.width / 2) - longitude,
		(canvas.height / 2) - latitude,
		radius,
		0,
		Math.PI * 2,
		false
	);
	ctx.stroke();
	ctx.fill();
}

function draw_terminator(ctx, dec, tau) {
}


	</script>
	<link href="flex-box.css" media="screen" rel="stylesheet" type="text/css" />
	<style>
body {
	font-family: sans-serif;
	font-size: 0.9em;
}
h4 {
	font-size: 0.9;
	font-style: italic;
	margin: 0px;<commit_msg>add terminator line to day/night map spike<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
	"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>Whendle spikes - day and night</title>
	<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js" type="text/javascript"></script>
	<script src="../whendle/api/whendle.js" type="text/javascript"></script>
	<script src="../whendle/api/time.js" type="text/javascript"></script>
	<script>
$.trace = function() { console.log($A(arguments).join(' ')); }
Math.K = Math.PI/180.0;

document.observe('dom:loaded', function() {
	document.dec = 0.0;
	document.tau = 0.0;
	document.now = Time.now();

	wire_adjuster($('link1'), $('declination'), function(value) { document.dec = value; });
	wire_adjuster($('link2'), $('hour-angle'), function(value) { document.tau = (value * 60) / 4; });

	redraw();
});

function wire_adjuster(source, target, on_change) {
	source.observe('click', function() {
		var visible = target.visible();
		$$('.selection').each(function(el) { el.hide() });
		if (!visible) {
			target.setStyle({
				display: 'block',
				top: (this.viewportOffset().top + 4) + 'px',
				left: '8px'
			});
		}
	});
	
	target.observe('click', function(e) {
		if (e.element() == this) return;
		var v = e.element().innerHTML;
		this.hide();
		on_change(parseFloat(v));
		redraw();
	});
}


function redraw() {
	var dec = document.dec;
	var tau = document.tau;

	var img = new Image();
	img.onload = function() {
		draw_daynight(this, dec, tau);
		draw_controls(dec, tau);
	}
	img.src = 'map-surface.jpg';
	
}

function draw_controls(dec, tau) {
	var declination = dec + '&deg;';
	var hour_angle = tau / 15 >= 0 ?
		Math.round(10 * tau / 15) / 10.0 + ' h' :
		'-' + Math.round(10 * Math.abs(tau / 15)) / 10.0 + ' h';
	
	$('link1').next('.reading').innerHTML = declination;
	$('link2').next('.reading').innerHTML = hour_angle;
}

function draw_daynight(map, dec, tau) {
	var canvas = $('canvas');
	var bounds = { left: 0, top: 0, right: canvas.width, bottom: canvas.height }
	var ctx = canvas.getContext('2d');
	
	draw_map(ctx, map);
	draw_sun(ctx, dec, tau);
	draw_terminator(ctx, dec, tau);
}

function draw_map(ctx, map) {
	var canvas = ctx.canvas;
	ctx.drawImage(map, 0, 0);
	
	// equator
	ctx.lineWidth = 2;
	ctx.strokeStyle = 'rgba(255, 255, 255, 0.33)';

	ctx.beginPath();
	ctx.moveTo(0, (canvas.height / 2) - 1);
	ctx.lineTo(canvas.width, (canvas.height / 2) - 1);
	ctx.stroke();	
}

function draw_sun(ctx, dec, tau) {
	var canvas = ctx.canvas;
	var radius = 4 * (canvas.height / 180);

	ctx.lineWidth = 2;
	ctx.fillStyle = 'rgba(255, 255, 100, 0.8)';
	ctx.strokeStyle = 'rgba(240, 120, 0, 0.5)';

	var x = (tau * (canvas.width / 360)) + 1;
	var y = (dec * (canvas.height / 180)) + 1;

	ctx.beginPath();
	ctx.arc(
		(canvas.width / 2) - x,
		(canvas.height / 2) - y,
		radius,
		0,
		Math.PI * 2,
		false
	);
	ctx.stroke();
	ctx.fill();
}

function draw_terminator(ctx, dec, tau) {
	var canvas = ctx.canvas;
	
	ctx.lineWidth = 2;
	ctx.strokeStyle = 'rgba(255, 255, 255, 0.5)';
	
	var xorigin = (canvas.width / 2);
	var yorigin = (canvas.height / 2);
	var xscale = (canvas.width / 360);
	var yscale = (canvas.height / 180);
	
	ctx.beginPath();
	
	for (var i = 0; i < 360; i++) {
		
		var x = (i - 180) * xscale + xorigin;
		var lng = i + tau + 180;
		var tl = -Math.cos(lng * Math.K) / Math.tan(dec * Math.K);
		var al = Math.atan(tl) / Math.K;
		var y = yorigin - (yscale * Math.round(al));
		
		if (i == 0) ctx.moveTo(x, y);
		else ctx.lineTo(x, y);
	}
	ctx.stroke();
}


	</script>
	<link href="flex-box.css" media="screen" rel="stylesheet" type="text/css" />
	<style>
body {
	font-family: sans-serif;
	font-size: 0.9em;
}
h4 {
	font-size: 0.9;
	font-style: italic;
	color: #333;
	margin: 0px;
{'fraction_non_alphanumeric': 0.2096469562690687, 'fraction_numerical': 0.03632137149498765, 'mean_word_length': 3.648210668467252, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 2, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5411777', 'n_tokens_mistral': 3035, 'n_tokens_neox': 2663, 'n_words': 577}