Difference between revisions of "Pain Scale"

From BITPlan Wiki
Jump to navigation Jump to search
Line 15: Line 15:
 
[[File:pain9.svg|100px]]
 
[[File:pain9.svg|100px]]
 
[[File:pain10.svg|100px]]
 
[[File:pain10.svg|100px]]
 +
 +
The idea of the above pain scale icons is to generate them programmatically to give a proportional expression in terms of color and mouth expression.
 +
The following script creates the above icons:
 +
<source lang='bash'>
 +
#!/bin/bash
 +
# WF 2021-08-04
 +
#
 +
# create 0-10 painscale svg images
 +
#
 +
# (c) Copyright 2021 Wolfgang Fahl
 +
#
 +
onepain() {
 +
  local l_color="$1"
 +
  # mouth y position
 +
  local l_mouthy="$2"
 +
  # mouth expression x and y arc
 +
  local l_mouthrx="$3"
 +
  local l_mouthry="$4"
 +
  # which route to sweep
 +
  local l_sweepflag="$5"
 +
  local l_sat="80%"
 +
cat << EOF
 +
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 +
<!-- Copyright 2021 Wolfgang Fahl
 +
see
 +
-->
 +
<svg
 +
  xmlns:dc="http://purl.org/dc/elements/1.1/"
 +
  xmlns:cc="http://creativecommons.org/ns#"
 +
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 +
  xmlns:svg="http://www.w3.org/2000/svg"
 +
  xmlns="http://www.w3.org/2000/svg"
 +
  width="210mm"
 +
  height="210mm"
 +
  id="painbase"
 +
  version="1.1"
 +
  viewBox="0 0 220 220">
 +
  <defs>
 +
 +
    <radialGradient
 +
      id="grad1" gradientUnits="userSpaceOnUse">
 +
            <stop offset="0%"  style="start-color:hsl($l_color,$l_sat,70%);stop-color:hsl($l_color,$l_sat,60%); "/>
 +
            <stop offset="70%"  style="stop-color:hsl($l_color,$l_sat,50%); "/>
 +
            <stop offset="100%" style="stop-color:hsl($l_color,$l_sat,40%); "/>
 +
    </radialGradient>
 +
 +
  </defs>
 +
  <!-- face -->
 +
  <circle cx="105" cy="105" r="100" style="fill:url(#grad1);" stroke="black"
 +
          stroke-width="2" ></circle>
 +
  <!-- eyes -->
 +
  <circle id="lefteye"  cx= "65"  cy="65" r="12" style="fill:hsl($l_color,$l_sat,30%)" ></circle>
 +
  <circle id="righteye" cx="145"  cy="65" r="12" style="fill:hsl($l_color,$l_sat,30%)" ></circle>
 +
  <!-- mouth -->
 +
  <path id="mouth" d="M 35 $l_mouthy A $l_mouthrx $l_mouthry 0 0 $l_sweepflag  175 $l_mouthy" stroke="hsl($l_color,$l_sat,30%)" fill="none" stroke-width="5"/>
 +
 +
</svg>
 +
EOF
 +
}
 +
pain=0
 +
while [ $pain -lt 11 ]
 +
do
 +
        color=$((100-pain*10))
 +
        mouthy=$((105+pain*6))
 +
        sweepflag=0
 +
        factor=$((5-pain))
 +
        if [ $pain -ge 5 ]
 +
        then
 +
          factor=$((pain-5))
 +
          sweepflag=1
 +
        fi
 +
        mouthrx=$((205-factor*10))
 +
        mouthry=$((factor*90))
 +
        echo "generating pain icon for $pain"
 +
        onepain $color $mouthy $mouthrx $mouthry $sweepflag> /tmp/pain$pain.svg
 +
        pain=$(($pain+1))
 +
done
 +
 +
</source>

Revision as of 14:41, 4 August 2021

see https://en.wikipedia.org/wiki/Pain_scale

You may use the painscale icons below under Creative Commons CC BY 4.0

Pain0.svg Pain1.svg Pain2.svg Pain3.svg Pain4.svg Pain5.svg Pain6.svg Pain7.svg Pain8.svg Pain9.svg Pain10.svg

The idea of the above pain scale icons is to generate them programmatically to give a proportional expression in terms of color and mouth expression. The following script creates the above icons:

#!/bin/bash
# WF 2021-08-04
#
# create 0-10 painscale svg images
#
# (c) Copyright 2021 Wolfgang Fahl
#
onepain() {
  local l_color="$1"
  # mouth y position
  local l_mouthy="$2"
  # mouth expression x and y arc
  local l_mouthrx="$3"
  local l_mouthry="$4"
  # which route to sweep
  local l_sweepflag="$5"
  local l_sat="80%"
cat << EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Copyright 2021 Wolfgang Fahl 
see 
-->
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   width="210mm"
   height="210mm"
   id="painbase"
   version="1.1"
   viewBox="0 0 220 220">
  <defs>

    <radialGradient
       id="grad1" gradientUnits="userSpaceOnUse">
            <stop offset="0%"   style="start-color:hsl($l_color,$l_sat,70%);stop-color:hsl($l_color,$l_sat,60%); "/>
            <stop offset="70%"  style="stop-color:hsl($l_color,$l_sat,50%); "/>
            <stop offset="100%" style="stop-color:hsl($l_color,$l_sat,40%); "/>
    </radialGradient>

  </defs>
  <!-- face -->
  <circle cx="105" cy="105" r="100" style="fill:url(#grad1);" stroke="black"
          stroke-width="2" ></circle>
  <!-- eyes -->
  <circle id="lefteye"  cx= "65"  cy="65" r="12" style="fill:hsl($l_color,$l_sat,30%)" ></circle>
  <circle id="righteye" cx="145"  cy="65" r="12" style="fill:hsl($l_color,$l_sat,30%)" ></circle>
  <!-- mouth -->
  <path id="mouth" d="M 35 $l_mouthy A $l_mouthrx $l_mouthry 0 0 $l_sweepflag  175 $l_mouthy" stroke="hsl($l_color,$l_sat,30%)" fill="none" stroke-width="5"/>

</svg>
EOF
}
pain=0
while [ $pain -lt 11 ]
do
        color=$((100-pain*10))
        mouthy=$((105+pain*6))
        sweepflag=0
        factor=$((5-pain))
        if [ $pain -ge 5 ]
        then
           factor=$((pain-5))
           sweepflag=1
        fi
        mouthrx=$((205-factor*10))
        mouthry=$((factor*90))
        echo "generating pain icon for $pain"
        onepain $color $mouthy $mouthrx $mouthry $sweepflag> /tmp/pain$pain.svg
        pain=$(($pain+1))
done