'QB64 X 64 version 1.2 20180228/86 from git b301f92
'2018-08-01 started from idea I had while trying to fix holes in Colbalt's cheese wedge shooter
'2018-08-02 Make growCheese sub completely self contained
' fix shooter:
'1. shooterX, shooterY must be in center of wedge
'2. wedge needs rounded back as if cut from round cheese cake
shooterX = 400: shooterY = 300
restart:
growCheese
shooterA = 0
'OK on the cheese here is outline of where the shooter wedge will be mapped
CIRCLE (wW
/ 2, wH
/ 2), sR
+ 1 x
= shooterX
+ sR
* COS(shooterA
)y
= shooterY
+ sR
* SIN(shooterA
)x1
= shooterX
+ sR
* COS(shooterA
+ _PI(5 / 6))y1
= shooterY
+ sR
* SIN(shooterA
+ _PI(5 / 6))x2
= shooterX
+ sR
* COS(shooterA
+ _PI(7 / 6))y2
= shooterY
+ sR
* SIN(shooterA
+ _PI(7 / 6))
_PRINTSTRING (20, 20), " Here is a sample of the cheese from which we are taking a wedge, " _PRINTSTRING (20, 60), " press any key (except spacebar) to transfer cheese image to shooter surrounded by black square. " _PRINTSTRING (20, 100), " press spacebar for another cheesey layout and wedge cut.. " _PRINTSTRING (20, 140), " press left and right arrows to swing shooter around... escape quits. "
'show different patterns of holes
LINE (wW
/ 2 - sR
- 5, wH
/ 2 - sR
- 5)-STEP(2 * sR
+ 10, 2 * sR
+ 10), _RGB32(0, 0, 0), BF
drawShooter
'first makeCheese and use cheese& image to build shooter image
'dim shared ShooterX, ShooterY, ShooterA, cheese&
cx0 = wW / 2: cy0 = wH / 2 'fix center for cheese wedge
x
= shooterX
+ sR
* COS(shooterA
) y
= shooterY
+ sR
* SIN(shooterA
) x1
= shooterX
+ sR
* COS(shooterA
+ _PI(5 / 6)) y1
= shooterY
+ sR
* SIN(shooterA
+ _PI(5 / 6)) cx1
= cx0
+ sR
* COS(_PI(5 / 6)) cy1
= cy0
+ sR
* SIN(_PI(5 / 6))
'take small traingles off cheese& image and map them onto main screen at shooter position
starter
= _PI(5 / 6) + stepper
'one to one ratio of mapping
x2
= shooterX
+ sR
* COS(shooterA
+ a
) y2
= shooterY
+ sR
* SIN(shooterA
+ a
) _MAPTRIANGLE (cx
, cy
)-(cx1
, cy1
)-(cx2
, cy2
), cheese&
TO(x
, y
)-(x1
, y1
)-(x2
, y2
)
'OK check value matches
x1 = x2: y1 = y2: cx1 = cx2: cy1 = cy2
'check overlap: not perfect but good enough!
x
= shooterX
+ sR
* COS(shooterA
) y
= shooterY
+ sR
* SIN(shooterA
) x1
= shooterX
+ sR
* COS(shooterA
+ _PI(5 / 6)) y1
= shooterY
+ sR
* SIN(shooterA
+ _PI(5 / 6)) x2
= shooterX
+ sR
* COS(shooterA
+ _PI(7 / 6)) y2
= shooterY
+ sR
* SIN(shooterA
+ _PI(7 / 6))
SUB growCheese
() 'make this more self contained than first version, all hole stuff just in here nHoles = 300: maxHoleLife = 20: maxHoleRadius = 7: tfStart = 1
DIM hx
(nHoles
), hy
(nHoles
), hLife
(nHoles
)
tfStart = 0
LINE (0, 0)-(wW
, wH
), _RGBA32(255, 255, 0, 50), BF
'layer of cheese FOR i
= 1 TO nHoles
'holes in layer IF hLife
(i
) + 1 > maxHoleLife
THEN GOSUB newHole
ELSE hLife
(i
) = hLife
(i
) + 1 hx
(i
) = hx
(i
) + RND * 2 - 1 hy
(i
) = hy
(i
) + RND * 2 - 1 IF hLife
(i
) < maxHoleRadius
THEN radius = hLife(i)
ELSEIF maxHoleLife
- hLife
(i
) < maxHoleRadius
THEN radius = maxHoleLife - hLife(i)
radius = maxHoleRadius
fcirc hx(i), hy(i), radius
newHole:
'Steve McNeil's copied from his forum note: Radius is too common a name
RadiusError = -subRadius
X = subRadius
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), , BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), , BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), , BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), , BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), , BF