SB Happy St Patrick's Day
#1
Code:
' Draw Angled Heart.bas SmallBASIC 0.12.11 (B+=MGA) 2018-03-07

while 1
 cc1 = rgb(0, rnd*100 +50, 0)
 cc2 = rgb(0, rnd*100 +50, 0)
 xp = rnd * xmax
 yp = rnd * ymax
 size = int(rnd*100) + 10
 ang = rnd*2*pi
 color cc1
 for r = 1 to size
   drawShamrock xp+1, yp, r, ang
   drawShamrock xp-1, yp, r, ang
   drawShamrock xp, yp+1, r, ang
   drawShamrock xp, yp-1, r, ang
   drawShamrock xp+1, yp+1, r, ang
 next
 color cc2
 for r = 1 to size
   drawShamrock xp, yp, r, ang
 next
 showpage
 delay 10
wend
pause

'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
       if rAngle = rAngleStart then
           lastX = xCenter + arcRadius * cos(rAngle)
           lastY = yCenter + arcRadius * sin(rAngle)
       else
           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
       end if
   next
end sub

sub drawHeart( x, y, r, a)
 local x1, x2, x3, x4, x5, x6, y1, y2, y3, y4, y5, y6
 'clockwise from due East, the V
 x1 = x + r * cos(a)
 y1 = y + r * sin(a)
 x2 = x + r * cos(a + pi/2)
 y2 = y + r * sin(a + pi/2)
 x3 = x + r * cos(a + pi)
 y3 = y + r * sin(a + pi)
 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
 line x1, y1, x2, y2
 line x2, y2, x3, y3
 '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
end sub

sub drawShamrock(x, y, r, a)
 local x1, x2, x3, y1, y2, y3
 x1 = x + r * cos(a + 3*pi/2)
 y1 = y + r * sin(a + 3*pi/2)
 x2 = x + r * cos(a + pi/6)
 y2 = y + r * sin(a + pi/6)
 x3 = x + r * cos(a + 5*pi/6)
 y3 = y + r * sin(a + 5*pi/6)
 drawHeart x1, y1, r, a
 drawHeart x2, y2, r, a + 2*pi/3
 drawHeart x3, y3, r, a + 4*pi/3
end sub


Attached Files Thumbnail(s)

B += x
Reply
#2
Shamrock slot machine: with 1 in 625 chance to get a 7 leafed Shamrock, how many will your run take?
Code:
' Shamrock Luck.bas SmallBASIC 0.12.11 (B+=MGA) 2018-03-10
' from: QB64 version of Shamrock 2018-03-09.bas
' 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
randomize timer
dim counts(7)
color 15, rgb(60, 30, 15)
cls
while nLeafs < 7
  luck = rnd
  if luck < 1 / 625 then
     nLeafs = 7
  elif luck < 1 / 125 then
     nLeafs = 6
  elif luck < 1 / 25
     nLeafs = 5
  elif luck < 1 / 5
     nLeafs = 4
  else
     nLeafs = 3
  fi
  counts(nLeafs) = counts(nLeafs) + 1
  counts(1) = counts(1) + 1
  stat$ = str$(counts(3))
  for i = 4 to 7
     stat$ = stat$ + " : " + str$(counts(i))
  next
  stat$ = stat$ + " = " + str$(counts(1))
  cc1 = rnd * 100 + 50
  cc2 = rnd * 100 + 50
  while abs(cc1 - cc2) < 30 'for contrast of 2 colors
     cc2 = rnd * 100 + 50
  wend
  xp = rnd * (xmax - 100) + 50
  yp = rnd * (ymax - 100) + 50
  size = int(rnd * 40) + 10
  ang = rnd * pi * 2
  color rgb(0, cc1, 0)
  drawShamrockN xp + 1, yp, size, ang, nLeafs, 1
  color rgb(0, cc2, 0)
  for r = 1 to size
     drawShamrockN xp, yp, r, ang, nLeafs, 0
  next
  color 15
  at 1, 1 : ? stat$ + " N Leafed Shamrocks, 1 in 625 chance for 7 Leafed Shamrock.
  showpage
  delay 10
wend
pause

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
 x1 = x + r * cos(a)
 y1 = y + r * sin(a)
 x2 = x + rl * cos(a + pi / 2)
 y2 = y + rl * sin(a + pi / 2)
 x3 = x + r * cos(a + pi)
 y3 = y + r * sin(a + pi)
 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
 if solid then
   drawpoly [x1, y1, x2, y2, x3, y3, x4, y4, x1, y1] filled
   circle x5, y5, .5 * r * 2 ^ .5 filled
   circle x6, y6, .5 * r * 2 ^ .5 filled
 else
   line x1, y1, x2, y2
   line x2, y2, x3, y3
   'left hump
   myArc x5, y5, .5 * r * 2 ^ .5, deg(a) + 135, 180
   'right hump
   myArc x6, y6, .5 * r * 2 ^ .5, deg(a) + 235, 180
 end if
end sub

sub drawShamrockN (x, y, r, a, nleafed, solid)
 local bigr, leaf, x1, y1
 bigr = 2.1 * r * nleafed / (2 * pi)
 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
 next
end sub

'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
      if rAngle = rAngleStart then
          lastX = xCenter + arcRadius * cos(rAngle)
          lastY = yCenter + arcRadius * sin(rAngle)
      else
          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
      end if
  next
end sub

SB has an arc sub but for some reason this handmade one draws nicer lines?


Attached Files Thumbnail(s)

B += x
Reply