- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我一直在谷歌搜索,但没有找到这个问题的答案或文章。我想创建一个六边形网格,但我需要半色调图案,所以我可能需要在图案中使用多个六边形。下面是生成六边形图案但不是半色调图案的代码。我需要半色调图案水平移动。我有这个 link来自 adobe 的半色调图案,但网格太小,它是垂直的,但我想要水平的。这是我在 codepen 上制作的六边形网格的链接.有人可以告诉我如何将六边形图案水平放置在半色调图案中吗?
html, body {
height: 100%;
margin: 0;
padding: 0;
background: black;
}
svg {
background: rgb(125, 155, 132);
}
polygon {
fill: rgb(125, 155, 132);
stroke-width: 1;
stroke: #000;
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%">
<defs>
<pattern id="hexagons" width="50" height="43.4"
patternUnits="userSpaceOnUse"
patternTransform="scale(2)">
<polygon
points="24.8,22 37.3,29.2 37.3,43.7 24.8,50.9 12.3,43.7 12.3,29.2"
id="hex" shape-rendering="geometricPrecision" />
<use xlink:href="#hex" x="25" />
<use xlink:href="#hex" x="-25" />
<use xlink:href="#hex" x="12.5" y="-21.7" />
<use xlink:href="#hex" x="-12.5" y="-21.7" />
</pattern>
</defs>
<rect width="100%" height="100%" fill="url(#hexagons)" />
</svg>
最佳答案
由于六边形的半径是 x 的变量,因此您不能在此处使用模式。主要思想是这样的:
fill:black;
R
的半径值来执行此操作。这正在生成一个六边形格子。let r = R * Math.sin(angle)
其中 Angular 是 x 值的函数,计算如下:let angle = map(x, 0, H, 0, Math.PI);
这意味着 x
是取一个介于 0 和 200 (H
) 之间的值, Angular 值介于 o 和 Math.PI 之间。请阅读我代码中的注释。
const SVG_NS = 'http://www.w3.org/2000/svg';
const SVG_XLINK = "http://www.w3.org/1999/xlink"
// variables used to draw the hexagon stack
let R = 5;// the radius of the circumscribed circle
let h = R * Math.sin(Math.PI / 3);//half height of the hexagon
let offset = 1.5 * R;//used to offset every second row of hexagons
let W = 200,H=200;//svg's viewBox = "0 0 200 200"
//draw the hexagonal lattice
let i = 0;
for(let y = 0; y<H; y+=h){
i++
let o = (i%2 == 0) ? offset : 0;
for(let x = o; x<W; x+=3*R){
hex(x,y)
}
}
// a function used to draw the hexagom
// the radius of the hexagon depends on the x value
function hex(x,y) {
// the radius of the drawn hexagon is in function of the x value
let angle = map(x, 0, H, 0, Math.PI);
let r = R * Math.sin(angle) - .5
let points = ""
for (var a = 0; a < 6; a++) {
let o = {}
o.x = x + r * Math.cos(a * Math.PI / 3);
o.y = y + r * Math.sin(a * Math.PI / 3);
points+= `${o.x}, ${o.y} `
}
let hexagon = drawSVGelmt({points:points},"polygon", svg)
}
// a function used to draw a new svg element
function drawSVGelmt(o,tag, parent) {
let elmt = document.createElementNS(SVG_NS, tag);
for (let name in o) {
if (o.hasOwnProperty(name)) {
elmt.setAttributeNS(null, name, o[name]);
}
}
parent.appendChild(elmt);
return elmt;
}
function map(n, a, b, _a, _b) {
let d = b - a;
let _d = _b - _a;
let u = _d / d;
return _a + n * u;
}
svg{background:white; border:1px solid;width:90vh;}
polygon{fill:black}
<svg id="svg" viewBox = "0 0 200 200" >
</svg>
OP 正在评论:
Thats kinda what I want but I'm trying to make a pattern so I can then use that patter for a mask for an image
及后者:
basically what you have made works but I need the pattern to repeat across the page becuase the image will be 100% width and about 800px height
在这种情况下,您可以将所有六边形放在一个组中,然后使用 clipPath
像这样剪辑组:
var SVG_NS = 'http://www.w3.org/2000/svg';
var SVG_XLINK = "http://www.w3.org/1999/xlink"
let H = 800,W=500
var R = 5;
//var l = R;
var h = R * Math.sin(Math.PI / 3);
var offset = 1.5 * R;
let i = 0;
for(let y = 0; y<H; y+=h){
i++
let o = (i%2 == 0) ? offset : 0;
for(let x = o; x<W; x+=3*R){
hex(x,y)
}
}
function hex(x,y) {
let angle = map(x, 0, W, 0, Math.PI);
let r = R * Math.sin(angle) - .5
let points = ""
for (var a = 0; a < 6; a++) {
let o = {}
o.x = x + r * Math.cos(a * Math.PI / 3);
o.y = y + r * Math.sin(a * Math.PI / 3);
points+= `${o.x}, ${o.y} `
}
let hexagon = drawSVGelmt({points:points},"polygon", svg)
}
function drawSVGelmt(o,tag, parent) {
let elmt = document.createElementNS(SVG_NS, tag);
for (let name in o) {
if (o.hasOwnProperty(name)) {
elmt.setAttributeNS(null, name, o[name]);
}
}
parent.appendChild(elmt);
return elmt;
}
function map(n, a, b, _a, _b) {
let d = b - a;
let _d = _b - _a;
let u = _d / d;
return _a + n * u;
}
svg{background:white; border:1px solid;}
polygon{fill:black}
<svg viewBox = "0 0 500 800" >
<clipPath id="clip">
<polygon points="250,0 100,100 0 300 100,600 200,800 400,600 500,500 400,200 250,0"/>
</clipPath>
<g id="svg" style="clip-path: url(#clip)"></g>
</svg>
如果您没有指定 svg 元素的宽度,它将占用所有可用的宽度,即:100%。
关于html - svg 六边形半色调图案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56822537/
我想将一些颜色值从众所周知的 HSL 转换为鲜为人知的 HSLum 怎么做? hsl(0, 1.0, 0.5) - rgb red is hslum(0, 1.0., 0.54) hsl(120,
在 xml 中为 ImageView 设置色调时,我收到一条警告,显示:- 必须使用 app:tint 而不是 android:tint 为什么我应该使用 app:tint? 最佳答案 因为有一些问题
如果我有一个 alpha 整数和三个用于色调、饱和度和亮度的 float ,我如何使用一种方法以最紧凑的方式将它们转换为一个 argb 值? 编辑:我知道我可以使用 HSBtoRGB,我已经通读了 j
尝试在 firemonkey 中实现类似于此的环形颜色选择器:http://dph.am/iDropper/ 我认为可以使用在笔划上具有多点渐变的 TCircle 来完成。根据我的实验和研究,渐变只能
我在 Hadoop 2.6.2 集群中使用 Hue 3.9。这些计算机都有 Ubuntu 14.04。我能够成功安装 Hue,但从 Web UI 查看 hue 时确实出现了一些错误。我试图一次解决这些
有没有一种方法可以使用 jQ 或某些插件对图像进行着色(应用色调)?谢谢 最佳答案 我能想到的最简单的方法是在图像上覆盖一个半透明的 div。 一个小例子: HTML CSS .overlay
类似于this previous question ,我想将任意颜色的色调应用于任意图像(UIImageView)。然而,我希望色调在 N 秒的时间内逐渐消失,以产生“脉冲”效果。我将每 M 秒触发一
是否有任何命令来检查Hadoop中当前正在运行多少个色调 session ,以及是否有任何方法可以查看已随着年龄运行的 session ? 最佳答案 一个可以帮助解决这个问题的吉拉是HUE-2288
我是 seaborn 的新手,我有这个数据集,想创建一个这样的图表,但要使用 seaborn。 这是我的数据: max_depth = [ 3, 3, 3, 3, 3, 5, 5, 5,
我是 seaborn 的新手,我有这个数据集,想创建一个这样的图表,但要使用 seaborn。 这是我的数据: max_depth = [ 3, 3, 3, 3, 3, 5, 5, 5,
如何使用 Stylus 更改十六进制颜色值的色调和增加饱和度? 最佳答案 Stylus 实际上内置了这些功能。基于文档 hue , saturation : 以下应该有效: 色调(#00c, 90de
我正在尝试创建一个应用程序,允许我通过调整上述每个字段的搜索栏来调整图像的色调、饱和度、亮度、对比度和清晰度。喜欢 http://ronbigelow.com/articles/workflow_ba
我为此问题创建了一个示例数据集 import pandas as pd from pandas import DataFrame import seaborn as sns import numpy
(HI) 我不是比色学方面的专家,但我想知道如何实现基于主色生成随机颜色的脚本。 可能是随机的阴影或色调 例如:#f25f9a。 http://www.color-hex.com/color/f25f
我用 TextView 制作了一些复选框和单选按钮,但它们在 Lollipop 之前没有着色。 我的 TextView 扩展 AppCompatCheckedTextView,样式如下: ?
我创建了一个启用了分析的 Solr 仪表板。计数器按钮现在显示,但它是灰色的。 Hue 或 solr 中是否有任何我应该启用的附加标志? 谢谢 我正在使用 Solr 7 + Hue 4 最佳答案 这是
正如标题所说,如何将状态栏图标的颜色更改为深色调而不是默认的白色。 来自 到 最佳答案 要使状态栏图标具有深色而不是默认的白色,请在 styles.xml 中添加以下标记(或者更准确地说是在 valu
刚刚在我的 iPhone 3GS 上切换到 iOS 4,我的一些应用程序崩溃了。 我遇到的一个问题是,我有一个带有一些按钮的 UIToolbar,颜色为粉红色,在 3.1.3 操作系统上运行良好。升级
我有一个“位图”类型,其中包含一些随机位图数据。我已经编写了自己的亮度、颜色、饱和度和色调调整,这些调整分别作用于每个位,毫不奇怪,速度非常慢。 在我的研究中,我注意到使用矩阵可以非常快地调整这些。此
假 --> HEX color:
我是一名优秀的程序员,十分优秀!