Skip to content

Instantly share code, notes, and snippets.

@erikhazzard
Created February 9, 2014 07:26
Show Gist options
  • Save erikhazzard/8895607 to your computer and use it in GitHub Desktop.
Save erikhazzard/8895607 to your computer and use it in GitHub Desktop.
damage viz
{"description":"damage viz","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":false,"loop":false,"restart":false,"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/Y5IQ5cj.png"}
svg = d3.select('svg');
var width = 500;
var height = 500;
var chart = svg.append('g');
function getMultiplier(factor, resist){
// take in a factor (0 to 1) and a resist value (e.g., the entity
// armor or magic resist or elemental resist value).
//
// Same formula for armor and resists
//
// Returns the multiplier, a number to multiply the original damage
// by
var multiplier;
if(resist >= 0){
multiplier = 100 / (100 + (factor * resist) );
} else {
multiplier = 2 - (100 / (100 - (factor * resist) ));
}
return multiplier;
}
var yMax = 200;
var xMax = 500;
var factor = 1;
var resist = 100;
var xScale = d3.scale.linear()
.domain([0, xMax])
.range([0, width]);
var yScale = d3.scale.linear()
.domain([0, yMax])
.range([0,height]);
var xVals = d3.range(0,xMax,5);
chart.selectAll('.damage')
.data(xVals)
.enter()
.append('circle')
.attr({
cx: function(d){ return xScale(d); },
cy: function(d){
return yScale(getMultiplier(factor, d)*100);
},
r: 2
})
.on('mouseenter', function(d){
console.log('resist : ', d, 'damage: ', (getMultiplier(factor, d) * 100) );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment