Author Topic: Quad test  (Read 493 times)

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Quad test
« on: September 06, 2016 »
Code: [Select]
'quad test.txt for Naalaa [B+=MGA] 2016-09-05

' try appendage with polygon fill method

constant:
XMAX = 800
YMAX = 600
hidden:

set window 100, 40, 800, 600
set redraw off
for a = 0 to 360
set colori 0
cls
set color 255, 0, 0
cp = xy2P(400, 300)
nextP = quad(cp, 1.0, float(a), 150.0, 50.0)
set color 0, 128, 0
nextP = quad(nextP, 1.0, float(a) * 4.0, 75.0, 25.0)
set color 0, 0, 255
nextP = quad(nextP, 1.0, float(a) * 16.0, 50.0, 13.0)
set color 255, 255, 0
nextP = quad(nextP, 1.0, float(a) * 64.0, 25.0, 7.0)
redraw
wait 100
next
wait keydown

function quad(pStart, r1#, ang#, lng#, r2#)
'solid fill circles at both ends, use polygon 4 points to fill middle area
'draws from pStart at radius r1 down angle ang for length of lng
'with r2 being the radius at end point
'returns the x, y end point in P form for further pendage drawing

'constants XMAX, YMAX
'needs fcirc(x, y, r)
'needs xy2P(x, y)

'extract x, y start line of circles
  fx# = float(pStart % (XMAX + 1))
fy# = float(pStart) / float(XMAX)
x1# = fx# + r1# * cos(ang# + 90.0)
y1# = fy# + r1# * sin(ang# + 90.0)
x2# = fx# + r1# * cos(ang# - 90.0)
y2# = fy# + r1# * sin(ang# - 90.0)

  xe# = fx# + lng# * cos(ang#)
  ye# = fy# + lng# * sin(ang#)
x3# = xe# + r2# * cos(ang# + 90.0)
y3# = ye# + r2# * sin(ang# + 90.0)
x4# = xe# + r2# * cos(ang# - 90.0)
y4# = ye# + r2# * sin(ang# - 90.0)

_fcirc int(fx#), int(fy#), int(r1#)
  _fcirc int(xe#), int(ye#), int(r2#)
'draw quad fill
draw poly[int(x1#), int(y1#), int(x2#), int(y2#), int(x4#), int(y4#), int(x3#), int(y3#)], true
return xy2P(int(xe#), int(ye#))
endfunc

procedure fcirc(x, y, r)
rsq = r * r
for a = 0 to r
b = int(sqr(float(rsq - a * a)))
x1 = x + a; x2 = x - a; y1 = y - b; y2 = y + b
draw line x1, y1, x1, y2
draw line x2, y1, x2, y2
next
endproc

function xy2P(x, y)
'note uses constants XMAX screen width
return y * (XMAX + 1) + x
endfunc
B+

Rick3137

  • Sr. Member
  • ****
  • Posts: 341
  • May the Force be with You
    • View Profile
    • Rick's Programs
Re: Quad test
« Reply #1 on: September 06, 2016 »
 Works good.  37 seconds on my computer.

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: Quad test
« Reply #2 on: September 07, 2016 »
Yes, much better than going down a line with circle fills.

Thanks for tip (I think) Mopz!

Faster still, if I eliminate circle fills altogether. Except they make for easy joints, but I could just draw one at the joint. hmm...
« Last Edit: September 07, 2016 by B+ »
B+