_TITLE "N Leafed Shamrocks, How many shamrocks until you get a 7 leafed one? by bplus 2018-03-09" ' Shamrock 2018-03-09 mod to lessons learned with JB version 2018-03-09 tsh tips
' from N Leafed Shamrocks 2018-03-08
' Draw Angled Heart.bas SmallBASIC 0.12.11 (B+=MGA) 2018-03-07
counts(nLeafs) = counts(nLeafs) + 1
counts(1) = counts(1) + 1
stat$
= stat$
+ " :" + STR$(counts
(i
)) stat$
= stat$
+ " =" + STR$(counts
(1)) _TITLE stat$
+ " N Leafed Shamrocks, How many shamrocks until you get a 7 leafed one? (1 in 625 chance) by bplus 2018-03-09" WHILE ABS(cc1%
- cc2%
) < 30 'for contrast of 2 colors xp
= RND * (xmax
- 100) + 50 yp
= RND * (ymax
- 100) + 50 drawShamrockN xp + 1, yp, size, ang, nLeafs, 1
drawShamrockN xp, yp, r, ang, nLeafs, 0
'draws an arc with center at xCenter, yCenter, radius from center is arcRadius
SUB myArc
(xCenter
, yCenter
, arcRadius
, dAStart
, dAMeasure
) 'notes:
'you may want to adjust size and color for line drawing
'using angle measures in degrees to match Just Basic ways with pie and piefilled
'this sub assumes drawing in a CW direction if dAMeasure positive
'for Just Basic angle 0 degrees is due East and angle increases clockwise towards South
'dAStart is degrees to start Angle, due East is 0 degrees
'dAMeasure is degrees added (Clockwise) to dAstart for end of arc
rAngleStart = RAD(dAStart)
rAngleEnd = RAD(dAMeasure) + rAngleStart
Stepper = RAD(1 / (.1 * arcRadius)) 'fixed
FOR rAngle
= rAngleStart
TO rAngleEnd
STEP Stepper
lastX
= xCenter
+ arcRadius
* COS(rAngle
) lastY
= yCenter
+ arcRadius
* SIN(rAngle
) nextX
= xCenter
+ arcRadius
* COS(rAngle
) IF nextX
<= lastX
THEN useX
= nextX
- 1 ELSE useX
= nextX
+ 1 nextY
= yCenter
+ arcRadius
* SIN(rAngle
) IF nextY
<= lastY
THEN useY
= nextY
- 1 ELSE useY
= nextY
+ 1 LINE (lastX
, lastY
)-(nextX
, nextY
) lastX = nextX
lastY = nextY
SUB drawHeart
(x
, y
, r
, rl
, a
, solid
) 'local x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6
'clockwise from due East, the V
x2
= x
+ rl
* COS(a
+ _PI / 2) y2
= y
+ rl
* SIN(a
+ _PI / 2) x4
= x
+ r
* COS(a
+ 3 * _PI / 2) y4
= y
+ r
* SIN(a
+ 3 * _PI / 2) x5 = (x3 + x4) / 2
y5 = (y3 + y4) / 2
x6 = (x4 + x1) / 2
y6 = (y4 + y1) / 2
filltri x1, y1, x2, y2, x3, y3
filltri x2, y2, x3, y3, x4, y4
fcirc x5, y5, .5 * r * 2 ^ .5
fcirc x6, y6, .5 * r * 2 ^ .5
'left hump
myArc x5, y5, .5 * r * 2 ^ .5, DEG(a) + 135, 180
'right hump
myArc x6, y6, .5 * r * 2 ^ .5, DEG(a) + 225, 180
SUB drawShamrockN
(x
, y
, r
, a
, nLeafed
, solid
) bigR
= 2.05 * r
* nLeafed
/ (2 * _PI) '<<<<<<<<<<<< EDIT for fuller leaves FOR leaf
= 0 TO nLeafed
- 1 x1
= x
+ bigR
* COS(a
+ leaf
* 2 * _PI / nLeafed
+ 3 * _PI / 2) y1
= y
+ bigR
* SIN(a
+ leaf
* 2 * _PI / nLeafed
+ 3 * _PI / 2) drawHeart x1
, y1
, r
, bigR
, a
+ leaf
* 2 * _PI / nLeafed
, solid
'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
SUB filltri
(xx1
, yy1
, xx2
, yy2
, xx3
, yy3
) 'make copies before swapping
x1 = xx1: y1 = yy1: x2 = xx2: y2 = yy2: x3 = xx3: y3 = yy3
'thanks Andy Amaya!
'triangle coordinates must be ordered: where x1 < x2 < x3
IF x1
<> x3
THEN slope1
= (y3
- y1
) / (x3
- x1
)
'draw the first half of the triangle
length = x2 - x1
slope2 = (y2 - y1) / (x2 - x1)
'lastx2% = lastx%
'draw the second half of the triangle
y = length * slope1 + y1: length = x3 - x2
slope3 = (y3 - y2) / (x3 - x2)
'IF INT(x + x2) <> lastx% AND INT(x + x2) <> lastx2% THEN 'works! but need 2nd? check