about summary refs log blame commit diff stats
path: root/508circle.mu
blob: 98cd5272b8c90c6f2aaca097c34a49592447ae3d (plain) (tree)
1
2
3
4
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn {
fn draw-circle screen: (addr screen), cx: int, cy: int, radius: int, color: int {
  var x: int
  var y: int
  var err: int
  # x = -r
  var tmp/eax: int <- copy radius
  tmp <- negate
  copy-to x, tmp
  # err = 2 - 2*r
  tmp <- copy radius
  tmp <- shift-left 1
  tmp <- negate
  tmp <- add 2
  copy-to err, tmp
  #
  var tmpx/ecx: int <- copy 0
  var tmpy/edx: int <- copy 0
  {
    # pixel(cx-x, cy+y)
    tmpx <- copy cx
    tmpx <- subtract x
    tmpy <- copy cy
    tmpy <- add y
    pixel screen, tmpx, tmpy, color
    # pixel(cx-y, cy-x)
    tmpx <- copy cx
    tmpx <- subtract y
    tmpy <- copy cy
    tmpy <- subtract x
    pixel screen, tmpx, tmpy, color
    # pixel(cx+x, cy-y)
    tmpx <- copy cx
    tmpx <- add x
    tmpy <- copy cy
    tmpy <- subtract y
    pixel screen, tmpx, tmpy, color
    # pixel(cx+y, cy+x)
    tmpx <- copy cx
    tmpx <- add y
    tmpy <- copy cy
    tmpy <- add x
    pixel screen, tmpx, tmpy, color
    # r = err
    tmp <- copy err
    copy-to radius, tmp
    # if (r <= y) { ++y; err += (y*2 + 1); }
    {
      tmpy <- copy y
      compare radius, tmpy
      break-if->
      increment y
      tmpy <- copy y
      tmpy <- shift-left 1
      tmpy <- increment
      add-to err, tmpy
    }
    # if (r > x || err > y) { ++x; err += (x*2 + 1); }
    $draw-circle:second-check: {
      {
        tmpx <- copy x
        compare radius, tmpx
        break-if->
        tmpy <- copy y
        compare err, tmpy
        break-if->
        break $draw-circle:second-check
      }
      increment x
      tmpx <- copy x
      tmpx <- shift-left 1
      tmpx <- increment
      add-to err, tmpx
    }
    # loop termination condition
    compare x, 0
    loop-if-<
  }
}

fn draw-disc screen: (addr screen), cx: int, cy: int, radius: int, color: int, border-color: int {
  var r/eax: int <- copy 0
  {
    compare r, radius
    break-if->=
    draw-circle screen, cx cy, r, color
    r <- increment
    loop
  }
  draw-circle screen, cx cy, r, border-color
}