Mintoris Forum

Author Topic: Poly Drawing Demo  (Read 1998 times)

Chuck

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1899
Poly Drawing Demo
« on: Sep 21, 2014, 11:29 PM »
Attached below is the Demo program for the new Poly shape drawing command. This is a powerful new drawing command which lets you define a shape as a series of coordinates. Then you can draw, move, scale, rotate and fill that shape. This program requires Basic 6.5 or higher to run.

Code: [Select]
' Poly Array Demo
' Written by: Charles Charbonneau
' 9/21/14

Graphics On
Wakelock On

maxSprites = 9

' Define a five pointed star
starX() = [Cos(1/10*Pi), Cos(9/10*Pi), Cos(17/10*Pi), Cos(5/10*Pi), Cos(13/10*Pi), Cos(1/10*Pi)] * 100
starY() = [Sin(1/10*Pi), Sin(9/10*Pi), Sin(17/10*Pi), Sin(5/10*Pi), Sin(13/10*Pi), Sin(1/10*Pi)] * 100

dim x(maxSprites)
dim y(maxSprites)
dim vx(maxSprites)
dim vy(maxSprites)
dim scale(maxSprites)
dim scaleAdj(maxSprites)
dim rotDeg(maxSprites)
dim rotDegAdj(maxSprites)
dim polyColor(maxSprites,2)

maxX = ScreenX()
maxY = ScreenY()

' Randomly set all the parameters for each star
For i = 0 to maxSprites
  x(i) = Rnd(maxX)
  y(i) = Rnd(maxY)
  vx(i) = Rnd(500)-250
  vy(i) = Rnd(500)-250
  scale(i) = Rnd(1) * 2
  scaleAdj(i) = (0.1 + Rnd(1) * 0.2) * sign(Rnd(1)-.5)
  rotDeg(i) = Rnd(90) - 45
  rotDegAdj(i) = (5 + Rnd(15)) * sign(Rnd(1)-.5)
  polyColor(i,0) = 50 + Rnd(50)
  polyColor(i,1) = 50 + Rnd(50)
  polyColor(i,2) = 50 + Rnd(50)
Next

lastTime = Time()

Do

  timeDiff = (Time() - lastTime) / 1000
  lastTime = Time()

  Color 0,0,0
  CLS
  For i = 0 to maxSprites

    ' Update the position
    x(i) = x(i) + vx(i) * timeDiff
    y(i) = y(i) + vy(i) * timeDiff

    if x(i) < 0 then
      x(i) = 0
      vx(i) = vx(i) * -1
    endif

    if x(i) > maxX then
      x(i) = maxX
      vx(i) = vx(i) * -1
    endif

    if y(i) < 0 then
      y(i) = 0
      vy(i) = vy(i) * -1
    endif

    if y(i) > maxY then
      y(i) = maxY
      vy(i) = vy(i) * -1
    endif

    ' Update the scale
    scale(i) = scale(i) + scaleAdj(i) * timeDiff
    if scale(i) < 0.1 then
      scale(i) = 0.1
      scaleAdj(i) = scaleAdj(i) * -1
    elseif scale(i) > 2.0 then
      scale(i) = 2.0
      scaleAdj(i) = scaleAdj(i) * -1
    endif

    ' Update the rotation
    rotDeg(i) = (rotDeg(i) + rotDegAdj(i) * timeDiff) % 360

    ' Draw each star in it's own color
    Color polyColor(i,0), polyColor(i,1), polyColor(i,2), 50 * scale(i)
    Poly starX(), starY(), x(i), y(i), 1, scale(i), scale(i), rotDeg(i), 0, 0

  Next

  Touch x,y, 20

Loop While x = -1 and y = -1

Exit

-Chuck
« Last Edit: Sep 21, 2014, 11:41 PM by Chuck »