Spiro - A Simulation
#2
Oh wow! I found a pretty nice one from The Joyful Programmer:
Code: (Select All)
Const TRUE = -1
Const FALSE = 0

Dim ToothSize As _Float
Dim Circumference As _Float
Dim Radius As _Float
Dim ArcDegrees As _Float
Dim ArcDegreesHalf As _Float
Dim CutDepth As _Float
Dim CutRadius As _Float
Dim CenterX As _Unsigned Integer
Dim CenterY As _Unsigned Integer
Dim Scale As _Float
Dim NumberOfArcs As _Float
Dim NumberOfTeethHollowGearInside As _Unsigned Long
Dim NumberOfTeethHollowGearOutside As _Unsigned Long
Dim NumberOfTeethSolidGear As _Unsigned Long

Dim SolidGearOffsetRadius As _Float
Dim SolidGearAnglePosition As _Float
Dim SolidGearAngleRotation As _Float
Dim SolidGearPenHoleRadius As _Float
Dim SolidGearOffsetX As _Float
Dim SolidGearOffsetXOld As _Float
Dim SolidGearOffsetY As _Float
Dim SolidGearOffsetYOld As _Float

'  DEFINE IMAGES USED IN DEMO
Dim HollowGear As Long
Dim SolidGear As Long
Dim DrawingPaper As Long
Dim HelpMenu As Long

Dim Shared Degree As _Float

Dim PenColor As _Unsigned Long
Dim PenSize As _Unsigned Integer
Dim DrawingSpeed As _Unsigned Integer

Dim PenOn As _Byte
Dim SolidGearMoving As _Byte
Dim SolidGearMinTeeth As _Unsigned Integer
Dim HollowGearMinTeeth As _Unsigned Integer
Dim PenSizeMin As _Unsigned Integer
Dim SolidGearSpeed As Integer
Dim PenHoleDistancePercent As _Float

PenOn = FALSE
SolidGearMoving = FALSE
SolidGearMinTeeth = 14
HollowGearMinTeeth = 24
PenSizeMin = 1
SolidGearSpeed = 1

PenColor = _RGB32(255, 255, 0)
PenSize = PenSizeMin
DrawingSpeed = 1

ToothSize = 3 / 32 '  SIZE IS IN INCHES
Degree = _Pi / 180
Scale = 100
CutDepth = (1 / 16) * Scale '  SIZE IN INCHES

Screen _NewImage(800, 600, 32)
_Title "The Joyful Programmer - Spirograph's Ver 01"

CenterX = _Width(0) / 2
CenterY = _Height(0) / 2


'  *** CREATE HELP MENU ***

HelpMenu = _NewImage(270, 260, 32)
_Dest HelpMenu

Line (0, 0)-(_Width(HelpMenu) - 1, _Height(HelpMenu) - 1), _RGB32(160, 160, 160), BF
Line (5, 5)-(_Width(HelpMenu) - 6, _Height(HelpMenu) - 6), _RGB32(250, 250, 250), BF

_SetAlpha 64, _RGB32(160, 160, 160)
_SetAlpha 64, _RGB32(250, 250, 250)

Color _RGB32(0, 0, 200)
_PrintMode _KeepBackground
_PrintString (8, 8), "COMMAND KEYS:"

Color _RGB32(0, 160, 0)
_PrintString (10, 30), "1 = Pen DOWN/UP"
_PrintString (10, 46), "2 = Solid Gear Spin ON/OFF"
_PrintString (10, 62), "3 = Pen Size INCREASE"
_PrintString (10, 78), "4 = Pen Size DECREASE"
_PrintString (10, 94), "5 = CLEAR DRAWING PAPER"
_PrintString (10, 110), "6 = Hollow Gear Size INCREASE"
_PrintString (10, 126), "7 = Hollow Gear Size DECREASE"
_PrintString (10, 142), "8 = Solid Gear Size INCREASE"
_PrintString (10, 158), "9 = Solid Gear Size DECREASE"
_PrintString (10, 174), "0 = Set Random Pen Color"
_PrintString (10, 190), "Q = Pen Hole Move OUT"
_PrintString (10, 206), "A = Pen Hole Move IN"
_PrintString (10, 222), "W = Speed Up Drawing"
_PrintString (10, 238), "S = Slow Down Drawing"


'  ------------------------------------------------------------------

NumberOfTeethHollowGearInside = 130
NumberOfTeethHollowGearOutside = NumberOfTeethHollowGearInside + 28
NumberOfTeethSolidGear = 40
PenHoleDistancePercent = 80

HollowGearPixelSize = ((NumberOfTeethHollowGearOutside * ToothSize) / _Pi) * Scale + 1
SolidGearPixelSize = (((NumberOfTeethSolidGear * ToothSize) / _Pi)) * Scale + 1

SolidGearPenHoleRadius = (SolidGearPixelSize / 2 - CutDepth - 14) / 100 * PenHoleDistancePercent + 6

HollowGear = _NewImage(HollowGearPixelSize, HollowGearPixelSize, 32)
SolidGear = _NewImage(SolidGearPixelSize, SolidGearPixelSize, 32)
DrawingPaper = _NewImage(_Width(0), _Height(0), 32)


'  DRAW HOLLOW GEAR ON HOLLOWGEAR IMAGE

DrawHollowGear HollowGear, _Width(HollowGear) / 2, _Height(HollowGear) / 2, NumberOfTeethHollowGearInside, NumberOfTeethHollowGearOutside, ToothSize, CutDepth, Scale
DrawSolidGear SolidGear, _Width(SolidGear) / 2, _Height(SolidGear) / 2, NumberOfTeethSolidGear, ToothSize, CutDepth, Scale, SolidGearPenHoleRadius

ToothSpin = (360 / (NumberOfTeethHollowGearInside - NumberOfTeethSolidGear)) / 2

_Dest DrawingPaper
Cls , _RGB32(220, 220, 220)

_Dest 0

SolidGearOffsetRadius = (((NumberOfTeethHollowGearInside * ToothSize) / _Pi) / 2) * Scale - _Height(SolidGear) / 2
SolidGearPenHoleRadius = (SolidGearPixelSize / 2 - CutDepth - 14) / 100 * PenHoleDistancePercent + 6
SolidGearAnglePosition = 0
SolidGearAngleRotation = 0

Circumference1 = (NumberOfTeethHollowGearInside + 1) * ToothSize
Circumference2 = (NumberOfTeethSolidGear + 1) * ToothSize
SolidGearSpin = (Circumference1 / Circumference2)

SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

SolidGearOffsetXOld = SolidGearOffsetX
SolidGearOffsetYOld = SolidGearOffsetY
SolidGearHoleXOld = SolidGearHoleX
SolidGearHoleYOld = SolidGearHoleY



Do


    _Limit 30

    _Dest DrawingPaper

    For i = 1 To DrawingSpeed

        k& = _KeyHit

        Select Case k&
            Case 27 '  <ESC> - EXIT THE DEMO

                System

            Case 48 '  <0> - CHANGE PEN COLOR

                PenColor = _RGB32(Rnd * 256, Rnd * 256, Rnd * 256)

            Case 49 '  <1> - TURN ON/OFF PEN

                If PenOn = TRUE Then
                    PenOn = FALSE
                Else
                    PenOn = TRUE
                End If

            Case 50 '  <2> - TURN ON/OFF SOLID GEARS MOVEMENT

                If SolidGearMoving = TRUE Then
                    SolidGearMoving = FALSE
                Else
                    SolidGearMoving = TRUE
                End If

            Case 51 '  <3> - PEN SIZE INCREASE

                PenSize = PenSize + 1

            Case 52 '  <4> - PEN SIZE DECREASE

                If PenSize > PenSizeMin Then PenSize = PenSize - 1

            Case 53 '  <5> - ERASE DRAWINGS IN DRAWING PAPER

                _Dest DrawingPaper
                Cls , _RGB32(240, 240, 240)

            Case 54 '  <6> - INCREASE HOLLOW GEAR SIZE

                _FreeImage HollowGear

                NumberOfTeethHollowGearInside = NumberOfTeethHollowGearInside + 1
                NumberOfTeethHollowGearOutside = NumberOfTeethHollowGearInside + 28
                HollowGearPixelSize = ((NumberOfTeethHollowGearOutside * ToothSize) / _Pi) * Scale + 1

                HollowGear = _NewImage(HollowGearPixelSize, HollowGearPixelSize, 32)

                DrawHollowGear HollowGear, _Width(HollowGear) / 2, _Height(HollowGear) / 2, NumberOfTeethHollowGearInside, NumberOfTeethHollowGearOutside, ToothSize, CutDepth, Scale
                ToothSpin = (360 / (NumberOfTeethHollowGearInside - NumberOfTeethSolidGear)) / 2
                SolidGearOffsetRadius = (((NumberOfTeethHollowGearInside * ToothSize) / _Pi) / 2) * Scale - _Height(SolidGear) / 2

                Circumference1 = (NumberOfTeethHollowGearInside) * ToothSize
                Circumference2 = (NumberOfTeethSolidGear) * ToothSize
                SolidGearSpin = (Circumference1 / Circumference2)

                SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
                SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
                SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
                SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

                SolidGearOffsetXOld = SolidGearOffsetX
                SolidGearOffsetYOld = SolidGearOffsetY
                SolidGearHoleXOld = SolidGearHoleX
                SolidGearHoleYOld = SolidGearHoleY

            Case 55 '  <7> - DECREASE HOLLOW GEAR SIZE

                _FreeImage HollowGear

                If NumberOfTeethHollowGearInside > HollowGearMinTeeth Then NumberOfTeethHollowGearInside = NumberOfTeethHollowGearInside - 1
                NumberOfTeethHollowGearOutside = NumberOfTeethHollowGearInside + 28
                HollowGearPixelSize = ((NumberOfTeethHollowGearOutside * ToothSize) / _Pi) * Scale + 1

                HollowGear = _NewImage(HollowGearPixelSize, HollowGearPixelSize, 32)

                DrawHollowGear HollowGear, _Width(HollowGear) / 2, _Height(HollowGear) / 2, NumberOfTeethHollowGearInside, NumberOfTeethHollowGearOutside, ToothSize, CutDepth, Scale
                ToothSpin = (360 / (NumberOfTeethHollowGearInside - NumberOfTeethSolidGear)) / 2
                SolidGearOffsetRadius = (((NumberOfTeethHollowGearInside * ToothSize) / _Pi) / 2) * Scale - _Height(SolidGear) / 2

                Circumference1 = (NumberOfTeethHollowGearInside) * ToothSize
                Circumference2 = (NumberOfTeethSolidGear) * ToothSize
                SolidGearSpin = (Circumference1 / Circumference2)

                SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
                SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
                SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
                SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

                SolidGearOffsetXOld = SolidGearOffsetX
                SolidGearOffsetYOld = SolidGearOffsetY
                SolidGearHoleXOld = SolidGearHoleX
                SolidGearHoleYOld = SolidGearHoleY

            Case 56 '  <8> - INCREASE SOLID GEAR SIZE

                _FreeImage SolidGear

                NumberOfTeethSolidGear = NumberOfTeethSolidGear + 1
                SolidGearPixelSize = (((NumberOfTeethSolidGear * ToothSize) / _Pi)) * Scale + 1

                SolidGear = _NewImage(SolidGearPixelSize, SolidGearPixelSize, 32)
                SolidGearPenHoleRadius = (SolidGearPixelSize / 2 - CutDepth - 14) / 100 * PenHoleDistancePercent + 6
                DrawSolidGear SolidGear, _Width(SolidGear) / 2, _Height(SolidGear) / 2, NumberOfTeethSolidGear, ToothSize, CutDepth, Scale, SolidGearPenHoleRadius

                ToothSpin = (360 / (NumberOfTeethHollowGearInside - NumberOfTeethSolidGear)) / 2
                SolidGearOffsetRadius = (((NumberOfTeethHollowGearInside * ToothSize) / _Pi) / 2) * Scale - _Height(SolidGear) / 2

                SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
                SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
                SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
                SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

                Circumference1 = (NumberOfTeethHollowGearInside) * ToothSize
                Circumference2 = (NumberOfTeethSolidGear) * ToothSize
                SolidGearSpin = (Circumference1 / Circumference2)

                SolidGearOffsetXOld = SolidGearOffsetX
                SolidGearOffsetYOld = SolidGearOffsetY
                SolidGearHoleXOld = SolidGearHoleX
                SolidGearHoleYOld = SolidGearHoleY

            Case 57 '  <9> - DECREASE SOLID GEAR SIZE

                _FreeImage SolidGear

                If NumberOfTeethSolidGear > SolidGearMinTeeth Then NumberOfTeethSolidGear = NumberOfTeethSolidGear - 1
                SolidGearPixelSize = (((NumberOfTeethSolidGear * ToothSize) / _Pi)) * Scale + 1

                SolidGear = _NewImage(SolidGearPixelSize, SolidGearPixelSize, 32)
                SolidGearPenHoleRadius = (SolidGearPixelSize / 2 - CutDepth - 14) / 100 * PenHoleDistancePercent + 6
                DrawSolidGear SolidGear, _Width(SolidGear) / 2, _Height(SolidGear) / 2, NumberOfTeethSolidGear, ToothSize, CutDepth, Scale, SolidGearPenHoleRadius

                ToothSpin = (360 / (NumberOfTeethHollowGearInside - NumberOfTeethSolidGear)) / 2
                SolidGearOffsetRadius = (((NumberOfTeethHollowGearInside * ToothSize) / _Pi) / 2) * Scale - _Height(SolidGear) / 2

                SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
                SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
                SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
                SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

                Circumference1 = (NumberOfTeethHollowGearInside) * ToothSize
                Circumference2 = (NumberOfTeethSolidGear) * ToothSize
                SolidGearSpin = (Circumference1 / Circumference2)

                SolidGearOffsetXOld = SolidGearOffsetX
                SolidGearOffsetYOld = SolidGearOffsetY
                SolidGearHoleXOld = SolidGearHoleX
                SolidGearHoleYOld = SolidGearHoleY


            Case 113, 81 ' <q> or <Q> - MOVE THE PEN HOLE TO THE OUTSIDE OF THE SOLID GEAR

                If PenHoleDistancePercent < 100 Then
                    _FreeImage SolidGear

                    SolidGearPixelSize = (((NumberOfTeethSolidGear * ToothSize) / _Pi)) * Scale + 1
                    SolidGear = _NewImage(SolidGearPixelSize, SolidGearPixelSize, 32)
                    PenHoleDistancePercent = PenHoleDistancePercent + 1
                    SolidGearPenHoleRadius = (SolidGearPixelSize / 2 - CutDepth - 14) / 100 * PenHoleDistancePercent + 6

                    DrawSolidGear SolidGear, _Width(SolidGear) / 2, _Height(SolidGear) / 2, NumberOfTeethSolidGear, ToothSize, CutDepth, Scale, SolidGearPenHoleRadius

                    SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
                    SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
                    SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
                    SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

                    SolidGearOffsetXOld = SolidGearOffsetX
                    SolidGearOffsetYOld = SolidGearOffsetY
                    SolidGearHoleXOld = SolidGearHoleX
                    SolidGearHoleYOld = SolidGearHoleY

                End If

            Case 97, 65 '  <a> or <A> - MOVE THE HOLE TO THE INSIDE OF THE SOLID GEAR

                If PenHoleDistancePercent > 0 Then
                    _FreeImage SolidGear

                    SolidGearPixelSize = (((NumberOfTeethSolidGear * ToothSize) / _Pi)) * Scale + 1
                    SolidGear = _NewImage(SolidGearPixelSize, SolidGearPixelSize, 32)
                    PenHoleDistancePercent = PenHoleDistancePercent - 1
                    SolidGearPenHoleRadius = (SolidGearPixelSize / 2 - CutDepth - 14) / 100 * PenHoleDistancePercent + 6

                    DrawSolidGear SolidGear, _Width(SolidGear) / 2, _Height(SolidGear) / 2, NumberOfTeethSolidGear, ToothSize, CutDepth, Scale, SolidGearPenHoleRadius

                    SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
                    SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
                    SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
                    SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)

                    SolidGearOffsetXOld = SolidGearOffsetX
                    SolidGearOffsetYOld = SolidGearOffsetY
                    SolidGearHoleXOld = SolidGearHoleX
                    SolidGearHoleYOld = SolidGearHoleY

                End If

            Case 119, 87 '  <W> or <w> - SPEED UP DRAWING

                DrawingSpeed = DrawingSpeed + 1

            Case 115, 83 '  <S> or <s> - SLOW DOWN DRAWING

                If DrawingSpeed > 1 Then
                    DrawingSpeed = DrawingSpeed - 1
                End If

            Case Else

        End Select

        If PenOn = TRUE Then
            For x = -(PenSize / 3) To PenSize / 3
                For y = -(PenSize / 3) To PenSize / 3
                    Line (SolidGearHoleXOld + x, SolidGearHoleYOld + y)-(SolidGearHoleX + x, SolidGearHoleY + y), PenColor
                Next
            Next
        End If


        If SolidGearMoving = TRUE Then
            SolidGearOffsetXOld = SolidGearOffsetX
            SolidGearOffsetYOld = SolidGearOffsetY
            SolidGearHoleXOld = SolidGearHoleX
            SolidGearHoleYOld = SolidGearHoleY

            SolidGearAnglePosition = SolidGearAnglePosition + SolidGearSpeed
            SolidGearAngleRotation = SolidGearAngleRotation + SolidGearSpin - 1 ' - SolidGearSpeed)

            SolidGearOffsetX = CenterX + SolidGearOffsetRadius * Sin(SolidGearAnglePosition * Degree)
            SolidGearOffsetY = CenterY - SolidGearOffsetRadius * Cos(SolidGearAnglePosition * Degree)
            SolidGearHoleX = SolidGearOffsetX - SolidGearPenHoleRadius * Sin(SolidGearAngleRotation * Degree)
            SolidGearHoleY = SolidGearOffsetY - SolidGearPenHoleRadius * Cos(SolidGearAngleRotation * Degree)
        End If

    Next


    _Dest 0

    _PutImage (0, 0), DrawingPaper, 0
    _PutImage (2, 2), HelpMenu, 0

    DisplayImage HollowGear, CenterX, CenterY, 0, 0
    DisplayImage SolidGear, SolidGearOffsetX, SolidGearOffsetY, SolidGearAngleRotation, 0

    _Display


Loop

System



Sub DrawGearOutline (CenterX As _Unsigned Integer, CenterY As _Unsigned Integer, NumberOfTeeth As _Unsigned Integer, ToothSize As _Float, CutDepth As _Float, Scale As _Float)

    Circumference = NumberOfTeeth * ToothSize
    Radius = ((Circumference / _Pi) / 2) * Scale
    ArcDegrees = (NumberOfTeeth / 360) * Degree
    ArcDegreesHalf = ArcDegrees / 2
    NumberOfArcs = 360 / NumberOfTeeth

    For Degrees = 0 To 359 Step NumberOfArcs

        x = CenterX + Radius * Sin(Degrees * Degree)
        y = CenterY - Radius * Cos(Degrees * Degree)

        x1 = CenterX + (Radius - CutDepth) * Sin((Degrees + NumberOfArcs / 2) * Degree)
        y1 = CenterY - (Radius - CutDepth) * Cos((Degrees + NumberOfArcs / 2) * Degree)

        x2 = CenterX + Radius * Sin((Degrees + NumberOfArcs) * Degree)
        y2 = CenterY - Radius * Cos((Degrees + NumberOfArcs) * Degree)

        Line (x, y)-(x1, y1)
        Line -(x2, y2)

    Next

End Sub


Sub DrawHollowGear (Image As Long, CenterX As _Unsigned Integer, CenterY As _Unsigned Integer, NumberOfInsideTeeth As _Unsigned Integer, NumberOfOutsideTeeth As _Unsigned Integer, ToothSize As _Float, CutDepth As _Float, Scale As _Float)

    Dim ImageTemp As Long
    Dim CircumferenceInside As _Float
    Dim CircumferenceOutside As _Float
    Dim RadiusInside As _Float
    Dim RadiusOutside As _Float

    ImageTemp = _NewImage(_Width(Image), _Height(Image), 32)
    _Dest ImageTemp

    Color _RGB32(255, 255, 255)

    CircumferenceInside = NumberOfInsideTeeth * ToothSize
    RadiusInside = ((CircumferenceInside / _Pi) / 2) * Scale

    CircumferenceOutside = NumberOfOutsideTeeth * ToothSize
    RadiusOutside = ((CircumferenceOutside / _Pi) / 2) * Scale

    x = CenterX + (RadiusInside + 15) * Sin(RadiusInside * Degree)
    y = CenterY - (RadiusInside + 15) * Cos(RadiusInside * Degree)

    Circle (CenterX, CenterY), RadiusInside + 4
    Circle (CenterX, CenterY), RadiusOutside - (ToothSize * Scale) - 2
    Paint (x, y), _RGB32(255, 255, 255), _RGB32(255, 255, 255)

    _SetAlpha 190, _RGB32(255, 255, 255)
    _PutImage (0, 0), ImageTemp, Image

    Cls

    DrawGearOutline CenterX, CenterY, NumberOfInsideTeeth, ToothSize, CutDepth, Scale
    DrawGearOutline CenterX, CenterY, NumberOfOutsideTeeth, ToothSize, CutDepth, Scale

    Circle (CenterX, CenterY), RadiusInside + 4, _RGB32(255, 255, 255)
    Circle (CenterX, CenterY), RadiusOutside - (ToothSize * Scale) - 2, _RGB32(255, 255, 255)

    Paint (CenterX, CenterY - (RadiusInside + 3)), _RGB32(255, 255, 255), _RGB32(255, 255, 255)
    Paint (CenterX, CenterY - (RadiusOutside - (ToothSize * Scale))), _RGB32(255, 255, 255), _RGB32(255, 255, 255)

    Circle (CenterX, CenterY), RadiusInside + 4, _RGB32(0, 0, 0)
    Circle (CenterX, CenterY), RadiusOutside - (ToothSize * Scale) - 2, _RGB32(0, 0, 0)

    _SetAlpha 0, _RGB32(0, 0, 0)
    _SetAlpha 80, _RGB32(255, 255, 255)
    _PutImage (0, 0), ImageTemp, Image

    _Dest Image

    Color _RGBA32(64, 64, 64, 96)
    DrawGearOutline CenterX, CenterY, NumberOfInsideTeeth, ToothSize, CutDepth, Scale
    DrawGearOutline CenterX, CenterY, NumberOfOutsideTeeth, ToothSize, CutDepth, Scale

    _FreeImage ImageTemp

End Sub




Sub DrawSolidGear (Image As Long, CenterX As _Unsigned Integer, CenterY As _Unsigned Integer, NumberOfTeeth As _Unsigned Integer, ToothSize As _Float, CutDepth As _Float, Scale As _Float, SolidGearPenHoleRadius As _Float)

    Dim ImageTemp As Long
    Dim Circumference As _Float
    Dim Radius As _Float

    ImageTemp = _NewImage(_Width(Image), _Height(Image), 32)
    _Dest ImageTemp

    Color _RGB32(200, 200, 200)

    Circumference = NumberOfTeeth * ToothSize
    Radius = ((Circumference / _Pi) / 2) * Scale

    DrawGearOutline CenterX, CenterY, NumberOfTeeth, ToothSize, CutDepth, Scale

    x = CenterX
    y = CenterY - SolidGearPenHoleRadius
    Circle (x, y), 5

    Paint (CenterX, CenterY), _RGB32(200, 200, 200), _RGB32(200, 200, 200)

    _SetAlpha 200, _RGB32(200, 200, 200)
    _PutImage (0, 0), ImageTemp, Image

    Cls
    _SetAlpha 0, _RGB32(0, 0, 0)

    Color _RGB32(32, 32, 32)

    Line (CenterX - Radius, CenterY)-(CenterX + Radius, CenterY)
    Line (CenterX, CenterY - SolidGearPenHoleRadius + 5)-(CenterX, CenterY + Radius)
    Line (CenterX, CenterY - SolidGearPenHoleRadius - 5)-(CenterX, CenterY - Radius)

    _SetAlpha 128, _RGB32(32, 32, 32)
    _PutImage (0, 0), ImageTemp, Image

    _Dest Image

    Color _RGBA32(64, 64, 64, 96)
    DrawGearOutline CenterX, CenterY, NumberOfTeeth, ToothSize, CutDepth, Scale
    Circle (x, y), 5, _RGBA32(64, 64, 64, 200)

    _FreeImage ImageTemp

End Sub



Sub DisplayImage (Image As Long, x As Integer, y As Integer, angle As Single, mode As _Byte)
    'Image is the image handle which we use to reference our image.
    'x,y is the X/Y coordinates where we want the image to be at on the screen.
    'angle is the angle which we wish to rotate the image.
    'mode determines HOW we place the image at point X,Y.
    'Mode 0 we center the image at point X,Y
    'Mode 1 we place the Top Left corner of our image at point X,Y
    'Mode 2 is Bottom Left
    'Mode 3 is Top Right
    'Mode 4 is Bottom Right


    Dim px(3) As Integer, py(3) As Integer, w As Integer, h As Integer
    Dim sinr As Single, cosr As Single, i As _Byte
    w = _Width(Image): h = _Height(Image)
    Select Case mode
        Case 0 'center
            px(0) = -w \ 2: py(0) = -h \ 2
            px(3) = w \ 2: py(3) = -h \ 2
            px(1) = -w \ 2: py(1) = h \ 2
            px(2) = w \ 2: py(2) = h \ 2
        Case 1 'top left
            px(0) = 0: py(0) = 0
            px(3) = w: py(3) = 0
            px(1) = 0: py(1) = h
            px(2) = w: py(2) = h
        Case 2 'bottom left
            px(0) = 0: py(0) = -h
            px(3) = w: py(3) = -h
            px(1) = 0: py(1) = 0
            px(2) = w: py(2) = 0
        Case 3 'top right
            px(0) = -w: py(0) = 0
            px(3) = 0: py(3) = 0
            px(1) = -w: py(1) = h
            px(2) = 0: py(2) = h
        Case 4 'bottom right
            px(0) = -w: py(0) = -h
            px(3) = 0: py(3) = -h
            px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
    End Select

    sinr = Sin(angle / 57.2957795131)
    cosr = Cos(angle / 57.2957795131)

    For i = 0 To 3
        x2 = (px(i) * cosr + sinr * py(i)) + x
        y2 = (py(i) * cosr - px(i) * sinr) + y
        px(i) = x2
        py(i) = y2
    Next

    _MapTriangle _Seamless(0, 0)-(0, h - 1)-(w - 1, h - 1), Image To(px(0), py(0))-(px(1), py(1))-(px(2), py(2)), , _Smooth
    _MapTriangle _Seamless(0, 0)-(w - 1, 0)-(w - 1, h - 1), Image To(px(0), py(0))-(px(3), py(3))-(px(2), py(2)), , _Smooth

End Sub

   

This was from way back when Walter agreed to host SmallBASIC at his Forum which is how I came to QB64.
b = b + ...
Reply


Messages In This Thread
Spiro - A Simulation - by TarotRedhand - 05-10-2022, 07:02 AM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 03:37 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 04:09 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 04:56 PM
RE: Spiro - A Simulation - by aurel - 05-10-2022, 06:22 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 06:30 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 06:38 PM
RE: Spiro - A Simulation - by aurel - 05-10-2022, 06:38 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 06:44 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 08:22 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 08:59 PM
RE: Spiro - A Simulation - by bplus - 05-10-2022, 09:05 PM
RE: Spiro - A Simulation - by johnno56 - 05-11-2022, 04:20 AM
RE: Spiro - A Simulation - by TarotRedhand - 05-11-2022, 06:44 AM



Users browsing this thread: 6 Guest(s)