Skip to content

Instantly share code, notes, and snippets.

@Muratam
Created September 26, 2019 04:38
Show Gist options
  • Save Muratam/6216b57cfd8a4e4609fb0df8044d44d9 to your computer and use it in GitHub Desktop.
Save Muratam/6216b57cfd8a4e4609fb0df8044d44d9 to your computer and use it in GitHub Desktop.
関係性.nim
import tables,strformat,math,strutils
let charas : Table[string,tuple[count:int,color:string]] = {
"香風智乃":(8866,"#cfefff"),
"保登心愛":(5104,"#ffefcf"),
"桐間紗路":(3180,"#efffcf"),
"天々座理世":(3120,"#efcfef"),
"宇治松千夜":(2258,"#cfffef"),
}.toTable()
let rels : seq[tuple[src,dst:string,count:int]] = @[
("桐間紗路","宇治松千夜",1+109),
("保登心愛","桐間紗路",1+19),
("香風智乃","保登心愛",667+46),
("天々座理世","宇治松千夜",1+13),
("保登心愛","宇治松千夜",0+70),
("保登心愛","天々座理世",41+0),
("桐間紗路","天々座理世",74+70),
("香風智乃","宇治松千夜",2+7),
("香風智乃","桐間紗路",25+11),
("香風智乃","天々座理世",2+18),
]
proc grad(x,y:string,n:int):string =
let xs = (x[1..2],x[3..4],x[5..6])
let ys = (y[1..2],y[3..4],y[5..6])
result = ""
for i in 0..<n:
let mid0 = int((parseHexInt(xs[0]) * i + parseHexInt(ys[0]) * (n-i)) / n)
let mid1 = int((parseHexInt(xs[1]) * i + parseHexInt(ys[1]) * (n-i)) / n)
let mid2 = int((parseHexInt(xs[2]) * i + parseHexInt(ys[2]) * (n-i)) / n)
result &= fmt"""#{toHex(mid0)[^2..^1]}{toHex(mid1)[^2..^1]}{toHex(mid2)[^2..^1]};{1/n}:"""
var str = ""
for (src,dst,count) in rels:
str &= fmt"""{dst} -> {src}[
len = 0.1,
fontsize = "8",
fontname = "Helvetica",
penwidth = {pow(count.float ,2/3) * 0.4},
color = "{grad(charas[src].color,charas[dst].color,30)}"
# color = "{charas[src].color};0.5:{charas[dst].color};0.5:"
dir=none,
style="radial"
];""" & '\n'
for name,(count,color) in charas:
str &= fmt"""{name} [
label=" "
shape=circle,
color="{color}",
width = {count.float.sqrt / 72},
penwidth = {count / 400},
height = 0.2,
fontname = "Helvetica",
# style = "filled",
];""" & '\n'
echo """
digraph {
layout = "sfdp"; // dot, fdp, twopi
overlap = false;
splines = true;
bgcolor="transparent"
pad = 0.2;
"""&str&"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment