:PROPERTIES:
#+title: literate programming test document
#+author: bsp
* source blocks
** lisp
#+begin_src emacs-lisp
(defun org-xor (a b)
"Exclusive or."
(if a (not b) b))
#+end_src
#+results:
: org-xor
** C
;; :results value raw
#+begin_src C :results output replace
#include <stdio.h>
int main(void) {
printf("hello, world!\n");
return 0;
}
#+end_src
#+results:
: hello, world!
** Python
#+begin_src python
return "hello, world."
#+end_src
#+results:
: hello, world.
** Shell
#+begin_src shell :results output replace :eval query
ls
#+end_src
#+results:
: literate_programming.org
: literate_programming.org.html
#+begin_src shell :results file link :file "org-mode-unicorn.svg" :eval query
wget -c "https://orgmode.org/resources/img/org-mode-unicorn.svg"
#+end_src
#+results:
** TKS
#+begin_src tks :results output replace
trace "hello, world.";
#+end_src
#+results:
: hello, world.
#+begin_src tks :cmd-line "-v" :results output replace
#+end_src
#+results:
: 0.9.86.4 (arm64)
#+begin_src tks :results output replace
class MyClass{test{trace "this.type="+typename(this)+" this.class="+yacMetaClassName();}}
MyClass c; c.test();
trace [1 2 3 4];
#+end_src
#+results:
: this.type=Class this.class=MyClass
: [1, 2, 3, 4]
#+begin_src tks :args "1 '2 2.5' 3" :results output replace :eval yes
trace Arguments;
#+end_src
#+results:
: ["1", "2 2.5", "3"]
#+begin_src tks :cmd-line "-ef lib:plot" :results output replace :eval yes
function myfunc(float x) { return pow(sin(x), 3); }
Plot.Run(myfunc, 0, 2PI);
trace "plot finished";
#+end_src
#+results:
: plot finished
#+begin_src tks :cmd-line "-ef lib:plot" :results file link :file "myfunc.png" :wrap "org \n#+ATTR_HTML: :width 640"
function myfunc(float x) { return pow(sin(x), 3) * 0.9; }
Plot.SavePNG("myfunc.png", myfunc, 0, 2PI);
#+end_src
#+results:
#+begin_org
#+ATTR_HTML: :width 640
#+end_org
#+begin_src tks :cmd-line "-ef lib:plot" :results file link :file "myfunc2.png"
function myfunc(float x) { return sin(x + 0.25 * pow(sin(2*x), 3)) * 0.95; }
Plot.SetSize(640, 240); Plot.SavePNG("myfunc2.png", myfunc, 0, 2PI);
#+end_src
#+results:
#+begin_src tks :cmd-line "-ep lib:plot-fs" :results output replace :eval yes
PlotFS.Run("c = vec4(sin(p.x*M_2PI*4), fract(u_t), sin(p.y*M_2PI*9), 0,1);");
#+end_src
#+results:
: 57 frames rendered.
#+begin_src tks :cmd-line "-ep lib:plot-fs" :results output replace :eval yes
String sFS <= "vec2 t; float d = 0; float s = 0.6;"
"t = vec2(p - s*vec2(sin(u_t*1.31), sin(u_t*1.7)));"
"d += 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"t = vec2(p - s*vec2(sin(u_t*-0.93), sin(u_t*1.9)));"
"d -= 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"t = vec2(p - s*vec2(sin(u_t*-0.43), sin(u_t*-1.1)));"
"d += 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"t = vec2(p - s*vec2(sin(u_t*0.43), sin(u_t*1.1)));"
"d -= 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"d = clamp(pow(d, 2.3), 0.0, 2.0);"
"c = vec4(mix(vec3(0.1,0.2,0.4), vec3(0.9,0.7,0.2), d), 1);"
;
PlotFS.Run(sFS);
#+end_src
#+results:
: 717 frames rendered.
#+begin_src tks :cmd-line "-ep lib:plot-fs" :results file link :file "myfs1.png"
String sFS <= "vec2 t; float d = 0; float s = 0.6;"
"t = vec2(p - s*vec2(sin(u_t*1.31), sin(u_t*1.7)));"
"d += 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"t = vec2(p - s*vec2(sin(u_t*-0.93), sin(u_t*1.9)));"
"d -= 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"t = vec2(p - s*vec2(sin(u_t*-0.43), sin(u_t*-1.1)));"
"d += 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"t = vec2(p - s*vec2(sin(u_t*0.43), sin(u_t*1.1)));"
"d -= 1.0 - clamp(sqrt(t.x*t.x + t.y*t.y), 0.0, 1.0);"
"d = clamp(pow(d, 2.3), 0.0, 2.0);"
"c = vec4(mix(vec3(0.95,0.97,0.984), vec3(0.3,0.43,0.8), d), 1);"
;
PlotFS.SetT(911.11); PlotFS.SetSize(640, 240);
if 0 PlotFS.Run(sFS); else PlotFS.SavePNG("myfs1.png", sFS);
#+end_src
#+RESULTS:
#+begin_src tks :cmd-line "-ep lib:plot-fs" :results output replace :eval yes
String sFS <= "c = vec4(u_r + u_r*sin(u_t+sin(p.x*M_2PI*0.4 * p.y))*u_scl1, "
"u_g + u_g*sin(u_t*1.3 + sin( ((p.x*0.5)+(p.y*0.6))*M_2PI*0.5)*0.2)*u_scl2, "
"u_b+u_b*sin(u_t*p.x*1.1)*sin(u_t*1.23*p.y)*u_scl3, 1);"
;
PlotFS.SetT(122.3); PlotFS.SetSize(640, 240);
PlotFS.AddCtl("r", 0.5);
PlotFS.AddCtl("g", 0.6);
PlotFS.AddCtl("b", 0.7);
PlotFS.AddCtl("scl1", 0.05);
PlotFS.AddCtl("scl2", 0.1);
PlotFS.AddCtl("scl3", 0.7);
PlotFS.SetPNGOutput("myfs2.png", 1);
PlotFS.Run(sFS);
#+end_src
#+results:
#+begin_example
[dbg] UI.SaveScreenShotPNG: pathName="myfs2.png" off=(0,0) s=(640,460)
[...] Texture::saveImage("myfs2.png")
[...] exportPNG: wrote "myfs2.png"
PlotsFS.AddCtl("r", 0.331794);
PlotsFS.AddCtl("g", 0.658487);
PlotsFS.AddCtl("b", 0.585004);
PlotsFS.AddCtl("scl1", 0.135862);
PlotsFS.AddCtl("scl2", 0.73644);
PlotsFS.AddCtl("scl3", 0.829068);
582 frames rendered.
#+end_example
* Link test
** TODO move to another document
*** some section
an anchor that the link below refers to
*** links
M-x org-store-link
C-c C-L : insert link (C-u C-c C-L inserts file link)
C-c C-l : edit link
C-c C-o : open link
file:~/tmp/t.txt]]
link to some section
* Notes
** COMMENT use ":results output discard" to quietly ignore stdout messages
** COMMENT ":eval query" forces confirmation
** COMMENT M-x org-toggle-inline-images
** COMMENT M-x htmlize-buffer