This class uses the 'Golden Ratio' to create a picture of a Seed-head. The algorithm can be altered to draw other natural objects: Sunflower Seeds, Dandelion, Fir Cone, Pineapple etc.
#include <math.h>
class CSeedHeadStencil {
virtual void Disc(WORD xCenter, WORD yCenter, WORD Radius, DWORD Colour) =0;
public:
CSeedHeadStencil() {}
void Seeds(WORD x0, WORD y0, DWORD Colour, short SeedRadius=6, int Seeds=987) {
const double PI=3.1415926535897932384626433832795;
const double Phi=1.6180339887498948482045868343656;
const double dA=Phi/PI;
double Angle= dA;
for(int Seed=Seeds; Seed--; Angle+=(Phi-1)*2*PI) {
double r=sqrt(Seed)*SeedRadius*dA;
Disc(x0+(WORD)(0.5+r*cos(Angle)), y0+(WORD)(0.5+r*sin(Angle)), SeedRadius-SeedRadius*Seed/Seeds, Colour);
}
}
};
Here's a 3D version:
Then to create full spheres:
You can mix in as many 'Stencils' as you like to provide all the primitives you need.
The Colours, Drawing and Effects sections have further extensions.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.