about summary refs log blame commit diff stats
path: root/linux/raytracing/color.mu
blob: 86b3d0b6fc1a2088720ca4fb7c360b5a04a39764 (plain) (tree)
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: 
type rgb {
  # components normalized to within [0.0, 1.0]
  r: float
  g: float
  b: float
}

# print translating to [0, 256)
fn print-rgb screen: (addr screen), _c: (addr rgb) {
  var c/esi: (addr rgb) <- copy _c
  var xn: float
  var xn-addr/ecx: (addr float) <- address xn
  fill-in-rational xn-addr, 0x3e7ff, 0x3e8  # 255999 / 1000
  # print 255.999 * c->r
  var result/xmm0: float <- copy xn
  var src-addr/eax: (addr float) <- get c, r
  result <- multiply *src-addr
  var result-int/edx: int <- truncate result
  print-int32-decimal screen, result-int
  print-string screen, " "
  # print 255.999 * c->g
  src-addr <- get c, g
  result <- copy xn
  result <- multiply *src-addr
  result-int <- truncate result
  print-int32-decimal screen, result-int
  print-string screen, " "
  # print 255.999 * c->b
  src-addr <- get c, b
  result <- copy xn
  result <- multiply *src-addr
  result-int <- truncate result
  print-int32-decimal screen, result-int
  print-string screen, "\n"
}
nv">equal contents-read-back, [xy] memory-should-contain [ 10 <- 1 # file contents read back exactly match what was written ] ] scenario write-to-fake-file-that-exists [ local-scope assume-resources [ [a] <- [] ] sink:&:sink:char, writer:num/routine <- start-writing resources, [a] sink <- write sink, 120/x sink <- write sink, 121/y close sink wait-for-routine writer contents-read-back:text <- slurp resources, [a] 10:bool/raw <- equal contents-read-back, [xy] memory-should-contain [ 10 <- 1 # file contents read back exactly match what was written ] ] scenario write-to-existing-file-preserves-other-files [ local-scope assume-resources [ [a] <- [] [b] <- [ |bcd| ] ] sink:&:sink:char, writer:num/routine <- start-writing resources, [a] sink <- write sink, 120/x sink <- write sink, 121/y close sink wait-for-routine writer contents-read-back:text <- slurp resources, [a] 10:bool/raw <- equal contents-read-back, [xy] other-file-contents:text <- slurp resources, [b] 11:bool/raw <- equal other-file-contents, [bcd ] memory-should-contain [ 10 <- 1 # file contents read back exactly match what was written 11 <- 1 # other files also continue to persist unchanged ] ]