Is it possible to apply gradient once over the whole tiling?

#let pattern = tiling(size: (30pt, 20pt), place(polygon(
  fill: gradient.linear(..color.map.rainbow),
  stroke: 1pt,
  (0%, 70%),
  (0%, 30%),
  (100%, 0%),
  (100%, 100%),
)))
#rect(fill: pattern, width: 100%, height: 20pt, stroke: 1pt)

image

I want red on the left and purple on the right, without any color repetition.

One way to do this is to place a rectangle inside another rectangle, with the inner being the rainbow and the outer one being the complement of the tiling:

#let opposite-pattern = tiling(size: (30pt, 20pt), place(polygon(
  fill: rgb("fff"),  // or whatever the background color is
  stroke: 1pt,
  (000%, 000%),
  (000%, 100%),
  (100%, 100%),
  (100%, 000%),
  (100%, 100%),
  (000%, 070%),
  (000%, 030%),
  (100%, 000%),
)))

#rect(
  width: 100%,
  height: 20pt,
  inset: 0pt,
  outset: 0pt,
  fill: gradient.linear(..color.map.rainbow),
  place(
    top + left,
    rect(
      fill: opposite-pattern, 
      width: 100%, 
      height: 20pt, 
      stroke: 1pt,
    )
  )
)

testing purposes

I trust that you are able to generalise this

1 Like

Don’t know what this means, but I removed some stuff that don’t change the output.

I don’t like that the rainbow isn’t actually what I thought, so I throw in the comparison:

#let opposite-pattern = tiling(size: (30pt, 20pt), polygon(
  fill: white,
  stroke: 1pt,
  // border
  (100%, 0%),
  (0%, 0%),
  (0%, 100%),
  (100%, 100%),
  // pattern
  (0%, 70%),
  (0%, 30%),
  (100%, 0%),
  (100%, 100%),
))

#block(
  width: 100%,
  height: 20pt,
  fill: gradient.linear(..color.map.rainbow),
  rect(fill: opposite-pattern, width: 100%, height: 100%, stroke: 1pt),
)

#block(
  width: 100%,
  height: 20pt,
  fill: gradient.linear(red, orange, yellow, green, aqua, blue, purple),
  rect(fill: opposite-pattern, width: 100%, height: 100%, stroke: 1pt),
)

#let red = rgb("#f00")
#let orange = rgb("#f70")
#let yellow = rgb("#ff0")
#let green = rgb("#0f0")
#let aqua = rgb("#0ff")
#let blue = rgb("#00f")
#let purple = rgb("#f0f")

#block(
  width: 100%,
  height: 20pt,
  fill: gradient.linear(red, orange, yellow, green, aqua, blue, purple),
  rect(fill: opposite-pattern, width: 100%, height: 100%, stroke: 1pt),
)

1 Like