10-02-2017, 05:02 PM

Code:

`' polygon demo 5.bas for QB64 (B+=MGA) 2017-10-02`

RANDOMIZE TIMER

CONST xmax = 700

CONST ymax = 700

SCREEN _NEWIMAGE(xmax, ymax, 32)

_TITLE "Polygon Demo 5: poly globe by bplus, spacebar will recycle whole thing again..."

horizon% = ymax / 2 + 80

land& = _NEWIMAGE(xmax, ymax, 32)

_DEST land&

FOR i = 0 TO horizon%

midInk 0, 0, 128, 40, 200, 255, i / horizon%

LINE (0, i)-(xmax, i)

NEXT

FOR i = horizon% TO ymax

midInk 40, 200, 255, 50, 200, 50, (i - horizon%) / (ymax - horizon%)

LINE (0, i)-(xmax, i)

NEXT

_DEST 0

WHILE 1

x0 = xmax / 2: y0 = ymax / 2 + 80: a = 0

_PUTIMAGE , land&, 0

radius = 240: side = 300

nV = 3

FOR i = 1 TO 60

midInk 65, 65, 65, 255, 255, 255, i / 20

turtlePolygon x0, y0, radius, a, nV, side

nV = nV + 1

radius = radius + .25 * radius * (1 / 2) ^ i

side = side - .1 * side

NEXT

dx = -150 / 500: dr = -140 / 500: ds = -200 / 500

FOR j = 1 TO 500

_PUTIMAGE , land&, 0

radius = 240 + j * dr: side = 300 + j * dr

nV = 3

FOR i = 1 TO 60

midInk 65, 65, 65, 255, 255, 255, i / 20

turtlePolygon x0 + j * dx, y0, radius, a, nV, side

nV = nV + 1

radius = radius + .25 * radius * (1 / 2) ^ i

side = side - .1 * side

NEXT

_DISPLAY

_LIMIT 50

NEXT

FOR i = 1 TO 10

midInk 255, 255, 255, 225, 255, 220, i / 10

LINE (0, 0)-(xmax, ymax), , BF

_DISPLAY

NEXT

a = 0

WHILE 1

IF _KEYHIT = 32 THEN EXIT WHILE

_PUTIMAGE , land&, 0

x0 = xmax / 2 - 150: y0 = ymax / 2 + 80

radius = 100

nV = 3

side = 100

FOR i = 1 TO 60

turtlePolygon x0, y0, radius, a, nV, side

nV = nV + 1

radius = radius + .25 * radius * (1 / 2) ^ i

side = side - .1 * side

NEXT

a = a + _PI(1 / 180)

_DISPLAY

_LIMIT 17

WEND

WEND

SUB turtlePolygon (xOrigin, yOrigin, radius, RadianAngleOffset, nVertex, side)

polyAngle = _PI(2) / nVertex

p2 = polyAngle / 2

x1 = xOrigin + radius * COS(-_PI(1 / 2))

y1 = yOrigin + radius * SIN(-_PI(1 / 2))

DO

x2 = x1 + side * COS(p2)

y2 = y1 + side * SIN(p2)

LINE (x1, y1)-(x2, y2)

p2 = p2 + polyAngle + RadianAngleOffset

x1 = x2: y1 = y2

sideCnt = sideCnt + 1

IF sideCnt = nVertex THEN EXIT DO

LOOP

END SUB

SUB midInk (r1%, g1%, b1%, r2%, g2%, b2%, fr##)

COLOR _RGB(r1% + (r2% - r1%) * fr##, g1% + (g2% - g1%) * fr##, b1% + (b2% - b1%) * fr##)

END SUB

At first I thought I had a mistake on my hands...

B += x