summaryrefslogtreecommitdiff
path: root/graphics/circuit_macros/examples/svg/ButtonsSVG.m4
blob: b9e9c12e69909516782fd661519aeb861fec2784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
.PS
# ButtonsSVG.m4
gen_init(svg_font(sans-serif,11bp__))
copy "HOMELIB_/dpictools.pic"

divert(-1)
#################################################################

                               `RoundButton(diameter,hue,linedensity)
                                hue 0=red, 60=yellow, 120=green ...'
define(`RoundButton',`[
#                               Colors and radius:
  hue = ifelse(`$2',,60,`$2')
  crad = ifelse(`$1',,circlerad,(`$1')/2)
  linedensity = ifelse(`$3',,150/scale,`$3')  # default 150 lines per inch
  hsvtorgb(hue,   1,  1, r1,g1,b1)
  hsvtorgb(hue-5, 1,0.9, r2,g2,b2)
  hsvtorgb(hue-10,1,0.5, r3,g3,b3)
#                               Shaded main disk
  define RBbackground {
    circle rad crad*($`'1) thick lthk at C outlined rgbstring($`'2,$`'3,$`'4)
    }
  C: circle invis rad crad at (0,0)
  nsteps = round_(crad*linedensity)
  lthk = crad/nsteps/(1bp__)
  ShadeObject(RBbackground,nsteps,
    0,   r1,g1,b1,
    0.2, r1,g1,b1,
    0.8, r2,g2,b2,
    1,   r3,g3,b3) at C
#                               Highlight disk with arc shading
  rad1 = crad*3/4
  C1: C.n-(0,rad1+0.02*crad)
  C2: C1+(0,2*rad1)
  lthk = 2*rad1/nsteps/(1bp__)
  define RBoverlay {
    radx = rad1 + ($`'1)*2*rad1
    if $`'1 < 1 then {
      arc cw rad radx thick lthk outlined rgbstring($`'2,$`'3,$`'4) \
        from Cintersect(C2,radx,C1,rad1) \
          to Cintersect(C2,radx,C1,rad1,R) \
        with .c at C2
      } }
  nsteps = round_(rad1*2*linedensity)
  ShadeObject(RBoverlay,nsteps,
    0,   1, 1, 1,
    0.1, 1, 1, 1,
    0.33,(r1+r2)/2,(g1+g2)/2,(b1+b2)/2,
    0.67,r1,g1,b1,
    1,  (r1+r2)/2,(g1+g2)/2,(b1+b2)/2) with .c at C1
  `$4']')

#################################################################

                               `BoxButton(wid,height,hue,linedensity)
                                hue 0=red, 60=yellow, 120=green ...'
define(`BoxButton',`[
#                               Size and Color
  boxw = ifelse(`$1',,boxwid*4/3,`$1')
  boxh = ifelse(`$2',,boxw/4,`$2')
  hue = ifelse(`$3',,180,`$3')
  hsvtorgb(hue,   1,  1, r1,g1,b1)
  hsvtorgb(hue-5, 1,0.9, r2,g2,b2)
  hsvtorgb(hue-10,1,0.5, r3,g3,b3)
#                               Peripheral shading
  linedensity = ifelse(`$4',,150/scale,`$4')
  nsteps=10
  define BxBshadow {
    box ht boxh wid boxw rad boxh/2 \
      outlined rgbstring($`'2,$`'3,$`'4) at (0,($`'1)*4*linethick bp__)
    }
  Q: ShadeObject(BxBshadow,nsteps,
    0, 1,1,1,
    1, r3,g3,b3)
#                               Shaded body
  lthk = boxh/nsteps/(1bp__)
  define BxBshade {
    v = boxh*(1-($`'1))
    h = (boxw-boxh)/2+sqrt((boxh/2)^2-(v-boxh/2)^2)
    line from (-h,v) to (h,v) thick lthk outlined rgbstring($`'2,$`'3,$`'4)
    }
  nsteps = boxh*linedensity
  C: ShadeObject(BxBshade,nsteps,
    0,   r1, g1, b1,
    0.4, r2, g2, b2,
    1,   r3, g3, b3) with .n at Q.n
#                               Shaded highlight
  bh = boxh*0.4
  bw = boxw*4/4.5
  define BxBhighlight {
    v = bh*(1-($`'1)); h = (bw-bh)/2+sqrt((bh/2)^2-(v-bh/2)^2)
    line from (-h,v) to (h,v) thick lthk outlined rgbstring($`'2,$`'3,$`'4)
    }
  nsteps = bh*linedensity
  ShadeObject(BxBhighlight,nsteps,
    0,1,1,1,
    8/nsteps,1,1,1,
    1, r2,g2,b2) with .n at Q.n+(0,-boxh/20)
  `$5']')

#################################################################
divert(0)dnl

for x=0 to 5 do {
  B: RoundButton(0.6,x*60) at (x,0)
  "Button" sprintf("%g",x+1) at B }

[ for i=0 to 2 do {
    BoxButton(1.5,,180+120*i) at (i*2,0)
    "Button" at last [].C
    }
 ] with .nw at 1st [].sw+(0,-0.5)

 command "</g>" # end font
.PE