From 9e0606f1d6ee725bb656f66a2db0c346895f75e5 Mon Sep 17 00:00:00 2001 From: kravohi Date: Tue, 26 Mar 2024 10:58:05 -0600 Subject: [PATCH] added the sqrt() function and a triginomitry guide --- guides/trigonometry.json | 2 ++ math/sin.json | 30 ++----------------------- math/sqrt.json | 2 ++ topics/guides.json | 2 ++ topics/math.json | 47 ++-------------------------------------- 5 files changed, 10 insertions(+), 73 deletions(-) create mode 100644 guides/trigonometry.json create mode 100644 math/sqrt.json create mode 100644 topics/guides.json diff --git a/guides/trigonometry.json b/guides/trigonometry.json new file mode 100644 index 0000000..35ba074 --- /dev/null +++ b/guides/trigonometry.json @@ -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"}]} \ No newline at end of file diff --git a/math/sin.json b/math/sin.json index d62e569..3626f97 100644 --- a/math/sin.json +++ b/math/sin.json @@ -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."}]} \ No newline at end of file diff --git a/math/sqrt.json b/math/sqrt.json new file mode 100644 index 0000000..62fc100 --- /dev/null +++ b/math/sqrt.json @@ -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()"}} \ No newline at end of file diff --git a/topics/guides.json b/topics/guides.json new file mode 100644 index 0000000..c3f3a63 --- /dev/null +++ b/topics/guides.json @@ -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"}} \ No newline at end of file diff --git a/topics/math.json b/topics/math.json index 4d1053f..2cda064 100644 --- a/topics/math.json +++ b/topics/math.json @@ -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"}]} \ No newline at end of file