Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw a chrysanthemum curve
DescriptionThis example shows how to draw a chrysanthemum curve in Visual Basic 6.
Keywordsgraphics, curve, chrysanthemum, chrysanthemum curve
CategoriesGraphics
 
This program uses the following equations to draw the chrysanthemum curve:

    r = 5 * (1 + Sin(11 * t / 5)) -
             4 * Sin(17 * t / 3) ^ 4 * Sin(2 * Cos(3 * t) - 28 * t) ^ 8
    x = r * Cos(t)
    y = r * Sin(t)

Subroutine DrawCurve loops variable t through the values 0 to 21 * Pi to generate and connect the curve's points.

 
Private Sub DrawCurve()
Const PI As Double = 3.14159265
Const NUM_LINES As Long = 5000
Const NUM_COLORS As Integer = 6
Dim i As Long
Dim t As Double
Dim expr As Double
Dim r As Double
Dim x As Double
Dim y As Double
Dim colors(0 To NUM_COLORS - 1) As OLE_COLOR

    ' Initialize colors.
    i = 0
    colors(i) = RGB(255, 0, 0): i = i + 1
    colors(i) = RGB(0, 255, 0): i = i + 1
    colors(i) = RGB(0, 0, 255): i = i + 1
    colors(i) = RGB(255, 255, 0): i = i + 1
    colors(i) = RGB(0, 255, 255): i = i + 1
    colors(i) = RGB(255, 0, 255): i = i + 1

    ' Get the first point.
    t = 0
    r = 5 * (1 + Sin(11 * t / 5)) - 4 * Sin(17 * t / 3) ^ 4 _
        * Sin(2 * Cos(3 * t) - 28 * t) ^ 8
    x = r * Cos(t)
    y = r * Sin(t)
    ' I switch these for vertical symmetry.
    Me.CurrentX = y
    Me.CurrentY = -x
    Me.DrawWidth = 2

    For i = 1 To NUM_LINES - 1
        t = i * 21# * PI / NUM_LINES
        r = 5 * (1 + Sin(11 * t / 5)) - 4 * Sin(17 * t / 3) _
            ^ 4 * Sin(2 * Cos(3 * t) - 28 * t) ^ 8
        x = r * Cos(t)
        y = r * Sin(t)

        'Line -(y, -x),vbblue
        Line -(y, -x), colors((i * 21 / NUM_LINES) Mod _
            NUM_COLORS)
    Next i
End Sub
 
For more information on graphics programming in Visual Basic 6, see my book Ready-to-Run Visual Basic Graphics Programming.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated