Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rotate and Scale Mesh Shape
#7
I've updated it to use INKEY$.
This removed the use of the framecounter hack used to control the speed of the spacebar toggle.

I have also changed the keys to a more popular WASD set to control the direction.
Code: (Select All)
Option _Explicit
Screen _NewImage(800, 600, 32)

Dim As Integer x(30), y(30)
Dim As Integer N, XC, YC, size, i, j
Dim As Integer dx, dy, scale, maxsize, minsize, maxdxy, shape
Dim As Single alpha, spinspeed, adif
Dim As Long shapecolor
Dim As String k
'##################################
' Setup some default values
'##################################
XC = 300 + Int(Rnd * 200): YC = 200 + Int(Rnd * 200) '  Assign XC and YC around the center ofthe screen
N = 10 '                                                Number of Points in the shape - maximum 30
alpha = 0
spinspeed = 0.005 '                                     +/- Spin speed of the shape
size = 150: scale = 10: minsize = 50: maxsize = 200
dx = 5 + Int(Rnd * 5) + 1: dy = 5 + Int(Rnd * 5) + 1: maxdxy = 40
shape = 1: shapecolor = _RGB32(240, 240, 240)
'#####################################################
'## Main loop
'#####################################################
Do
    '##################################################################################################################
    '## Calculate a new LIMIT based on the size of the shape,
    '## smaller shape faster speed, larger shape slower speed
    '##################################################################################################################
    _Limit Int((220 - size) * 0.15 + 10)
    Cls , _RGB32(0, 0, 0)
    Locate 1, 1: Print "Left/Right: Dec/Inc Spin Speed.     Down/Up: Dec/Inc. size         -/+:   Dec/Inc # of Points"
    Locate 2, 1: Print "A/D       : Dec/Inc X direction     W/S    : Dec/Inc Y direction   Space: Change Shape"

    '#####################################
    '## Generate new points for the shape
    '#####################################
    adif = (2 * _Pi / N) + spinspeed
    For i = 1 To N
        x(i) = Cos(alpha) * size + XC: y(i) = Sin(alpha) * size + YC
        alpha = alpha + adif
    Next i

    '##################
    '## Draw the shape
    '##################
    For i = 1 To N - 1
        For j = i + 1 To N
            If shape = 1 Then
                Line (x(i), y(i))-(x(j), y(j)), shapecolor '           Draws only lines
            Else
                Line (x(i), y(i))-(x(j), y(j)), shapecolor, B '        Draws Boxes
            End If
        Next j
    Next i
    _Display
    '##############################
    ' Get new shape screen position
    '##############################
    XC = XC + dx
    YC = YC + dy

    '##########################################################################################################################################
    '## Process Key presses
    '##########################################################################################################################################
    If _KeyDown(20480) And size >= minsize And XC >= size + scale And YC >= size + scale Then size = size - scale ' UP Arrow

    If _KeyDown(18432) And size <= maxsize Then '                                         Press DOWN Arrow and Size is not at maxiumum size
        If _Width - size - (2 * scale) > XC And _Height - size - (2 * scale) > YC Then '  is not off right or bottom of screen
            If XC >= size + (2 * scale) And YC >= size + (2 * scale) Then '               is not off left or top of screen
                size = size + scale '                                                     Increase Size of shape
            End If
        End If
    End If

    If _KeyDown(19200) And spinspeed > -0.02 Then spinspeed = spinspeed - 0.001 '         Left Arrow Key - Decrease Spin Speed
    If _KeyDown(19712) And spinspeed < 0.02 Then spinspeed = spinspeed + 0.001 '          Right Arrow Key - Increase Spin Speed

    k = UCase$(InKey$)
    Select Case k
        Case "A": If Abs(dx) > 1 Then ' 65
                If Abs(dx) >= 1 And Abs(dx) <= maxdxy Then dx = Sgn(dx) * Abs(dx) - (Sgn(dx) * 1)
            End If
        Case "D": If Abs(dx) < maxdxy Then '68
                If Abs(dx) >= 1 And Abs(dx) <= maxdxy Then dx = Sgn(dx) * Abs(dx) + (Sgn(dx) * 1)
            End If
        Case "W": If Abs(dy) < maxdxy Then '87
                If Abs(dy) >= 1 And Abs(dy) <= maxdxy Then dy = Sgn(dy) * Abs(dy) + (Sgn(dy) * 1)
            End If
        Case "S": If Abs(dy) > 1 Then '83
                If Abs(dy) >= 1 And Abs(dy) <= maxdxy Then dy = Sgn(dy) * Abs(dy) - (Sgn(dy) * 1)
            End If
    End Select

    If k = "-" And N > 3 Then N = N - 1 '                                            Press - key, decrease points on shape
    If k = "+" And N < 30 Then N = N + 1 '                                           Press + key, increase points on shape

    If k = " " Then shape = shape * -1 '                  Press Space to change shape, only once every 3 frames
    '##########################################################################################################################################

    '#####################################################################
    '## change direction of shape and keep it within the screen boundaries
    '#####################################################################
    If XC > _Width - size - scale Then dx = -dx
    If XC < size Then dx = -dx
    If YC >= _Height - size - scale Then dy = -dy
    If YC < size Then dy = -dy

Loop Until k = Chr$(27)
System
Reply


Messages In This Thread
Rotate and Scale Mesh Shape - by King Mocker - 11-24-2022, 03:07 AM
RE: Rotate and Scale Mesh Shape - by bplus - 11-24-2022, 03:16 AM
RE: Rotate and Scale Mesh Shape - by King Mocker - 11-24-2022, 04:14 PM
RE: Rotate and Scale Mesh Shape - by SMcNeill - 11-24-2022, 04:37 PM
RE: Rotate and Scale Mesh Shape - by King Mocker - 11-24-2022, 05:10 PM
RE: Rotate and Scale Mesh Shape - by King Mocker - 11-24-2022, 05:35 PM
RE: Rotate and Scale Mesh Shape - by SMcNeill - 11-25-2022, 06:28 PM
RE: Rotate and Scale Mesh Shape - by King Mocker - 11-24-2022, 06:04 PM
RE: Rotate and Scale Mesh Shape - by james2464 - 11-24-2022, 07:19 PM
RE: Rotate and Scale Mesh Shape - by TerryRitchie - 11-24-2022, 09:49 PM
RE: Rotate and Scale Mesh Shape - by bplus - 11-24-2022, 08:20 PM
RE: Rotate and Scale Mesh Shape - by james2464 - 11-24-2022, 08:35 PM
RE: Rotate and Scale Mesh Shape - by james2464 - 11-24-2022, 10:05 PM
RE: Rotate and Scale Mesh Shape - by mnrvovrfc - 11-24-2022, 10:45 PM
RE: Rotate and Scale Mesh Shape - by TerryRitchie - 11-24-2022, 11:33 PM
RE: Rotate and Scale Mesh Shape - by mnrvovrfc - 11-25-2022, 12:00 AM
RE: Rotate and Scale Mesh Shape - by SMcNeill - 11-25-2022, 06:40 PM
RE: Rotate and Scale Mesh Shape - by King Mocker - 11-25-2022, 03:41 AM
RE: Rotate and Scale Mesh Shape - by bplus - 11-25-2022, 02:12 PM



Users browsing this thread: 1 Guest(s)