1.1.5 • Published 3 years ago
svg-gear-generator v1.1.5
svg-gear-generator
This library allows you to generate an SVG of a simple gear. This does NOT generate a technically accurate gear, with things like correct curved involutes and undercuts, etc. Useful for custom settings icons, (and generating stars!).
Installation
yarn add svg-gear-generatoror
npm install svg-gear-generator --saveUsage
There are three possible uses:
generateGear(args): This generates adattribute for use with<path>. Used internally by the following components.<Gear>component: For use with React. Returns a<path>element.<GearWithAxle>component: For use with React, same as<Gear>but also includes a circle for the axle.
Arguments for the generateGear function and custom props for <Gear> and <GearWithAxle> are the same:
radii: { outer: number; inner: number }: Specify the outer and inner radiuses of the gear (addendum and dedendum circle radiuses)numTeeth: number: Number of gear teeth.toothThicknessPercent: number: For each tooth, how much of it is the flat part (see examples). Optional, defaults to0.5
The <Gear> component additionally takes any props that <path> does. The <GearWithAxle> takes additionally:
axleRadius: number: Radius of the axle.axleProps: React.SVGAttributes<SVGPathElement>: Any additional props to be passed to the<circle>element. If undefined, will copy any props specified on the<GearWithAxle>component onto the<circle>element.
Examples
Gear with 9 teeth and axle.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 4 4">
<GearWithAxle
axleRadius={0.6}
numTeeth={9}
radii={{inner: 1.0, outer: 0.8}}
toothThicknessPercent={0.5}
fill="none"
stroke="black"
strokeWidth={0.05}
strokeLinejoin="round"
/>
</svg>Gear with 13 teeth.
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 4 4">
<Gear
numTeeth={13}
radii={{inner: 1.0, outer: 0.85}}
toothThicknessPercent={0.5}
fill="none"
stroke="black"
strokeWidth={0.05}
strokeLinejoin="round"
/>
</svg>Starbust
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 4 4">
<Gear
numTeeth={13}
radii={{inner: 1.0, outer: 0.7}}
toothThicknessPercent={1.0}
fill="none"
stroke="black"
strokeWidth={0.05}
strokeLinejoin="round"
/>
</svg>Star
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 4 4">
<Gear
numTeeth={5}
radii={{inner: 1.0, outer: 0.4}}
toothThicknessPercent={0.0}
fill="none"
stroke="black"
strokeWidth={0.05}
strokeLinejoin="miter"
/>
</svg>