1.[代码][Lua]代码
function setup()
displayMode(OVERLAY)
end
function draw()
background(10, 10, 13, 255)
raderGraph()
end
function raderGraph()
pushMatrix()
p = {"体力","内力","精力","智力","气血"}
p = {"金","木","水","火","土"}
-- 中心坐标,半径,角度,比例
local x0,y0,r,a,s = WIDTH/2,HEIGHT/2,200,360/5,4
-- 计算四条斜线的坐标
x1,y1 = 200*math.cos(math.rad(90+a)),200*math.sin(math.rad(90+a))
x2,y2 = 200*math.cos(math.rad(90+a*2)),200*math.sin(math.rad(90+a*2))
x3,y3 = 200*math.cos(math.rad(90+a*3)),200*math.sin(math.rad(90+a*3))
x4,y4 = 200*math.cos(math.rad(90+a*4)),200*math.sin(math.rad(90+a*4))
-- 各交点坐标
axis = {t={vec2(0,r/s),vec2(0,r*2/s),vec2(0,r*3/s),vec2(0,r)},
n={vec2(x1/s,y1/s),vec2(x1*2/s,y1*2/s),vec2(x1*3/s,y1*3/s),vec2(x1,y1)},
j={vec2(x2/s,y2/s),vec2(x2*2/s,y2*2/s),vec2(x2*3/s,y2*3/s),vec2(x2,y2)},
z={vec2(x3/s,y3/s),vec2(x3*2/s,y3*2/s),vec2(x3*3/s,y3*3/s),vec2(x3,y3)},
q={vec2(x4/s,y4/s),vec2(x4*2/s,y4*2/s),vec2(x4*3/s,y4*3/s),vec2(x4,y4)}}
-- 用于绘制圈线的函数
function lines(t,n,j,z,q)
line(axis.t[t].x, axis.t[t].y, axis.n[n].x, axis.n[n].y)
line(axis.n[n].x, axis.n[n].y, axis.j[j].x, axis.j[j].y)
line(axis.z[z].x, axis.z[z].y, axis.j[j].x, axis.j[j].y)
line(axis.z[z].x, axis.z[z].y, axis.q[q].x, axis.q[q].y)
line(axis.q[q].x, axis.q[q].y, axis.t[t].x, axis.t[t].y)
end
-- 平移到中心点 (x0,y0)
translate(x0,y0)
-- 围绕中心点匀速旋转
rotate(30+ElapsedTime*10)
-- 绘制圆形背景
fill(57, 121, 189, 116)
strokeWidth(2)
strokeWidth(0)
for i=1,5 do
ellipse(0,0, 2*i*r/5)
end
-- 绘制圈线
stroke(53, 255, 0, 122)
strokeWidth(2)
for i = 1,4 do
lines(i,i,i,i,i)
end
-- 绘制雷达图的5条分支
stroke(53, 255, 0, 122)
fill(84, 255, 0, 255)
fontSize(20)
for i=1,5 do
text(p[i],0,r+20)
line(0,0,0,0+200)
rotate(a)
end
stroke(255, 32, 0, 255)
strokeWidth(4)
smooth()
-- 设定当前各参数的值
local t,n,j,z,q = 3,2,3,2,4
lines(t,n,j,z,q)
stroke(0, 10, 255, 255)
strokeWidth(4)
smooth()
-- 设定当前各参数的值
local t,n,j,z,q = 4,3,3,4,4
lines(t,n,j,z,q)
popMatrix()
end