Skip to content

Instantly share code, notes, and snippets.

@cbellei
Created September 28, 2013 23:00
Show Gist options
  • Save cbellei/6747592 to your computer and use it in GitHub Desktop.
Save cbellei/6747592 to your computer and use it in GitHub Desktop.
Mach cone
{"description":"Mach cone","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":true,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/dM74Emu.png"}
function range(start, end){ //function that produces evenly spaced array
var ra = [];
var i_final = Math.round(end / 0.5);
ra[0] = 0.0;
for(var i=1; i<i_final; i++){
ra[i] = ra[i-1] + 0.5;
}
console.log(ra)
return ra;
}
//---- CHANGE Mach_sub and Mach_sup! -------
var Mach_sub = 0.5; //defines subsonic Mach number
var Mach_sup = 3.0; //defines supersonic Mach number
//-------------------------------------------
var width = 1000;
var height = 1000;
var xpos = 600, ypos = 200;
var textwidth = 150, textheight = 50;
var bubble_time = 4000; //duration of each expanding circle
var vsound = 0.05; //speed of sound (in some normalized units)
var max_radius = bubble_time * vsound; //maximum radius of circles
var Mach_mult = Mach_sup / Mach_sub; // multiplierfor the 2 different Mach numbers
var vsource = Mach_sub * vsound; //speed of source particle
var sourcerd = 5; //radius of source particle
var time = range(0.0,15.0); //creates evenly spaced array
var time = time.map(function(x) {return 1.e3*x ;} ); //time is in seconds now
var xsource = time.map(function(x) {return x * vsource;} ); //position of source at different times
var svg = d3.select("svg");
var canvas = svg
.attr("width",width)
.attr("height",height)
.append("g")
.attr("transform","translate(20,0)");
var elementRoot = canvas.selectAll("g").data(xsource).enter().append("g");
//plot circles for subsonic case
var circles_sub = elementRoot.append("circle")
.attr("cx", function(d) { return d; } )
.attr("cy", ypos)
.attr("r", 0)
.attr("fill","none")
.attr("stroke","black")
.transition()
.delay( function(d,i) { return time[i]; } )
.duration( bubble_time )
.attr("r", max_radius )
.remove()
.ease("linear")
//plot source for subsonic case
var source_sub = elementRoot.append("circle")
.attr("cx", function(d) { return d; } )
.attr("cy", ypos)
.attr("r", 0)
.attr("fill","black")
.transition()
.delay( function(d,i) { return time[i]; } )
.duration( 50 )
.attr("r",sourcerd)
.remove()
//plot source for supersonic case
var circles_sup = elementRoot.append("circle")
.attr("cx", function(d) { return d; } )
.attr("cy", 2 * ypos)
.attr("r", 0)
.attr("fill","none")
.attr("stroke","black")
.transition()
.delay( function(d,i) { return time[i] / Mach_mult; } )
.duration( bubble_time )
.attr("r", max_radius )
.remove()
.ease("linear")
//plot source forsupersonic case
var source_sup = elementRoot.append("circle")
.attr("cx", function(d) { return d; } )
.attr("cy", 2 * ypos)
.attr("r", 0)
.attr("fill","black")
.transition()
.delay( function(d,i) { return time[i] / Mach_mult; } )
.duration( 50/Mach_mult )
.attr("r",sourcerd)
.remove()
//write labels and boxes for both cases
canvas.append("rect")
.attr("width", textwidth)
.attr("height",textheight)
.attr("x",xpos).attr("y",ypos-textheight/2)
.attr("fill","steelblue")
canvas.append("rect")
.attr("width", textwidth)
.attr("height",textheight)
.attr("x",xpos).attr("y",2 * ypos-textheight/2)
.attr("fill","steelblue")
canvas.append("text").text("SUBSONIC")
.attr("x",xpos+32).attr("y",ypos+5)
.attr("fill","black")
canvas.append("text").text("SUPERSONIC")
.attr("x",xpos+23).attr("y",2 * ypos+5)
.attr("fill","black")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment