Skip to content

Instantly share code, notes, and snippets.

@roundrobin
Created January 24, 2013 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roundrobin/4616220 to your computer and use it in GitHub Desktop.
Save roundrobin/4616220 to your computer and use it in GitHub Desktop.
Circle play
{"description":"Circle play","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}},"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"tab":"edit","display_percent":0.5352306547619047,"hidepanel":false,"fullscreen":false,"thumbnail":"http://i.imgur.com/1avfJia.png"}
var svg = d3.select("svg");
function betwi (min, max) {
return Math.random() * (max - min) + min;
}
function Path(canvas){
this.dataPoints = [];
this.path = canvas.append('svg:path')
.attr("stroke","black")
.attr("stroke-width",3)
.attr("fill","none")
}
Path.prototype.el = function(wayPoint){
return this.path;
}
Path.prototype.add = function(wayPoint){
this.dataPoints.push(wayPoint);
this.render();
}
Path.prototype.render = function(){
this.path.attr("d",this.pathWay());
}
Path.prototype.pathWay = function(){
console.log('Hello')
var way = '';
for(var i=0;i < this.dataPoints.length;i++){
var elem = this.dataPoints[i];
console.log('check',elem);
way += elem.join(' ')
}
return way;
}
var g = svg.append("svg:g")
.attr("transform","translate("+[506,415]+")")
.attr("class","group");
var radius = 301;
var text = ["China",
"India",
"United States",
"Indonesia",
"Brazil",
"Pakistan",
"Nigeria",
"Bangladesh",
"Russia",
"Japan",
"Mexico",
"Philippines",
"Vietnam",
"Ethiopia",
"Egypt",
"Germany",
"Iran",
"Turkey",
"Democratic Republic of the Congo",
"Thailand",
"France",
"United Kingdom",
"Italy",
"South Africa",
"South Korea",
"Myanmar",
"Colombia",
"Spain",
"Ukraine",
"Tanzania",
"Argentina",
"Kenya",
"Poland",
"Algeria",
"Canada",
"Uganda",
"Iraq",
"Morocco",
"Sudan",
"Peru",
"Malaysia",
"Uzbekistan",
"Venezuela",
"Saudi Arabia",
"Nepal",
"Afghanistan",
"Ghana",
"North Korea",
"Yemen",
"Mozambique",
"Taiwan",
"Australia",
"Syria",
"Ivory Coast",
"Madagascar",
"Angola",
"Sri Lanka",
"Cameroon",
"Romania",
"Kazakhstan",
"Netherlands",
"Chile",
"Niger",
"Malawi",
"Burkina Faso",
"Ecuador",
"Guatemala",
"Mali",
"Cambodia",
"Zambia",
"Zimbabwe",
"Senegal",
"Chad",
"Cuba",
"Belgium",
"Guinea",
"Greece",
"Tunisia",
"Portugal",
"Rwanda",
"Czech Republic",
"Bolivia",
"Haiti",
"Hungary",
"Somalia",
"Sweden",
"Belarus",
"Dominican Republic",
"Benin",
"Azerbaijan",
"Burundi",
"Austria",
"Honduras",
"United Arab Emirates",
"South Sudan",
"Switzerland",
"Israel",
"Tajikistan",
"Bulgaria",
"Serbia",
"Hong Kong (China)",
"Papua New Guinea",
"Libya",
"Laos",
"Paraguay",
"Jordan",
"Togo",
"El Salvador",
"Sierra Leone",
"Nicaragua",
"Denmark",
"Eritrea",
"Kyrgyzstan",
"Slovakia",
"Finland",
"Singapore",
"Turkmenistan",
"Norway",
"Ireland",
"Central African Republic",
"Georgia",
"New Zealand",
"Costa Rica",
"Palestinian territories",
"Lebanon",
"Croatia",
"Liberia",
"Republic of the Congo",
"Bosnia and Herzegovina",
"Puerto Rico",
"Kuwait",
"Moldova",
"Panama",
"Mauritania",
"Uruguay",
"Armenia",
"Lithuania",
"Albania",
"Oman",
"Mongolia",
"Jamaica",
"Lesotho",
"Namibia",
"Latvia",
"Macedonia",
"Slovenia",
"Botswana",
"Gambia",
"Qatar",
"Gabon",
"Guinea-Bissau",
"Trinidad and Tobago",
"Estonia",
"Mauritius",
"Bahrain",
"Swaziland",
"Timor-Leste",
"Fiji",
"Cyprus",
"Réunion (France)",
"Djibouti",
"Guyana",
"Equatorial Guinea",
"Comoros",
"Bhutan",
"Montenegro",
"Macau (China)",
"Western Sahara",
"Solomon Islands",
"Suriname",
"Luxembourg",
"Cape Verde",
"Malta",
"Guadeloupe (France)",
"Martinique (France)",
"Brunei",
"Bahamas",
"Iceland",
"Maldives",
"Belize",
"Barbados",
"French Polynesia",
"Vanuatu" ];
var iterations = text.length;
var n = iterations;
var points = [];
for(var i = 0; i < n; i++) {
0.832
var x = radius * Math.cos(2 * Math.PI * i / n);
var y = radius * Math.sin(2 * Math.PI * i / n);
var angle = (i/iterations * 360 ) * 1;
if(i % 2 == 0){
var reduce = 0.64;
x = x * reduce;
y = y * reduce;
points.push({"x":x,"y": y})
}
g.append('svg:text')
.text(text[i])
.attr("fill", "#000000")
.attr("x", x)
.attr("y", y)
.attr("font-size", 10)
.attr("font-family", "Arial")
.attr("text-anchor", "start")
.attr("transform","translate(0,0)rotate("+[(angle) ]+","+(x)+","+(y)+")")
g.append("svg:circle")
.attr("r",1.88)
.attr("cx",x*0.99)
.attr("cy",y*0.99)
.attr("fill","#001FFF");
}
var path = new Path(svg)
path.el().attr("transform","translate("+[50,46]+")");
path.add(['m',1,0]);
path.add(['q',-154,169,128,220]);
console.log(points)
for(var i = 0; i < points.length; i++) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment