Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spiro - A Simulation
#1
Another adaptation of an old QB4.5 program of mine. This is a simulation of a Spirograph. To be precise it simulates the result of a wheel that runs around inside a larger wheel and the patterns that can be created with different diameters of the small wheel and offsets from its centre. It is easy to use and is something of a rabbit hole that you may well disappear down into. While instructions are included in the comments, here is the relevant text -

Quote:To experiment with the patterns that this program can produce it is only necessary to alter the values held in two constants.  These constants are SmallDiameter# and Offset#.  Changing the value in SmallDiameter# will alter the overall shape of the pattern while altering Offset# will change the "pointyness" of the peaks.  To see what I am talking about, simply play around with these constants.  Note that it is not necessary to change both values every time that you wish to change the pattern.


If you find values for one or the other of those constants feel free to post them in here. To start you off try a value of 100 for SmallDiameter#. One little warning - it is possible to get the drawing to run off the screen although this doesn't crash the program.

SPIRO.BAS
Code: (Select All)
'===========================================================================
' Subject: SIMULATION OF A SPIROGRAPH        Date: 02-23-99 (21:53)
'  Author: TarotRedhand                      Code: QB, QBasic, PDS
'===========================================================================
'SPIRO.BAS - A simulation of the most used part of the toy called a
'            spirograph.  Public domain.  Use entirely at own risk.  The
'            author accepts no liability whatsoever.  In the case that I have
'            used a registered trademark, I apologise.  I do not at this time
'            own any trademarks.
'
' There is a toy called a spirograph that is used to make curved patterns.
' This toy consists of a number of pieces that are made from transparent
' plastic and a number of ball-point pens with different coloured inks in them.
' Each piece has gear-teeth along their outside edges.  The gear-teeth are
' all of the same size, independent of the piece that they are on.  In
' addition each piece has a number of holes in them, which are designed to
' accept a pen point.
'
' This program works in VGA mode 12 graphics and is a simulation of the most
' often used part of that toy.  It simulates the use of 2 of the plastic pieces
' to produce a circular pattern.  As this program uses double-precision
' numbers and maths, it is comparatively slow.  One thing that I have done to
' speed this up is to have 2 identical SUBs with STATIC variables in them.
' This works by ensuring that the built-in functions SIN and COS are only
' called once for each of the 2 angles that are used.
'
' RULES
'
' In order to use this program there are a few rules that you should be aware
' of.  DO NOT alter the value of the constant LargeDiameter#.  DO NOT place a
' value in the constant SmallDiameter# that is less than or equal to zero or
' greater than or equal to the value in LargeDiameter#.  DO NOT place a value
' greater than one or less than or equal to zero in the constant Offset.
' Violation of any of these rules will result in at best, the program
' attempting to draw off of the screen.
'
' Using this program.
'
' To experiment with the patterns that this program can produce it is only
' necessary to alter the values held in two constants.  These constants are
' SmallDiameter# and Offset#.  Changing the value in SmallDiameter# will alter
' the overall shape of the pattern while altering Offset# will change the
' "pointyness" of the peaks.  To see what I am talking about, simply play
' around with these constants.  Note that it is not necessary to change both
' values every time that you wish to change the pattern.
'
' Anyway, have fun.
'
' TarotRedhand - 11/1998
'
Const PI# = 3.141592653589793#
Const LargeDiameter# = 478
Const SmallDiameter# = 333
Const CenterX# = 320, CenterY# = 240
Const Offset# = .725
Const Angle1# = 1
Const StartColour = 1
Const EndColour = 13
Const FALSE% = 0
Const TRUE% = Not FALSE%

LC# = (PI# * LargeDiameter#) / 360
A2# = 360 / ((PI# * SmallDiameter#) / LC#)
SmallRadius# = SmallDiameter# / 2
SmallCenterY# = 1 + SmallRadius#
SmallCenterX# = CenterX#
StartX# = CenterX#
StartY# = 1 + SmallRadius# - (SmallRadius# * Offset#)
MyX# = StartX#
MyY# = StartY#
Orbit1 SmallCenterX#, SmallCenterY#, CenterX#, CenterY#, Angle1#, TRUE%
Orbit1 MyX#, MyY#, CenterX#, CenterY#, Angle1#, FALSE%
Orbit2 MyX#, MyY#, SmallCenterX#, SmallCenterY#, -A2#, TRUE%
Screen 12
_FullScreen _SquarePixels
Line (1, 1)-(640, 480), 15, BF
Colour = StartColour
Line (StartX#, StartY#)-(MyX#, MyY#), Colour
Do
    For Index% = 1 To 360
        Orbit1 SmallCenterX#, SmallCenterY#, CenterX#, CenterY#, Angle1#, FALSE%
        Orbit1 MyX#, MyY#, CenterX#, CenterY#, Angle1#, FALSE%
        Orbit2 MyX#, MyY#, SmallCenterX#, SmallCenterY#, -A2#, FALSE%
        Line -(MyX#, MyY#), Colour
        _Delay 0.002
        If InKey$ <> "" Then
            Exit Do
        End If
    Next Index%
    Colour = Colour + 1
    If Colour > EndColour Then Colour = StartColour
Loop
End

Sub Orbit1 (PointX#, PointY#, OrbitX#, OrbitY#, Angle#, FirstTime%)
    Static C#, S#
    If FirstTime% Then
        C# = Cos(Angle# * (PI# / 180#))
        S# = Sin(Angle# * (PI# / 180#))
    End If
    OldX# = PointX# - OrbitX#
    OldY# = PointY# - OrbitY#
    PointX# = (OldX# * C# - OldY# * S#) + OrbitX#
    PointY# = (OldX# * S# + OldY# * C#) + OrbitY#
End Sub

Sub Orbit2 (PointX#, PointY#, OrbitX#, OrbitY#, Angle#, FirstTime%)
    Static C#, S#
    If FirstTime% Then
        C# = Cos(Angle# * (PI# / 180#))
        S# = Sin(Angle# * (PI# / 180#))
    End If
    OldX# = PointX# - OrbitX#
    OldY# = PointY# - OrbitY#
    PointX# = (OldX# * C# - OldY# * S#) + OrbitX#
    PointY# = (OldX# * S# + OldY# * C#) + OrbitY#
End Sub

TR
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: 2 Guest(s)