2
$\begingroup$

I'm trying to define a function that is of this form:

f1[gr_,clr_] := Graphics@Style[gr,clr]

f2[gr1_, clr1_, gr2_, clr2_ (*etc*)] := Show[{f1[gr1,clr1], f1[gr2,clr2] (*etc*)}, "showOpts"]

Ηere, gr is a defined graphic, and clr is a color. I'm trying to have the arguments in f2 not require braces, just like one would use arguments in Graphics. I already have options for Show that are the same for every iteration of f1, but I'm having trouble with sequencing this one. `

$\endgroup$
2
  • 1
    $\begingroup$ f2 = List /* OperatorApplied[Partition][2] /* Map[Apply[f1]] /* Show. $\endgroup$ Nov 1, 2021 at 17:38
  • $\begingroup$ I'm not sure I entirely follow. Graphics takes one argument, a list of styles and objects, not a var-arg" $\endgroup$ Nov 1, 2021 at 21:58

1 Answer 1

4
$\begingroup$
ClearAll[f1, f2]
f1[gr_, clr_] := Graphics@Style[gr, clr]

f2[args : __, opts : OptionsPattern[Show]] := Show[f1 @@@ Partition[{args}, 2], opts]

Example:

f2[Disk[{2, 2}, 1], Red, 
 Annulus[{1, 1}, 1/2], Blue, 
 Rectangle[{0, 2}], Green, 
 ImageSize -> 400, Frame -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.