Skip to content

Add plate-capacitor.typ to gallery#786

Merged
johannes-wolf merged 3 commits intocetz-package:masterfrom
janosh:plate-capacitor-gallery
Jan 7, 2025
Merged

Add plate-capacitor.typ to gallery#786
johannes-wolf merged 3 commits intocetz-package:masterfrom
janosh:plate-capacitor-gallery

Conversation

@janosh
Copy link
Contributor

@janosh janosh commented Jan 3, 2025

another gallery example following #783. this one comes with a question. what's the best way to get a rectangle with rounded corners and split in half with different fill colors. i tried beziers first but then opted for two rectangles but couldn't figure out how to get the rounded corners.

current

Screenshot 2025-01-03 at 6 07 44 PM

desired (see tikz code)

plate-capacitor-hd

final
plate-capacitor

@johannes-wolf
Copy link
Member

johannes-wolf commented Jan 7, 2025

Hi, thank you!

You can draw two rects side by side, each having rounded corners on the opposing side:

#cetz.canvas({
  import cetz.draw: *

  let pill(a, b, stroke: black, left-fill: blue, right-fill: red) = group({
    anchor("a", a)
    anchor("b", b)
    
    rect("a", (("a", "|-", "b"), 50%, "b"), fill: left-fill, stroke: stroke, radius: (west: .5, rest: 0))
    rect((("a", "-|", "b"), 50%, "a"), "b", fill: right-fill, stroke: stroke, radius: (east: .5, rest: 0))
  })

  pill((0,0), (4,2))
  pill((2,3), (rel: (3,1)))
})

Gives:
grafik

janosh added a commit to janosh/diagrams that referenced this pull request Jan 7, 2025
janosh added a commit to janosh/diagrams that referenced this pull request Jan 7, 2025
@janosh
Copy link
Contributor Author

janosh commented Jan 7, 2025

@johannes-wolf thanks! looks great. this should be ready to go

@johannes-wolf johannes-wolf self-requested a review January 7, 2025 19:22
@johannes-wolf johannes-wolf added the documentation Improvements or additions to documentation label Jan 7, 2025
@johannes-wolf johannes-wolf merged commit c76142a into cetz-package:master Jan 7, 2025
@johannes-wolf
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants