Skip to content

Commit

Permalink
added the sqrt() function and a triginomitry guide
Browse files Browse the repository at this point in the history
  • Loading branch information
church-basement committed Mar 26, 2024
1 parent c81785d commit 9e0606f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 73 deletions.
2 changes: 2 additions & 0 deletions guides/trigonometry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--[[pod_format="raw",created="2024-03-26 15:47:39",modified="2024-03-26 16:55:47",revision=31]]
{"metadata":{"authors":["kravohi"],"version":"0.4","page_title":"Trigonometry in Picotron"},"elements":[{"text":"This is a demo showing some usefull \ntrigonometic relations and how they \ncan be implemented in picotron.\nScroll to the bottom of this page \nand press \"Run Demo\" to see these\nrelations in action.","type":"label"},{"text":"zoom = 40\noffset = -60\nfunction _draw()\n\tcls()\n\tpoke(0x4000, get(fetch(\"/system/fonts/p8.font\")))\n\tcamera(offset,offset)\n\tmx, my = mouse()\r\n\tmx += offset\n\tmy += offset\n\t\n\t-- Draw unit circle.\n\tcirc(0,0,zoom,1)\n\tlocal label_count = 8\r\n \tfor ai=1, label_count do\r\n \t\tlocal a = (ai/label_count) % 1\r\n \t\tprint(\r\n \t\t\ta, \r\n \t\t\tcos(a)*(zoom+5)-9, \r\n \t\t\tsin(a)*(zoom+5)-3,\r\n \t\t\t5\r\n \t\t)\r\n \t\tprint(\r\n \t\t\ta-1, \r\n \t\t\tcos(a)*(zoom+5)-9, \r\n \t\t\tsin(a)*(zoom+5)+3,\r\n \t\t\t5\r\n \t\t)\r\n \tend\t\n \tprint(\"+x\",zoom+15,0,26)\n \tprint(\"-x\",-zoom-15,0,26)\n \tprint(\"+y\",0,zoom+15,12)\r\n \tprint(\"-y\",0,-zoom-15,12)\n\n \t-- Draw cos() and sin()\n \tlocal angle = atan2(mx,my)\n \tlocal cos_x = cos(angle) * zoom\n \tlocal sin_y = sin(angle) * zoom\n \tline(0,sin_y,cos_x,sin_y,1)\r\n \tline(cos_x,0,cos_x,sin_y,1)\n \tline(0,0,0,sin_y,12)\n \tline(0,0,cos_x,0,26)\n \t\n \t-- Draw mouse\n \tcirc(mx,my,4,18)\r\n \tline(0,0,mx,my,18)\n \t\n \t-- Draw normalized vector\n \tlocal dist = sqrt(mx*mx + my*my)\n \tline(0,0,mx/dist*zoom,my/dist*zoom,8)\r\t\n \t\n \t-- Draw the values\n \tlocal x = -offset+30\n \tlocal y = offset\n \tprint(\"distance: \"..dist/zoom,x,y,18)\n \ty += 8\n \tprint(\"angle = atan2(mouse_x, mouse_y)\",x,y,6)\r\n \ty += 8\n \tprint(\"angle: \"..angle,x,y,6)\r\n \ty += 8\n\tprint(\"cos(angle): \"..cos(angle),x,y,26)\n\ty += 8\n\tprint(\"sin(angle): \"..sin(angle),x,y,12)\n\ty += 8\r\n\tprint(\"normalized_mx = mouse_x / distance\",x,y,8)\r\n\ty += 8\r\n\tprint(\"normalized_my = mouse_y / distance\",x,y,8)\n\ty += 8\r\n\tprint(\"normalized_mx = cos(angle)\",x,y,8)\r\n\ty += 8\r\n\tprint(\"normalized_my = sin(angle)\",x,y,8)\r\n\ty += 8\r\n\tprint(\"normalized_mx:\"..mx/dist,x,y,8)\r\n\ty += 8\r\n\tprint(\"normalized_my:\"..my/dist,x,y,8)\nend","type":"demo"}]}
30 changes: 2 additions & 28 deletions math/sin.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,2 @@
{
"metadata" : {
"page_title" : "sin()",
"version" : "0.2",
"authors" : [
"kravohi",
"Hessery"
]
},
"elements" : [
{
"type" : "snippet",
"text" : "sin(\n x -- angle\n)"
},
{
"type" : "label",
"text" : "From a given angle, the sin() function returns\nthe inverted value of what a classical sine\nfunction would give. Angles in picotron are\nmessured as a range of 0.0-1.0 counter-clockwize\naround a unit circle. (0.0 being to the right)"
},
{
"type" : "label",
"text" : "sin(0.0) = 0.0\nsin(0.125) = -0.7071...\nsin(0.25) = -1.0\nsin(0.375) = -0.7071...\nsin(0.5) = 0.0\nsin(0.625) = 0.7071...\nsin(0.75) = 1.0\nsin(0.875) = 0.7071..."
},
{
"type" : "label",
"text" : "The invertion of the classical sine is usefull\nsince picotron uses inverted screen coordinates.\n(0, 0) being the top left.\n(480, 270) being bottom right."
}
]
}
--[[pod_format="raw",created="2024-03-26 15:01:10",modified="2024-03-26 15:01:10",revision=0]]
{"metadata":{"authors":["kravohi","Hessery"],"page_title":"sin()","version":"0.2"},"elements":[{"type":"snippet","text":"sin(\n x -- angle\n)"},{"type":"label","text":"From a given angle, the sin() function returns\nthe inverted value of what a classical sine\nfunction would give. Angles in picotron are\nmessured as a range of 0.0-1.0 counter-clockwize\naround a unit circle. (0.0 being to the right)"},{"type":"label","text":"sin(0.0) = 0.0\nsin(0.125) = -0.7071...\nsin(0.25) = -1.0\nsin(0.375) = -0.7071...\nsin(0.5) = 0.0\nsin(0.625) = 0.7071...\nsin(0.75) = 1.0\nsin(0.875) = 0.7071..."},{"type":"label","text":"The invertion of the classical sine is usefull\nsince picotron uses inverted screen coordinates.\n(0, 0) being the top left.\n(480, 270) being bottom right."}]}
2 changes: 2 additions & 0 deletions math/sqrt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--[[pod_format="raw",created="2024-03-26 15:03:41",modified="2024-03-26 15:09:06",revision=5]]
{"elements":[{"type":"snippet","text":"sqrt(\n x -- any positive number\n)"},{"type":"label","text":"Returns the square root of any positive\nnumber."},{"type":"warning","text":"If 'x' is negative, this function\nwill return the value 'nan'!"},{"type":"label","text":"Here is a mathmatical equivalency.\nz = sqrt(z * z)"}],"metadata":{"authors":["kravohi"],"version":"0.4","page_title":"sqrt()"}}
2 changes: 2 additions & 0 deletions topics/guides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--[[pod_format="raw",created="2024-03-26 15:37:42",modified="2024-03-26 15:48:24",revision=4]]
{"elements":[{"type":"label","text":"Here are our current documents:"},{"text":"Trigonometry in Picotron","ref":"guides/trigonometry","type":"wiki_ref"}],"metadata":{"authors":["kravohi"],"page_title":"Guides","version":"0.4"}}
47 changes: 2 additions & 45 deletions topics/math.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,2 @@
{
"metadata" : {
"page_title" : "Math",
"version" : "0.2",
"authors" : [
"kravohi"
]
},
"elements" : [
{
"type" : "label",
"text" : "Here are our current documents:"
},
{
"type" : "wiki_ref",
"ref" : "math/atan2",
"text" : "atan2()"
},
{
"type" : "wiki_ref",
"ref" : "math/cos",
"text" : "cos()"
},
{
"type" : "wiki_ref",
"ref" : "math/max",
"text" : "max()"
},
{
"type" : "wiki_ref",
"ref" : "math/min",
"text" : "min()"
},
{
"type": "wiki_ref",
"ref": "math/mid",
"text": "mid()"
},
{
"type" : "wiki_ref",
"ref" : "math/sin",
"text" : "sin()"
}
]
}
--[[pod_format="raw",created="2024-03-26 15:37:42",modified="2024-03-26 15:38:03",revision=1]]
{"metadata":{"page_title":"Math","authors":["kravohi"],"version":"0.2"},"elements":[{"type":"label","text":"Here are our current documents:"},{"text":"atan2()","type":"wiki_ref","ref":"math/atan2"},{"text":"cos()","type":"wiki_ref","ref":"math/cos"},{"text":"max()","type":"wiki_ref","ref":"math/max"},{"text":"min()","type":"wiki_ref","ref":"math/min"},{"text":"mid()","type":"wiki_ref","ref":"math/mid"},{"text":"sin()","type":"wiki_ref","ref":"math/sin"},{"text":"sqrt()","type":"wiki_ref","ref":"math/sqrt"}]}

0 comments on commit 9e0606f

Please sign in to comment.