惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - 黄彬子

【转】Go语言:编译后文件体积过大解决方案 【转】使用 UPX 压缩可执行文件 Go语言获取路径的文件名、后缀 go - 如何将gin模式设置为release模式? 【Golang标准库】flag 【Golang踩过的坑】exported function Script should have comment or be unexported wget配置文件的使用:代理设置与不检查证书 Rust Crates 源使用帮助 2020大风口!什么是图神经网络?有什么用?终于有人讲明白了 2020必火的图神经网络(GNN)是什么?有什么用? 【每天学习一点点】Tensorflow 版本与CUDA版本 【每天学习一点点】使用plot_model绘制网络模式失败 【每天学习一点点】keras cifar10.load_data()自己下载数据 【每天学习一点点】Tensorflow2.X 运行问题:Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED 【每天学习一点点】mxnet 版本运行失败问题 【每天学习一点点】Tensorflow GPU与CPU版本 【每天学习一点点】不再显示I信息(Tensorflow GPU) 【每天学习一点点】numpy中的reshape中参数为-1 Putty与Xming组合应用
【Golang学习】SVG图片的生成
黄彬子 · 2022-11-03 · via 博客园 - 黄彬子

生成的图片:

package main

import (
    "fmt"
    "math"
)

const (
    width, height = 1200, 820
    cells         = 100
    xyrange       = 30.0
    xyscale       = width / 2 / xyrange
    zscale        = height * 0.4
    angle         = math.Pi / 6
)

var sin30, cos30 = math.Sin(angle), math.Cos(angle)

func main() {

    fmt.Printf("<svg xmlns='http://www.w3.org/2000/svg' "+
        "style='stroke: blue; fill: white; stroke-width: 1.0' "+
        "width='%d' height='%d'>", width, height)
    for i := 0; i < cells; i++ {
        for j := 0; j < cells; j++ {
            ax, ay := corner(i+1, j)
            bx, by := corner(i, j)
            cx, cy := corner(i, j+1)
            dx, dy := corner(i+1, j+1)
            fmt.Printf("<polygon points='%g,%g,%g,%g,%g,%g,%g,%g'/>\n", ax, ay, bx, by, cx, cy, dx, dy)

        }
    }
    fmt.Println("</svg>")
}

func corner(i, j int) (float64, float64) {
    x := xyrange * (float64(i)/cells - 0.5)
    y := xyrange * (float64(j)/cells - 0.5)
    z := f(x, y)

    sx := width/2 + (x-y)*cos30*xyscale
    sy := height/2 + (x+y)*sin30*xyscale - z*zscale
    return sx, sy
}

func f(x, y float64) float64 {
    r := math.Hypot(x, y)
    return math.Sin(r) / r
}