diff --git a/.vscode/settings.json b/.vscode/settings.json index b5601daaa..c71a2653d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,62 @@ { "files.associations": { "*.mdx": "markdown" - } + }, + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false } \ No newline at end of file diff --git a/astro.config.mjs b/astro.config.mjs index fd5e45b57..a48577aa0 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,154 +1,184 @@ -import { defineConfig } from "astro/config"; -import starlight from "@astrojs/starlight"; -// import solidJs from "@astrojs/solid-js"; -import react from "@astrojs/react"; -import starlightLinksValidator from 'starlight-links-validator'; -import sitemap from "@astrojs/sitemap"; -import remarkMath from 'remark-math'; -import rehypeMathjax from 'rehype-mathjax' -import starlightBlog from 'starlight-blog' -import starlightDocSearch from '@astrojs/starlight-docsearch'; -import remarkHeadingID from 'remark-heading-id'; -import { loadEnv } from "vite"; - -const { DOCSEARCH_API_ID } = loadEnv(process.env.DOCSEARCH_API_ID, process.cwd(), ""); -const { DOCSEARCH_API_SEARCH_KEY } = loadEnv(process.env.DOCSEARCH_API_SEARCH_KEY, process.cwd(), ""); -const { DOCSEARCH_INDEX_NAME } = loadEnv(process.env.DOCSEARCH_INDEX_NAME, process.cwd(), ""); - -if (!DOCSEARCH_API_ID || !DOCSEARCH_API_SEARCH_KEY || !DOCSEARCH_INDEX_NAME) { - console.error("Algolia DocSearch enviroment variables are invalid. Please check configuration!"); - process.exit(1); -} - -// https://astro.build/config -export default defineConfig({ - site: 'https://splashkit.io/', - integrations: [ - starlight({ - title: "SplashKit", - description: 'SplashKit is a cross-platform game engine for C, C++ and Objective-C. It provides a simple API for 2D game development.', - plugins: [ - starlightBlog({ - title: 'Announcements', - recentPostCount: 5, - prevNextLinksOrder: 'chronological', - }), - starlightLinksValidator({ - errorOnRelativeLinks: true, - }), - starlightDocSearch({ - appId: DOCSEARCH_API_ID, - apiKey: DOCSEARCH_API_SEARCH_KEY, - indexName: DOCSEARCH_INDEX_NAME, - }), - ], - expressiveCode: { - // theme: ["github-dark", "github-light"], - // frames: { - // showCopyToClipboardButton: true, - // }, - styleOverrides: { borderRadius: '0.5rem' }, - useDarkModeMediaQuery: true, - }, - customCss: [ - "/src/styles/custom.css", - "/src/styles/background.css", - "/src/styles/cards.css", - ], - social: [ - { icon: 'github', label: 'GitHub', href: 'https://github.com/splashkit' }, - { icon: 'youtube', label: 'YouTube', href: 'https://www.youtube.com/@splashkit7674' }, - ], - favicon: "/images/favicon.svg", - logo: { - src: "./src/assets/favicon.svg", - }, - sidebar: [ - { - label: "Installation", - collapsed: false, - items: [ - { label: "Installation Overview", link: "installation/" }, - { - label: "Windows", - collapsed: true, - items: - [ - { label: "MSYS2", autogenerate: { directory: "installation/Windows (MSYS2)" }, collapsed: false }, - { label: "WSL", autogenerate: { directory: "installation/Windows (WSL)" }, collapsed: false }, - ] - }, - { label: "MacOS", autogenerate: { directory: "installation/MacOS" }, collapsed: true }, - { label: "Linux", autogenerate: { directory: "installation/Linux" }, collapsed: true }, - { label: "Virtual Machine", autogenerate: { directory: "installation/Virtual Machine" }, collapsed: true }, - ], - }, - { - label: "Troubleshooting", - collapsed: true, - items: [ - { label: "Troubleshooting Overview", link: "troubleshoot/" }, - { - label: "Windows", - collapsed: true, - items: - [ - { label: "MSYS2", autogenerate: { directory: "troubleshoot/Windows (MSYS2)" }, collapsed: false }, - { label: "WSL", autogenerate: { directory: "troubleshoot/Windows (WSL)" }, collapsed: false }, - ] - }, - { label: "MacOS", autogenerate: { directory: "troubleshoot/MacOS" }, collapsed: true }, - { label: "Linux", autogenerate: { directory: "troubleshoot/Linux" }, collapsed: true }, - ], - // autogenerate: { directory: "troubleshoot", collapsed: true }, - }, - { - label: "API Documentation", - autogenerate: { directory: "api", collapsed: false }, - }, - { - label: "Tutorials and Guides", - collapsed: false, - items: [ - { label: "Overview", link: "guides/" }, - { label: "Using SplashKit", link: "guides/0-using-splashkit" }, - { label: "Animations", autogenerate: { directory: "guides/Animations" }, collapsed: true }, - { label: "Audio", autogenerate: { directory: "guides/Audio" }, collapsed: true }, - { label: "Camera", autogenerate: { directory: "guides/Camera" }, collapsed: true }, - { label: "Color", autogenerate: { directory: "guides/Color" }, collapsed: true }, - { label: "Graphics", autogenerate: { directory: "guides/Graphics" }, collapsed: true }, - { label: "Input", autogenerate: { directory: "guides/Input" }, collapsed: true }, - { label: "Interface", autogenerate: { directory: "guides/Interface" }, collapsed: true }, - { label: "Json", autogenerate: { directory: "guides/JSON" }, collapsed: true }, - { label: "Networking", autogenerate: { directory: "guides/Networking" }, collapsed: true }, - { label: "Physics", badge: 'New', autogenerate: { directory: "guides/Physics" }, collapsed: true }, - { label: "Raspberry GPIO", autogenerate: { directory: "guides/Raspberry-GPIO" }, collapsed: true }, - { label: "Resource Bundles", autogenerate: { directory: "guides/Resource-Bundles" }, collapsed: true }, - { label: "Utilities", autogenerate: { directory: "guides/Utilities" }, collapsed: true }, - ], - // autogenerate: { directory: "guides", collapsed: true }, - }, - { - label: "Beyond SplashKit", - autogenerate: { directory: "beyond-splashkit", collapsed: true }, - badge: "New", - }, - ], - - }), - - react(), - sitemap() - ], - - server: { - host: true, - port: 4321 - }, - - // Render mathematical equations using remark-math and rehype-mathjax - markdown: { - remarkPlugins: [remarkMath, remarkHeadingID], - rehypePlugins: [rehypeMathjax], - }, -}); +import { defineConfig } from "astro/config"; +import starlight from "@astrojs/starlight"; +// import solidJs from "@astrojs/solid-js"; +import react from "@astrojs/react"; +import starlightLinksValidator from 'starlight-links-validator'; +import sitemap from "@astrojs/sitemap"; +import remarkMath from 'remark-math'; +import rehypeMathjax from 'rehype-mathjax' +import starlightBlog from 'starlight-blog' +import starlightDocSearch from '@astrojs/starlight-docsearch'; +import remarkHeadingID from 'remark-heading-id'; +import { loadEnv } from "vite"; + +const { DOCSEARCH_API_ID } = loadEnv(process.env.DOCSEARCH_API_ID, process.cwd(), ""); +const { DOCSEARCH_API_SEARCH_KEY } = loadEnv(process.env.DOCSEARCH_API_SEARCH_KEY, process.cwd(), ""); +const { DOCSEARCH_INDEX_NAME } = loadEnv(process.env.DOCSEARCH_INDEX_NAME, process.cwd(), ""); + +if (!DOCSEARCH_API_ID || !DOCSEARCH_API_SEARCH_KEY || !DOCSEARCH_INDEX_NAME) { + console.error("Algolia DocSearch enviroment variables are invalid. Please check configuration!"); + process.exit(1); +} + +// https://astro.build/config +export default defineConfig({ + site: 'https://splashkit.io/', + integrations: [ + starlight({ + title: "SplashKit", + description: 'SplashKit is a cross-platform game engine for C, C++ and Objective-C. It provides a simple API for 2D game development.', + plugins: [ + starlightBlog({ + title: 'Announcements', + recentPostCount: 5, + prevNextLinksOrder: 'chronological', + }), + starlightLinksValidator({ + errorOnRelativeLinks: true, + }), + starlightDocSearch({ + appId: DOCSEARCH_API_ID, + apiKey: DOCSEARCH_API_SEARCH_KEY, + indexName: DOCSEARCH_INDEX_NAME, + }), + ], + + head: [ + { + tag: 'script', + attrs: { + async: true, + src: `https://www.googletagmanager.com/gtag/js?id=G-6DBXQ3VQ8T`, + }, + }, + { + tag: 'script', + content: ` + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', 'G-6DBXQ3VQ8T'); + `, + }, + ], + + expressiveCode: { + // theme: ["github-dark", "github-light"], + // frames: { + // showCopyToClipboardButton: true, + // }, + styleOverrides: { borderRadius: '0.5rem' }, + useDarkModeMediaQuery: true, + }, + customCss: [ + "/src/styles/custom.css", + "/src/styles/background.css", + "/src/styles/cards.css", + ], + social: [ + { icon: 'github', label: 'GitHub', href: 'https://github.com/splashkit' }, + { icon: 'youtube', label: 'YouTube', href: 'https://www.youtube.com/@splashkit7674' }, + ], + favicon: "/images/favicon.svg", + logo: { + src: "./src/assets/favicon.svg", + }, + sidebar: [ + { + label: "Installation", + collapsed: false, + items: [ + { label: "Installation Overview", link: "installation/" }, + { + label: "Windows", + collapsed: true, + items: + [ + { label: "MSYS2", autogenerate: { directory: "installation/Windows (MSYS2)" }, collapsed: false }, + { label: "WSL", autogenerate: { directory: "installation/Windows (WSL)" }, collapsed: false }, + ] + }, + { label: "MacOS", autogenerate: { directory: "installation/MacOS" }, collapsed: true }, + { label: "Linux", autogenerate: { directory: "installation/Linux" }, collapsed: true }, + { label: "Virtual Machine", autogenerate: { directory: "installation/Virtual Machine" }, collapsed: true }, + ], + }, + { + label: "Troubleshooting", + collapsed: true, + items: [ + { label: "Troubleshooting Overview", link: "troubleshoot/" }, + { + label: "Windows", + collapsed: true, + items: + [ + { label: "MSYS2", autogenerate: { directory: "troubleshoot/Windows (MSYS2)" }, collapsed: false }, + { label: "WSL", autogenerate: { directory: "troubleshoot/Windows (WSL)" }, collapsed: false }, + ] + }, + { label: "MacOS", autogenerate: { directory: "troubleshoot/MacOS" }, collapsed: true }, + { label: "Linux", autogenerate: { directory: "troubleshoot/Linux" }, collapsed: true }, + ], + // autogenerate: { directory: "troubleshoot", collapsed: true }, + }, + { + label: "API Documentation", + autogenerate: { directory: "api", collapsed: false }, + }, + { + label: "Tutorials and Guides", + collapsed: false, + items: [ + { label: "Overview", link: "guides/" }, + { + label: "Getting Started", + collapsed: false, + items: [ + { label: "Drawing with Procedures", link: "guides/graphics/drawing-using-procedures" }, + { label: "Understanding Double Buffering", link: "guides/graphics/double-buffering" }, + { label: "Graphical User Inputs", link: "guides/input/user-inputs-in-graphical-applications" }, + { label: "Loading Resources with Bundles", link: "guides/resources/loading-resources-with-bundles" }, + { label: "Getting Started With Audio", link: "guides/audio/getting-started-with-audio" }, + { label: "Using Animations", link: "guides/animations/using-animations" }, + { label: "SplashKit Camera", link: "guides/input/using-splashkit-camera" }, + { label: "Useful Utilities", link: "guides/utilities/useful-utilities" }, + { label: "Using JSON in SplashKit", link: "guides/json/getting-started-with-json" }, + { label: "SplashKit Colors", link: "guides/color/splashkit-colors" }, + ], + }, + { label: "Raspberry GPIO", autogenerate: { directory: "guides/raspberry-gpio" }, collapsed: true }, + { label: "Physics", autogenerate: { directory: "guides/physics" }, collapsed: true }, + { label: "Interface", autogenerate: { directory: "guides/interface" }, collapsed: true }, + { label: "Networking", autogenerate: { directory: "guides/networking" }, collapsed: true }, + { + label: "Beyond SplashKit", + collapsed: true, + items: [ + { label: "Overview", link: "guides/beyond-splashkit/" }, + { label: "Using SDL2", autogenerate: { directory: "guides/beyond-splashkit/sdl2" }, collapsed: false }, + { label: "Cryptography", autogenerate: { directory: "guides/beyond-splashkit/cryptography" }, collapsed: true }, + { label: "Utilities", autogenerate: { directory: "guides/beyond-splashkit/utilities" }, collapsed: true }, + ], + }, + ], + }, + ], + + }), + + react(), + sitemap() + ], + + server: { + host: true, + port: 4321 + }, + + // Render mathematical equations using remark-math and rehype-mathjax + markdown: { + remarkPlugins: [remarkMath, remarkHeadingID], + rehypePlugins: [rehypeMathjax], + }, +}); diff --git a/package-lock.json b/package-lock.json index ea930c30e..f50c0ac99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@astrojs/sitemap": "^3.1.6", "@astrojs/starlight": "^0.34.2", "@astrojs/starlight-docsearch": "^0.3.0", + "@google-analytics/data": "^4.7.0", "@types/react": "^18.3.2", "@types/react-dom": "^18.3.0", "astro": "^5.5.2", @@ -1665,6 +1666,49 @@ "@expressive-code/core": "^0.41.2" } }, + "node_modules/@google-analytics/data": { + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@google-analytics/data/-/data-4.12.1.tgz", + "integrity": "sha512-LzyrkVrnVUTYTmdmHayOZoroc+YA9GHEUrkSSuiXSmMSNbesuWy/MoTXugC1V7+8PCGqb2eQ1UtVVv/2BCAQYA==", + "license": "Apache-2.0", + "dependencies": { + "google-gax": "^4.0.3" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@grpc/grpc-js": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.13.4.tgz", + "integrity": "sha512-GsFaMXCkMqkKIvwCQjCrwH+GHbPKBjhwo/8ZuUkWHqbI73Kky9I+pQltrlT0+MWpedCoosda53lgjYfyEPgxBg==", + "license": "Apache-2.0", + "dependencies": { + "@grpc/proto-loader": "^0.7.13", + "@js-sdsl/ordered-map": "^4.4.2" + }, + "engines": { + "node": ">=12.10.0" + } + }, + "node_modules/@grpc/proto-loader": { + "version": "0.7.15", + "resolved": "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.15.tgz", + "integrity": "sha512-tMXdRCfYVixjuFK+Hk0Q1s38gV9zDiDJfWL3h1rv4Qc39oILCu1TRTDt7+fGUI8K4G1Fj125Hx/ru3azECWTyQ==", + "license": "Apache-2.0", + "dependencies": { + "lodash.camelcase": "^4.3.0", + "long": "^5.0.0", + "protobufjs": "^7.2.5", + "yargs": "^17.7.2" + }, + "bin": { + "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/@img/sharp-darwin-arm64": { "version": "0.34.1", "resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.34.1.tgz", @@ -2089,6 +2133,16 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@js-sdsl/ordered-map": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/@js-sdsl/ordered-map/-/ordered-map-4.4.2.tgz", + "integrity": "sha512-iUKgm52T8HOE/makSxjqoWhe95ZJA1/G1sYsGev2JDKUSS14KAgg1LHb+Ba+IPow0xflbnSkOsZcO08C7w1gYw==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/js-sdsl" + } + }, "node_modules/@mdx-js/mdx": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@mdx-js/mdx/-/mdx-3.1.0.tgz", @@ -2202,6 +2256,70 @@ "win32" ] }, + "node_modules/@protobufjs/aspromise": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", + "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/base64": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", + "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/codegen": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", + "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/eventemitter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", + "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.1", + "@protobufjs/inquire": "^1.1.0" + } + }, + "node_modules/@protobufjs/float": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", + "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/inquire": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", + "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/path": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", + "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/pool": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", + "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", + "license": "BSD-3-Clause" + }, + "node_modules/@protobufjs/utf8": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", + "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", + "license": "BSD-3-Clause" + }, "node_modules/@rollup/pluginutils": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.4.tgz", @@ -2546,6 +2664,15 @@ "integrity": "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==", "license": "MIT" }, + "node_modules/@tootallnate/once": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", + "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", + "license": "MIT", + "engines": { + "node": ">= 10" + } + }, "node_modules/@types/acorn": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/@types/acorn/-/acorn-4.0.6.tgz", @@ -2596,6 +2723,12 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/caseless": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.5.tgz", + "integrity": "sha512-hWtVTC2q7hc7xZ/RLbxapMvDMgUnDvKvMOpKal4DrMyfGBUfB1oKaZlIRr6mJL+If3bAP6sV/QneGzF6tJjZDg==", + "license": "MIT" + }, "node_modules/@types/cookie": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", @@ -2644,6 +2777,12 @@ "integrity": "sha512-HMwFiRujE5PjrgwHQ25+bsLJgowjGjm5Z8FVSf0N6PwgJrwxH0QxzHYDcKsTfV3wva0vzrpqMTJS2jXPr5BMEQ==", "license": "MIT" }, + "node_modules/@types/long": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/long/-/long-4.0.2.tgz", + "integrity": "sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA==", + "license": "MIT" + }, "node_modules/@types/mathjax": { "version": "0.0.40", "resolved": "https://registry.npmjs.org/@types/mathjax/-/mathjax-0.0.40.tgz", @@ -2714,6 +2853,35 @@ "@types/react": "*" } }, + "node_modules/@types/request": { + "version": "2.48.13", + "resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.13.tgz", + "integrity": "sha512-FGJ6udDNUCjd19pp0Q3iTiDkwhYup7J8hpMW9c4k53NrccQFFWKRho6hvtPPEhnXWKvukfwAlB6DbDz4yhH5Gg==", + "license": "MIT", + "dependencies": { + "@types/caseless": "*", + "@types/node": "*", + "@types/tough-cookie": "*", + "form-data": "^2.5.5" + } + }, + "node_modules/@types/request/node_modules/form-data": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.5.tgz", + "integrity": "sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.35", + "safe-buffer": "^5.2.1" + }, + "engines": { + "node": ">= 0.12" + } + }, "node_modules/@types/sax": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz", @@ -2723,6 +2891,12 @@ "@types/node": "*" } }, + "node_modules/@types/tough-cookie": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz", + "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==", + "license": "MIT" + }, "node_modules/@types/unist": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", @@ -2753,6 +2927,18 @@ "vite": "^4.2.0 || ^5.0.0 || ^6.0.0" } }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "license": "MIT", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, "node_modules/accessible-astro-components": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/accessible-astro-components/-/accessible-astro-components-3.0.1.tgz", @@ -2781,6 +2967,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, "node_modules/algoliasearch": { "version": "5.17.0", "resolved": "https://registry.npmjs.org/algoliasearch/-/algoliasearch-5.17.0.tgz", @@ -3605,6 +3800,26 @@ "integrity": "sha512-kwDPIFCGx0NZHog36dj+tHiwP4QMzsZ3AgMViUBKI0+V5n4U0ufTCUMhnQ04diaRI8EX/QcPfql7zlhZ7j4zgg==", "license": "MIT" }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/bcp-47": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/bcp-47/-/bcp-47-2.1.0.tgz", @@ -3638,6 +3853,15 @@ "require-from-string": "^2.0.2" } }, + "node_modules/bignumber.js": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.1.tgz", + "integrity": "sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/boolbase": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", @@ -3698,6 +3922,25 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/camelcase": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-8.0.0.tgz", @@ -3830,6 +4073,93 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/cliui/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/cliui/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" + }, + "node_modules/cliui/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cliui/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/clsx": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", @@ -3861,24 +4191,11 @@ "node": ">=12.5.0" } }, - "node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" - }, - "node_modules/color-string": { - "version": "1.9.1", - "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", - "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", - "dependencies": { - "color-name": "^1.0.0", - "simple-swizzle": "^0.2.2" - } - }, - "node_modules/color/node_modules/color-convert": { + "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "license": "MIT", "dependencies": { "color-name": "~1.1.4" }, @@ -3886,10 +4203,20 @@ "node": ">=7.0.0" } }, - "node_modules/color/node_modules/color-name": { + "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT" + }, + "node_modules/color-string": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz", + "integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==", + "dependencies": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } }, "node_modules/combined-stream": { "version": "1.0.8", @@ -4179,6 +4506,41 @@ "node": ">=4" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/duplexify": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-4.1.3.tgz", + "integrity": "sha512-M3BmBhwJRZsSx38lZyhE53Csddgzl5R7xGJNk7CVddZD6CcmwMCH8J+7AprIrQKH7TonKxaCjcv27Qmf+sQ+oA==", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.4.1", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1", + "stream-shift": "^1.0.2" + } + }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.149", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.149.tgz", @@ -4197,6 +4559,15 @@ "integrity": "sha512-LRlerrMYoIDrT6jgpeZ2YYl/L8EulRTt5hQcYjy5AInh7HWXKimpqx68aknBFpGL2+/IcogTcaydJEgaTmOpDg==", "license": "MIT" }, + "node_modules/end-of-stream": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", + "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, "node_modules/entities": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", @@ -4208,12 +4579,57 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.6.0.tgz", "integrity": "sha512-qqnD1yMU6tk/jnaMosogGySTZP8YtUgAffA9nMN+E/rjxcfRQ6IEk7IiozUjgxKoFHBGjTLnrHB/YC45r/59EQ==", "license": "MIT" }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/esast-util-from-estree": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/esast-util-from-estree/-/esast-util-from-estree-2.0.0.tgz", @@ -4420,6 +4836,15 @@ "@types/estree": "^1.0.0" } }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/eventemitter3": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", @@ -4524,6 +4949,45 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gaxios": { + "version": "6.7.1", + "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-6.7.1.tgz", + "integrity": "sha512-LDODD4TMYx7XXdpwxAVRAIAuB0bzv0s+ywFonY46k126qzQHT9ygyoa9tncmOiQmmDrik65UYsEkv3lbfqQ3yQ==", + "license": "Apache-2.0", + "dependencies": { + "extend": "^3.0.2", + "https-proxy-agent": "^7.0.1", + "is-stream": "^2.0.0", + "node-fetch": "^2.6.9", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/gcp-metadata": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-6.1.1.tgz", + "integrity": "sha512-a4tiq7E0/5fTjxPAaH4jpjkSv/uCaU2p5KC6HVGrvl0cDjA8iBZv4vv1gyzlmK0ZUKqwpOyQMKzZQe3lTit77A==", + "license": "Apache-2.0", + "dependencies": { + "gaxios": "^6.1.1", + "google-logging-utils": "^0.0.2", + "json-bigint": "^1.0.0" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -4533,6 +4997,15 @@ "node": ">=6.9.0" } }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "license": "ISC", + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, "node_modules/get-east-asian-width": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.3.0.tgz", @@ -4545,6 +5018,43 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/github-slugger": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-2.0.0.tgz", @@ -4559,6 +5069,67 @@ "node": ">=4" } }, + "node_modules/google-auth-library": { + "version": "9.15.1", + "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.15.1.tgz", + "integrity": "sha512-Jb6Z0+nvECVz+2lzSMt9u98UsoakXxA2HGHMCxh+so3n90XgYWkq5dur19JAJV7ONiJY22yBTyJB1TSkvPq9Ng==", + "license": "Apache-2.0", + "dependencies": { + "base64-js": "^1.3.0", + "ecdsa-sig-formatter": "^1.0.11", + "gaxios": "^6.1.1", + "gcp-metadata": "^6.1.0", + "gtoken": "^7.0.0", + "jws": "^4.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/google-gax": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/google-gax/-/google-gax-4.6.1.tgz", + "integrity": "sha512-V6eky/xz2mcKfAd1Ioxyd6nmA61gao3n01C+YeuIwu3vzM9EDR6wcVzMSIbLMDXWeoi9SHYctXuKYC5uJUT3eQ==", + "license": "Apache-2.0", + "dependencies": { + "@grpc/grpc-js": "^1.10.9", + "@grpc/proto-loader": "^0.7.13", + "@types/long": "^4.0.0", + "abort-controller": "^3.0.0", + "duplexify": "^4.0.0", + "google-auth-library": "^9.3.0", + "node-fetch": "^2.7.0", + "object-hash": "^3.0.0", + "proto3-json-serializer": "^2.0.2", + "protobufjs": "^7.3.2", + "retry-request": "^7.0.0", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/google-logging-utils": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-0.0.2.tgz", + "integrity": "sha512-NEgUnEcBiP5HrPzufUkBzJOD/Sxsco3rLNo1F1TNf7ieU8ryUzBhqba8r756CjLX7rn3fHl6iLEwPYuqpoKgQQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/gray-matter": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/gray-matter/-/gray-matter-4.0.3.tgz", @@ -4596,6 +5167,19 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/gtoken": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz", + "integrity": "sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw==", + "license": "MIT", + "dependencies": { + "gaxios": "^6.0.0", + "jws": "^4.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/h3": { "version": "1.15.1", "resolved": "https://registry.npmjs.org/h3/-/h3-1.15.1.tgz", @@ -4613,6 +5197,45 @@ "uncrypto": "^0.1.3" } }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/hast-util-embedded": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/hast-util-embedded/-/hast-util-embedded-3.0.0.tgz", @@ -5043,13 +5666,14 @@ "node": ">= 14" } }, - "node_modules/http-proxy-agent/node_modules/agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", "license": "MIT", "dependencies": { - "debug": "^4.3.4" + "agent-base": "^7.1.2", + "debug": "4" }, "engines": { "node": ">= 14" @@ -5099,6 +5723,12 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, "node_modules/inline-style-parser": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/inline-style-parser/-/inline-style-parser-0.2.4.tgz", @@ -5238,6 +5868,18 @@ "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", "license": "MIT" }, + "node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-wsl": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz", @@ -5310,31 +5952,6 @@ } } }, - "node_modules/jsdom/node_modules/agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", - "license": "MIT", - "dependencies": { - "debug": "^4.3.4" - }, - "engines": { - "node": ">= 14" - } - }, - "node_modules/jsdom/node_modules/https-proxy-agent": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", - "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", - "license": "MIT", - "dependencies": { - "agent-base": "^7.0.2", - "debug": "4" - }, - "engines": { - "node": ">= 14" - } - }, "node_modules/jsdom/node_modules/tr46": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.0.0.tgz", @@ -5381,6 +5998,15 @@ "node": ">=6" } }, + "node_modules/json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "license": "MIT", + "dependencies": { + "bignumber.js": "^9.0.0" + } + }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", @@ -5393,6 +6019,27 @@ "node": ">=6" } }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz", + "integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.0", + "safe-buffer": "^5.0.1" + } + }, "node_modules/katex": { "version": "0.16.21", "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.21.tgz", @@ -5480,6 +6127,18 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, + "node_modules/lodash.camelcase": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", + "integrity": "sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==", + "license": "MIT" + }, + "node_modules/long": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/long/-/long-5.3.2.tgz", + "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", + "license": "Apache-2.0" + }, "node_modules/longest-streak": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz", @@ -5593,6 +6252,15 @@ "marked": ">=4 <16" } }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/mathjax-full": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/mathjax-full/-/mathjax-full-3.2.2.tgz", @@ -6762,6 +7430,26 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-fetch-native": { "version": "1.6.6", "resolved": "https://registry.npmjs.org/node-fetch-native/-/node-fetch-native-1.6.6.tgz", @@ -6801,6 +7489,15 @@ "url": "https://github.com/fb55/nth-check?sponsor=1" } }, + "node_modules/object-hash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", + "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, "node_modules/ofetch": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/ofetch/-/ofetch-1.4.1.tgz", @@ -6812,6 +7509,15 @@ "ufo": "^1.5.4" } }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, "node_modules/oniguruma-parser": { "version": "0.12.1", "resolved": "https://registry.npmjs.org/oniguruma-parser/-/oniguruma-parser-0.12.1.tgz", @@ -7080,6 +7786,42 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/proto3-json-serializer": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/proto3-json-serializer/-/proto3-json-serializer-2.0.2.tgz", + "integrity": "sha512-SAzp/O4Yh02jGdRc+uIrGoe87dkN/XtwxfZ4ZyafJHymd79ozp5VG5nyZ7ygqPM5+cpLDjjGnYFUkngonyDPOQ==", + "license": "Apache-2.0", + "dependencies": { + "protobufjs": "^7.2.5" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/protobufjs": { + "version": "7.5.4", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.5.4.tgz", + "integrity": "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg==", + "hasInstallScript": true, + "license": "BSD-3-Clause", + "dependencies": { + "@protobufjs/aspromise": "^1.1.2", + "@protobufjs/base64": "^1.1.2", + "@protobufjs/codegen": "^2.0.4", + "@protobufjs/eventemitter": "^1.1.0", + "@protobufjs/fetch": "^1.1.0", + "@protobufjs/float": "^1.0.2", + "@protobufjs/inquire": "^1.1.0", + "@protobufjs/path": "^1.1.2", + "@protobufjs/pool": "^1.1.0", + "@protobufjs/utf8": "^1.1.0", + "@types/node": ">=13.7.0", + "long": "^5.0.0" + }, + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", @@ -7139,6 +7881,20 @@ "node": ">=0.10.0" } }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/readdirp": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", @@ -7545,6 +8301,15 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", @@ -7621,6 +8386,20 @@ "url": "https://opencollective.com/unified" } }, + "node_modules/retry-request": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/retry-request/-/retry-request-7.0.2.tgz", + "integrity": "sha512-dUOvLMJ0/JJYEn8NrpOaGNE7X3vpI5XlZS/u0ANjqtcZVKnIxP7IgCFwrKTxENw29emmwug53awKtaMm4i9g5w==", + "license": "MIT", + "dependencies": { + "@types/request": "^2.48.8", + "extend": "^3.0.2", + "teeny-request": "^9.0.0" + }, + "engines": { + "node": ">=14" + } + }, "node_modules/rollup": { "version": "4.35.0", "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.35.0.tgz", @@ -7665,6 +8444,26 @@ "integrity": "sha512-APM0Gt1KoXBz0iIkkdB/kfvGOwC4UuJFeG/c+yV7wSc7q96cG/kJ0HiYCnzivD9SB53cLV1MlHFNfOuPaadYSw==", "license": "MIT" }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -7697,12 +8496,6 @@ "loose-envify": "^1.1.0" } }, - "node_modules/search-insights": { - "version": "2.17.3", - "resolved": "https://registry.npmjs.org/search-insights/-/search-insights-2.17.3.tgz", - "integrity": "sha512-RQPdCYTa8A68uM2jwxoY842xDhvx3E5LFL1LxvxCNMev4o5mLuokczhzjAgGwUZBAmOKZknArSxLKmXtIi2AxQ==", - "peer": true - }, "node_modules/section-matter": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/section-matter/-/section-matter-1.0.0.tgz", @@ -7954,11 +8747,35 @@ "@astrojs/starlight": ">=0.32.0" } }, + "node_modules/stream-events": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/stream-events/-/stream-events-1.0.5.tgz", + "integrity": "sha512-E1GUzBSgvct8Jsb3v2X15pjzN1tYebtbLaMg+eBOUOAxgbLoSbT2NS91ckc5lJD1KfLjId+jXJRgo0qnV5Nerg==", + "license": "MIT", + "dependencies": { + "stubs": "^3.0.0" + } + }, "node_modules/stream-replace-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/stream-replace-string/-/stream-replace-string-2.0.0.tgz", "integrity": "sha512-TlnjJ1C0QrmxRNrON00JvaFFlNh5TTG00APw23j74ET7gkQpTASi6/L2fuiav8pzK715HXtUeClpBTw2NPSn6w==" }, + "node_modules/stream-shift": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/stream-shift/-/stream-shift-1.0.3.tgz", + "integrity": "sha512-76ORR0DO1o1hlKwTbi/DM3EXWGf3ZJYO8cXX5RJwnul2DEg2oyoZyjLNoQM8WsvZiFKCRfC1O0J7iCvie3RZmQ==", + "license": "MIT" + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, "node_modules/string-width": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", @@ -8025,6 +8842,12 @@ ], "license": "MIT" }, + "node_modules/stubs": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/stubs/-/stubs-3.0.0.tgz", + "integrity": "sha512-PdHt7hHUJKxvTCgbKX9C1V/ftOcjJQgz8BZwNfV5c4B6dcGqlpelTbJ999jBGZ2jYiPAwcX5dP6oBwVlBlUbxw==", + "license": "MIT" + }, "node_modules/style-to-js": { "version": "1.1.16", "resolved": "https://registry.npmjs.org/style-to-js/-/style-to-js-1.1.16.tgz", @@ -8068,6 +8891,61 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "license": "MIT" }, + "node_modules/teeny-request": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/teeny-request/-/teeny-request-9.0.0.tgz", + "integrity": "sha512-resvxdc6Mgb7YEThw6G6bExlXKkv6+YbuzGg9xuXxSgxJF7Ozs+o8Y9+2R3sArdWdW8nOokoQb1yrpFB0pQK2g==", + "license": "Apache-2.0", + "dependencies": { + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.0", + "node-fetch": "^2.6.9", + "stream-events": "^1.0.5", + "uuid": "^9.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/teeny-request/node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/teeny-request/node_modules/http-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", + "license": "MIT", + "dependencies": { + "@tootallnate/once": "2", + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/teeny-request/node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/tinyexec": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz", @@ -8105,6 +8983,12 @@ "node": ">=6" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/trim-lines": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/trim-lines/-/trim-lines-3.0.1.tgz", @@ -8163,20 +9047,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/typescript": { - "version": "5.8.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz", - "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==", - "license": "Apache-2.0", - "peer": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/ufo": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.5.4.tgz", @@ -8403,6 +9273,19 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "license": "MIT" }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vfile": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.3.tgz", @@ -8555,6 +9438,12 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, "node_modules/whatwg-encoding": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", @@ -8576,6 +9465,16 @@ "node": ">=18" } }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which-pm-runs": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.1.0.tgz", @@ -8623,6 +9522,12 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, "node_modules/ws": { "version": "8.18.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz", @@ -8674,12 +9579,39 @@ "integrity": "sha512-147y/6YNh+tlp6nd/2pWq38i9h6mz/EuQ6njIrmW8D1BS5nCqs0P6DG+m6zTGnNz5I+uhZ0SHxBs9BsPrwcKDA==", "license": "MIT" }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "license": "ISC", + "engines": { + "node": ">=10" + } + }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", "license": "ISC" }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/yargs-parser": { "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", @@ -8689,6 +9621,47 @@ "node": ">=12" } }, + "node_modules/yargs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" + }, + "node_modules/yargs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/yargs/node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/yocto-queue": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.0.tgz", diff --git a/package.json b/package.json index 1a83bb895..cfeb761c9 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "kleur": "4.1.5", "react": "18.3.1", "react-dom": "18.3.1", - "rehype-mathjax": "^6.0.0", + "rehype-mathjax": "^6.0.0", + "@google-analytics/data": "^4.7.0", "remark-heading-id": "^1.0.1", "remark-math": "^6.0.0", "sharp": "^0.34.1", diff --git a/public/beyond-splashkit/code-files/audio/0-sound-effects/no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/audio/0-sound-effects/no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/audio/0-sound-effects/no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/audio/0-sound-effects/no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/audio/0-sound-effects/with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/audio/0-sound-effects/with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/audio/0-sound-effects/with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/audio/0-sound-effects/with-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-with-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-with-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-with-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-with-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-with-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/utilities/0-integer-input-validation/no-splashkit.cpp b/public/guides/beyond-splashkit/code-files/utilities/0-integer-input-validation/no-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/utilities/0-integer-input-validation/no-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/utilities/0-integer-input-validation/no-splashkit.cpp diff --git a/public/beyond-splashkit/code-files/utilities/0-integer-input-validation/with-splashkit.cpp b/public/guides/beyond-splashkit/code-files/utilities/0-integer-input-validation/with-splashkit.cpp similarity index 100% rename from public/beyond-splashkit/code-files/utilities/0-integer-input-validation/with-splashkit.cpp rename to public/guides/beyond-splashkit/code-files/utilities/0-integer-input-validation/with-splashkit.cpp diff --git a/public/beyond-splashkit/images/cryptography/1-steganography/cat.bmp b/public/guides/beyond-splashkit/images/cryptography/1-steganography/cat.bmp similarity index 100% rename from public/beyond-splashkit/images/cryptography/1-steganography/cat.bmp rename to public/guides/beyond-splashkit/images/cryptography/1-steganography/cat.bmp diff --git a/public/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip b/public/guides/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip similarity index 100% rename from public/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip rename to public/guides/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip diff --git a/public/beyond-splashkit/resources/BeyondSplashKit_SoundEffects_Resources.zip b/public/guides/beyond-splashkit/resources/BeyondSplashKit_SoundEffects_Resources.zip similarity index 100% rename from public/beyond-splashkit/resources/BeyondSplashKit_SoundEffects_Resources.zip rename to public/guides/beyond-splashkit/resources/BeyondSplashKit_SoundEffects_Resources.zip diff --git a/public/images/installation/csharp-in-vscode.png b/public/images/installation/csharp-in-vscode.png index 4c30fead7..31b427d50 100644 Binary files a/public/images/installation/csharp-in-vscode.png and b/public/images/installation/csharp-in-vscode.png differ diff --git a/public/images/installation/python-in-vscode.png b/public/images/installation/python-in-vscode.png index cd14ce538..894c837bb 100644 Binary files a/public/images/installation/python-in-vscode.png and b/public/images/installation/python-in-vscode.png differ diff --git a/public/usage-examples/CONTRIBUTING.mdx b/public/usage-examples/CONTRIBUTING.mdx index a511a0ff8..5dffdbae9 100644 --- a/public/usage-examples/CONTRIBUTING.mdx +++ b/public/usage-examples/CONTRIBUTING.mdx @@ -27,22 +27,15 @@ eg. For the `write_line` examples mentioned below, these would be located in `/p To allow the files to be used to automatically generate the usage example MDX page, you need to follow a specific format when naming your files. -Here is an example of files for two code examples added for the `write_line` function that are demonstrating the use of `void write_line(string line);`: +Here is an example of files for one of the code examples added for the `write_line` function that are demonstrating the use of `void write_line(string line);`: ```plaintext write_line-1-example-oop.cs write_line-1-example-top-level.cs -write_line-1-example-sk.cpp -write_line-1-example-beyond.cpp +write_line-1-example.cpp write_line-1-example.png write_line-1-example.py write_line-1-example.txt -write_line-2-example-oop.cs -write_line-2-example-top-level.cs -write_line-2-example.cpp -write_line-2-example.png -write_line-2-example.py -write_line-2-example.txt ``` Breaking down the first file name from above: @@ -91,14 +84,12 @@ Remove identifying details from the image/gif/audio where possible. Please follow the guidelines below: -- All of the example code needs to be in a single file. - Example code should be able to be run by copying the code into an empty code file. -- Make sure to include 5 code files: - 1. `.cpp` file using SplashKit - 2. `.cpp` file using Beyond SplashKit (without SplashKit) - 3. `.cs` file using top-level statements style - 4. `.cs` file using object-oriented style - 5. `.py` file +- Make sure to include 4 code files: + 1. `.cpp` file + 2. `.cs` file using top-level statements style + 3. `.cs` file using object-oriented style + 4. `.py` file ## Adding Zip File Resources diff --git a/public/usage-examples/animations/0-README.md b/public/usage-examples/animations/0-README.md deleted file mode 100644 index 419295163..000000000 --- a/public/usage-examples/animations/0-README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Files for Usage Examples - -To contribute a function usage example, please read the [CONTRIBUTING file](/public/usage-examples/CONTRIBUTING.mdx) - -Note: You can use 'CTRL + click' (or 'Command + click' on macOS) on the path above for quick access diff --git a/public/usage-examples/audio/play_music_named-1-example-sk.cpp b/public/usage-examples/audio/play_music_named-1-example.cpp similarity index 100% rename from public/usage-examples/audio/play_music_named-1-example-sk.cpp rename to public/usage-examples/audio/play_music_named-1-example.cpp diff --git a/public/usage-examples/audio/resume_music-1-example-sk.cpp b/public/usage-examples/audio/resume_music-1-example.cpp similarity index 100% rename from public/usage-examples/audio/resume_music-1-example-sk.cpp rename to public/usage-examples/audio/resume_music-1-example.cpp diff --git a/public/usage-examples/geometry/closest_point_on_circle-1-example-oop.cs b/public/usage-examples/geometry/closest_point_on_circle-1-example-oop.cs index 30dc0d41a..b555f166a 100644 --- a/public/usage-examples/geometry/closest_point_on_circle-1-example-oop.cs +++ b/public/usage-examples/geometry/closest_point_on_circle-1-example-oop.cs @@ -1,38 +1,38 @@ -using SplashKitSDK; - -namespace ClosestPointOnCircleExample -{ - public class Program - { - public static void Main() - { - SplashKit.OpenWindow("Closest point", 600, 600); - - // Declare variables - Point2D circle_pt = ScreenCenter(); - Circle circle = SplashKit.CircleAt(circle_pt, 100); - Point2D mouse_pt = SplashKit.MousePosition(); - Point2D closest_point; - - while (!SplashKit.QuitRequested()) - { - SplashKit.ProcessEvents(); - - // Get "current" Mouse Position - mouse_pt = SplashKit.MousePosition(); - - // Calculate the closest distance between the current mouse position and the circle - closest_point = SplashKit.ClosestPointOnCircle(mouse_pt, circle); - - // Draw circle and indicated points - SplashKit.ClearScreen(); - SplashKit.DrawCircle(Color.Black, circle); - SplashKit.FillCircle(Color.Red, closest_point.X, closest_point.Y, 5); - SplashKit.FillCircle(Color.Blue, mouse_pt.X, mouse_pt.Y, 5); - SplashKit.RefreshScreen(); - } - - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace ClosestPointOnCircleExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Closest point", 600, 600); + + // Declare variables + Point2D circle_pt = ScreenCenter(); + Circle circle = SplashKit.CircleAt(circle_pt, 100); + Point2D mouse_pt = SplashKit.MousePosition(); + Point2D closest_point; + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Get "current" Mouse Position + mouse_pt = SplashKit.MousePosition(); + + // Calculate the closest distance between the current mouse position and the circle + closest_point = SplashKit.ClosestPointOnCircle(mouse_pt, circle); + + // Draw circle and indicated points + SplashKit.ClearScreen(); + SplashKit.DrawCircle(Color.Black, circle); + SplashKit.FillCircle(Color.Red, closest_point.X, closest_point.Y, 5); + SplashKit.FillCircle(Color.Blue, mouse_pt.X, mouse_pt.Y, 5); + SplashKit.RefreshScreen(); + } + + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/closest_point_on_circle-1-example-top-level.cs b/public/usage-examples/geometry/closest_point_on_circle-1-example-top-level.cs index 67cc18dee..befd4b6fb 100644 --- a/public/usage-examples/geometry/closest_point_on_circle-1-example-top-level.cs +++ b/public/usage-examples/geometry/closest_point_on_circle-1-example-top-level.cs @@ -1,30 +1,30 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -OpenWindow("Closest point", 600, 600); - -// Declare variables -Point2D circle_pt = ScreenCenter(); -Circle circle = CircleAt(circle_pt, 100); -Point2D mouse_pt = MousePosition(); -Point2D closest_point; - -while (!QuitRequested()) -{ - ProcessEvents(); - - // Get "current" Mouse Position - mouse_pt = MousePosition(); - - // Calculate the closest distance between the current mouse position and the circle - closest_point = ClosestPointOnCircle(mouse_pt, circle); - - // Draw circle and indicated points - ClearScreen(); - DrawCircle(ColorBlack(), circle); - FillCircle(ColorRed(), closest_point.X, closest_point.Y, 5); - FillCircle(ColorBlue(), mouse_pt.X, mouse_pt.Y, 5); - RefreshScreen(); -} - +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Closest point", 600, 600); + +// Declare variables +Point2D circle_pt = ScreenCenter(); +Circle circle = CircleAt(circle_pt, 100); +Point2D mouse_pt = MousePosition(); +Point2D closest_point; + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Get "current" Mouse Position + mouse_pt = MousePosition(); + + // Calculate the closest distance between the current mouse position and the circle + closest_point = ClosestPointOnCircle(mouse_pt, circle); + + // Draw circle and indicated points + ClearScreen(); + DrawCircle(ColorBlack(), circle); + FillCircle(ColorRed(), closest_point.X, closest_point.Y, 5); + FillCircle(ColorBlue(), mouse_pt.X, mouse_pt.Y, 5); + RefreshScreen(); +} + CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/point_in_rectangle-1-example-oop.cs b/public/usage-examples/geometry/point_in_rectangle-1-example-oop.cs index e7f31413f..8daabbd1e 100644 --- a/public/usage-examples/geometry/point_in_rectangle-1-example-oop.cs +++ b/public/usage-examples/geometry/point_in_rectangle-1-example-oop.cs @@ -1,65 +1,65 @@ -using SplashKitSDK; - -namespace PointInRectangleExample -{ - public class Program - { - public static void Main() - { - // Variable Declarations - Point2D mousePt; - Rectangle boundary = SplashKit.RectangleFrom(150, 150, 300, 100); - string text; - Color color1; - Color color2; - SplashKitSDK.Timer flashingTimer = SplashKit.CreateTimer("flash time"); - - SplashKit.OpenWindow("Cursor Jail", 600, 600); - flashingTimer.Start(); - - while (!SplashKit.QuitRequested()) - { - SplashKit.ProcessEvents(); - - // Get mouse position - mousePt = SplashKit.MousePosition(); - - // Check if mouse is in the boundary - if (SplashKit.PointInRectangle(mousePt, boundary)) - { - text = ""; - color1 = Color.Green; - color2 = Color.Green; - flashingTimer.Reset(); - } - else - { - // Flash screen red and blue if mouse has escaped boundary - text = "JAILBREAK"; - color1 = Color.RoyalBlue; - color2 = Color.DarkRed; - } - - // Draw UI using timer ticks - if (flashingTimer.Ticks < 500) - { - SplashKit.ClearScreen(color1); - SplashKit.FillRectangle(Color.White, boundary); - SplashKit.RefreshScreen(); - } - if (flashingTimer.Ticks >= 500 && flashingTimer.Ticks < 1000) - { - SplashKit.ClearScreen(color2); - SplashKit.FillRectangle(Color.White, boundary); - SplashKit.DrawText(text, Color.Black, 250, 400); - SplashKit.RefreshScreen(); - } - if (flashingTimer.Ticks >= 1000) - { - flashingTimer.Reset(); - } - } - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace PointInRectangleExample +{ + public class Program + { + public static void Main() + { + // Variable Declarations + Point2D mousePt; + Rectangle boundary = SplashKit.RectangleFrom(150, 150, 300, 100); + string text; + Color color1; + Color color2; + SplashKitSDK.Timer flashingTimer = SplashKit.CreateTimer("flash time"); + + SplashKit.OpenWindow("Cursor Jail", 600, 600); + flashingTimer.Start(); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Get mouse position + mousePt = SplashKit.MousePosition(); + + // Check if mouse is in the boundary + if (SplashKit.PointInRectangle(mousePt, boundary)) + { + text = ""; + color1 = Color.Green; + color2 = Color.Green; + flashingTimer.Reset(); + } + else + { + // Flash screen red and blue if mouse has escaped boundary + text = "JAILBREAK"; + color1 = Color.RoyalBlue; + color2 = Color.DarkRed; + } + + // Draw UI using timer ticks + if (flashingTimer.Ticks < 500) + { + SplashKit.ClearScreen(color1); + SplashKit.FillRectangle(Color.White, boundary); + SplashKit.RefreshScreen(); + } + if (flashingTimer.Ticks >= 500 && flashingTimer.Ticks < 1000) + { + SplashKit.ClearScreen(color2); + SplashKit.FillRectangle(Color.White, boundary); + SplashKit.DrawText(text, Color.Black, 250, 400); + SplashKit.RefreshScreen(); + } + if (flashingTimer.Ticks >= 1000) + { + flashingTimer.Reset(); + } + } + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/point_in_rectangle-1-example-top-level.cs b/public/usage-examples/geometry/point_in_rectangle-1-example-top-level.cs index 2eef8ecb5..bd0207ea7 100644 --- a/public/usage-examples/geometry/point_in_rectangle-1-example-top-level.cs +++ b/public/usage-examples/geometry/point_in_rectangle-1-example-top-level.cs @@ -1,56 +1,56 @@ -using static SplashKitSDK.SplashKit; - -// Variable Declarations -SplashKitSDK.Point2D mousePt; -SplashKitSDK.Rectangle boundary = RectangleFrom(150, 150, 300, 100); -string text; -SplashKitSDK.Color color1; -SplashKitSDK.Color color2; -SplashKitSDK.Timer flashingTimer = CreateTimer("flash time"); - -OpenWindow("Cursor Jail", 600, 600); -StartTimer(flashingTimer); - -while (!QuitRequested()) -{ - ProcessEvents(); - - // Get mouse position - mousePt = MousePosition(); - - // Check if mouse is in the boundary - if (PointInRectangle(mousePt, boundary)) - { - text = ""; - color1 = ColorGreen(); - color2 = ColorGreen(); - ResetTimer(flashingTimer); - } - else - { - // Flash screen red and blue if mouse has escaped boundary - text = "JAILBREAK"; - color1 = ColorRoyalBlue(); - color2 = ColorDarkRed(); - } - - // Draw UI using timer ticks - if (TimerTicks(flashingTimer) < 500) - { - ClearScreen(color1); - FillRectangle(ColorWhite(), boundary); - RefreshScreen(); - } - if (TimerTicks(flashingTimer) >= 500 && TimerTicks(flashingTimer) < 1000) - { - ClearScreen(color2); - FillRectangle(ColorWhite(), boundary); - DrawText(text, ColorBlack(), 250, 400); - RefreshScreen(); - } - if (TimerTicks(flashingTimer) >= 1000) - { - ResetTimer(flashingTimer); - } -} +using static SplashKitSDK.SplashKit; + +// Variable Declarations +SplashKitSDK.Point2D mousePt; +SplashKitSDK.Rectangle boundary = RectangleFrom(150, 150, 300, 100); +string text; +SplashKitSDK.Color color1; +SplashKitSDK.Color color2; +SplashKitSDK.Timer flashingTimer = CreateTimer("flash time"); + +OpenWindow("Cursor Jail", 600, 600); +StartTimer(flashingTimer); + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Get mouse position + mousePt = MousePosition(); + + // Check if mouse is in the boundary + if (PointInRectangle(mousePt, boundary)) + { + text = ""; + color1 = ColorGreen(); + color2 = ColorGreen(); + ResetTimer(flashingTimer); + } + else + { + // Flash screen red and blue if mouse has escaped boundary + text = "JAILBREAK"; + color1 = ColorRoyalBlue(); + color2 = ColorDarkRed(); + } + + // Draw UI using timer ticks + if (TimerTicks(flashingTimer) < 500) + { + ClearScreen(color1); + FillRectangle(ColorWhite(), boundary); + RefreshScreen(); + } + if (TimerTicks(flashingTimer) >= 500 && TimerTicks(flashingTimer) < 1000) + { + ClearScreen(color2); + FillRectangle(ColorWhite(), boundary); + DrawText(text, ColorBlack(), 250, 400); + RefreshScreen(); + } + if (TimerTicks(flashingTimer) >= 1000) + { + ResetTimer(flashingTimer); + } +} CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/point_on_line-1-example-oop.cs b/public/usage-examples/geometry/point_on_line-1-example-oop.cs index 9eff6f9ba..87762f9df 100644 --- a/public/usage-examples/geometry/point_on_line-1-example-oop.cs +++ b/public/usage-examples/geometry/point_on_line-1-example-oop.cs @@ -1,34 +1,34 @@ -using SplashKitSDK; - -namespace PointOnLineExample -{ - public class Program - { - public static void Main() - { - // Variable Declarations - Line line = SplashKit.LineFrom(100, 300, 500, 300); - - // Create window - Window window = new Window("Select Point", 600, 600); - - while (!SplashKit.QuitRequested()) - { - // Display line - window.Clear(Color.White); - window.DrawLine(Color.Black, line); - - // Draw text if cursor is on line - if (SplashKit.PointOnLine(SplashKit.MousePosition(), line)) - { - window.DrawText("Point on line: " + SplashKit.PointToString(SplashKit.MousePosition()), Color.Black, 200, 450); - } - - window.Refresh(); - SplashKit.ProcessEvents(); - } - - window.Close(); - } - } +using SplashKitSDK; + +namespace PointOnLineExample +{ + public class Program + { + public static void Main() + { + // Variable Declarations + Line line = SplashKit.LineFrom(100, 300, 500, 300); + + // Create window + Window window = new Window("Select Point", 600, 600); + + while (!SplashKit.QuitRequested()) + { + // Display line + window.Clear(Color.White); + window.DrawLine(Color.Black, line); + + // Draw text if cursor is on line + if (SplashKit.PointOnLine(SplashKit.MousePosition(), line)) + { + window.DrawText("Point on line: " + SplashKit.PointToString(SplashKit.MousePosition()), Color.Black, 200, 450); + } + + window.Refresh(); + SplashKit.ProcessEvents(); + } + + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/point_on_line-1-example-top-level.cs b/public/usage-examples/geometry/point_on_line-1-example-top-level.cs index 19ef9185d..2151bfc49 100644 --- a/public/usage-examples/geometry/point_on_line-1-example-top-level.cs +++ b/public/usage-examples/geometry/point_on_line-1-example-top-level.cs @@ -1,25 +1,25 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Variable Declarations -Line line = LineFrom(100, 300, 500, 300); - -// Create window -Window window = OpenWindow("Select Point", 600, 600); - -while (!QuitRequested()) -{ - // Display line - ClearScreen(ColorWhite()); - DrawLine(ColorBlack(), line); - - // Draw text if cursor is on line - if (PointOnLine(MousePosition(), line)) - { - DrawText("Point on line: " + PointToString(MousePosition()), ColorBlack(), 200, 450); - } - - RefreshScreen(); - ProcessEvents(); -} +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Variable Declarations +Line line = LineFrom(100, 300, 500, 300); + +// Create window +Window window = OpenWindow("Select Point", 600, 600); + +while (!QuitRequested()) +{ + // Display line + ClearScreen(ColorWhite()); + DrawLine(ColorBlack(), line); + + // Draw text if cursor is on line + if (PointOnLine(MousePosition(), line)) + { + DrawText("Point on line: " + PointToString(MousePosition()), ColorBlack(), 200, 450); + } + + RefreshScreen(); + ProcessEvents(); +} CloseWindow(window); \ No newline at end of file diff --git a/public/usage-examples/geometry/point_on_line-2-example-oop.cs b/public/usage-examples/geometry/point_on_line-2-example-oop.cs index 81c541cc5..e969e280f 100644 --- a/public/usage-examples/geometry/point_on_line-2-example-oop.cs +++ b/public/usage-examples/geometry/point_on_line-2-example-oop.cs @@ -1,52 +1,52 @@ -using SplashKitSDK; - -namespace PointOnLineExample -{ - public class Program - { - public static void Main() - { - // Variable Declarations - double barX = 100; - Line slider = SplashKit.LineFrom(100, 300, 500, 300); - Line bar = SplashKit.LineFrom(barX, 310, barX, 290); - int percent = 0; - bool barSelected = false; - - Window window = new Window("Volume Slider", 600, 600); - - while (!SplashKit.QuitRequested()) - { - SplashKit.ProcessEvents(); - - // Check if user has clicked on the bar Line - if (SplashKit.MouseDown(MouseButton.LeftButton) && SplashKit.PointOnLine(SplashKit.MousePosition(), bar)) - { - barSelected = true; - } - - // Check if user has released mouse button - if (SplashKit.MouseUp(MouseButton.LeftButton)) - { - barSelected = false; - } - - // Update bar location - if (barSelected && SplashKit.MouseX() >= 100 && SplashKit.MouseX() <= 500) - { - barX = SplashKit.MouseX(); // sets barX value to mouse X value - percent = (int)((barX - 100) / (500 - 100) * 100); // convert barX position to percent value - bar = SplashKit.LineFrom(barX, 310, barX, 290); - } - - // Draw Lines and volume text - window.Clear(Color.White); - window.DrawLine(Color.Black, bar); - window.DrawLine(Color.Black, slider); - window.DrawText($"Volume: {percent} %", Color.Black, 200, 450); - window.Refresh(); - } - window.Close(); - } - } +using SplashKitSDK; + +namespace PointOnLineExample +{ + public class Program + { + public static void Main() + { + // Variable Declarations + double barX = 100; + Line slider = SplashKit.LineFrom(100, 300, 500, 300); + Line bar = SplashKit.LineFrom(barX, 310, barX, 290); + int percent = 0; + bool barSelected = false; + + Window window = new Window("Volume Slider", 600, 600); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Check if user has clicked on the bar Line + if (SplashKit.MouseDown(MouseButton.LeftButton) && SplashKit.PointOnLine(SplashKit.MousePosition(), bar)) + { + barSelected = true; + } + + // Check if user has released mouse button + if (SplashKit.MouseUp(MouseButton.LeftButton)) + { + barSelected = false; + } + + // Update bar location + if (barSelected && SplashKit.MouseX() >= 100 && SplashKit.MouseX() <= 500) + { + barX = SplashKit.MouseX(); // sets barX value to mouse X value + percent = (int)((barX - 100) / (500 - 100) * 100); // convert barX position to percent value + bar = SplashKit.LineFrom(barX, 310, barX, 290); + } + + // Draw Lines and volume text + window.Clear(Color.White); + window.DrawLine(Color.Black, bar); + window.DrawLine(Color.Black, slider); + window.DrawText($"Volume: {percent} %", Color.Black, 200, 450); + window.Refresh(); + } + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/point_on_line-2-example-top-level.cs b/public/usage-examples/geometry/point_on_line-2-example-top-level.cs index 4841be9ea..1e70326bb 100644 --- a/public/usage-examples/geometry/point_on_line-2-example-top-level.cs +++ b/public/usage-examples/geometry/point_on_line-2-example-top-level.cs @@ -1,44 +1,44 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Variable Declarations -double barX = 100; -Line slider = LineFrom(100, 300, 500, 300); -Line bar = LineFrom(barX, 310, barX, 290); -int percent = 0; -bool barSelected = false; - -Window window = OpenWindow("Volume Slider", 600, 600); - -while (!QuitRequested()) -{ - ProcessEvents(); - - // Check if user has clicked on the bar Line - if (MouseDown(MouseButton.LeftButton) && PointOnLine(MousePosition(), bar)) - { - barSelected = true; - } - - // Check if user has released mouse button - if (MouseUp(MouseButton.LeftButton)) - { - barSelected = false; - } - - // Update bar location - if (barSelected && MouseX() >= 100 && MouseX() <= 500) - { - barX = MouseX(); // sets barX value to mouse X value - percent = (int)((barX - 100) / (500 - 100) * 100); // convert barX position to percent value - bar = LineFrom(barX, 310, barX, 290); - } - - // Draw Lines and volume text - ClearScreen(ColorWhite()); - DrawLine(ColorBlack(), bar); - DrawLine(ColorBlack(), slider); - DrawText($"Volume: {percent}", ColorBlack(), 200, 450); - RefreshScreen(); -} +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Variable Declarations +double barX = 100; +Line slider = LineFrom(100, 300, 500, 300); +Line bar = LineFrom(barX, 310, barX, 290); +int percent = 0; +bool barSelected = false; + +Window window = OpenWindow("Volume Slider", 600, 600); + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Check if user has clicked on the bar Line + if (MouseDown(MouseButton.LeftButton) && PointOnLine(MousePosition(), bar)) + { + barSelected = true; + } + + // Check if user has released mouse button + if (MouseUp(MouseButton.LeftButton)) + { + barSelected = false; + } + + // Update bar location + if (barSelected && MouseX() >= 100 && MouseX() <= 500) + { + barX = MouseX(); // sets barX value to mouse X value + percent = (int)((barX - 100) / (500 - 100) * 100); // convert barX position to percent value + bar = LineFrom(barX, 310, barX, 290); + } + + // Draw Lines and volume text + ClearScreen(ColorWhite()); + DrawLine(ColorBlack(), bar); + DrawLine(ColorBlack(), slider); + DrawText($"Volume: {percent}", ColorBlack(), 200, 450); + RefreshScreen(); +} CloseWindow(window); \ No newline at end of file diff --git a/public/usage-examples/geometry/point_point_distance-1-example-oop.cs b/public/usage-examples/geometry/point_point_distance-1-example-oop.cs index ea2304735..196cfb47d 100644 --- a/public/usage-examples/geometry/point_point_distance-1-example-oop.cs +++ b/public/usage-examples/geometry/point_point_distance-1-example-oop.cs @@ -1,38 +1,38 @@ -using SplashKitSDK; - -namespace PointPointDistance -{ - public class Program - { - public static void Main() - { - SplashKit.OpenWindow("Distance From Center", 600, 600); - - // Define the variables - Point2D center_pt = SplashKit.ScreenCenter(); - Point2D mouse_pt; - float pt_pt_distance; - - while (!SplashKit.QuitRequested()) - { - SplashKit.ProcessEvents(); - - // Get "current" Mouse Position - mouse_pt = SplashKit.MousePosition(); - - // Calculate the distance between the center point and the current mouse position - pt_pt_distance = SplashKit.PointPointDistance(center_pt, mouse_pt); - - // Draw line and distance between center of window (filled circle) and mouse point - SplashKit.ClearScreen(); - SplashKit.FillCircle(Color.Red, center_pt.X, center_pt.Y, 5); - SplashKit.DrawLine(Color.Blue, center_pt, mouse_pt); - SplashKit.DrawText(pt_pt_distance.ToString(), Color.Black, mouse_pt.X + 10, mouse_pt.Y - 10); - SplashKit.RefreshScreen(); - } - - // Close all opened windows - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace PointPointDistance +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Distance From Center", 600, 600); + + // Define the variables + Point2D center_pt = SplashKit.ScreenCenter(); + Point2D mouse_pt; + float pt_pt_distance; + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Get "current" Mouse Position + mouse_pt = SplashKit.MousePosition(); + + // Calculate the distance between the center point and the current mouse position + pt_pt_distance = SplashKit.PointPointDistance(center_pt, mouse_pt); + + // Draw line and distance between center of window (filled circle) and mouse point + SplashKit.ClearScreen(); + SplashKit.FillCircle(Color.Red, center_pt.X, center_pt.Y, 5); + SplashKit.DrawLine(Color.Blue, center_pt, mouse_pt); + SplashKit.DrawText(pt_pt_distance.ToString(), Color.Black, mouse_pt.X + 10, mouse_pt.Y - 10); + SplashKit.RefreshScreen(); + } + + // Close all opened windows + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/point_point_distance-1-example-top-level.cs b/public/usage-examples/geometry/point_point_distance-1-example-top-level.cs index d7ab01978..82188ee95 100644 --- a/public/usage-examples/geometry/point_point_distance-1-example-top-level.cs +++ b/public/usage-examples/geometry/point_point_distance-1-example-top-level.cs @@ -1,30 +1,30 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -OpenWindow("Distance From Center", 600, 600); - -// Define the variables -Point2D center_pt = ScreenCenter(); -Point2D mouse_pt; -float pt_pt_distance; - -while (!QuitRequested()) -{ - ProcessEvents(); - - // Get "current" Mouse Position - mouse_pt = MousePosition(); - - // Calculate the distance between the center point and the current mouse position - pt_pt_distance = PointPointDistance(center_pt, mouse_pt); - - // Draw line and distance between center of window (filled circle) and mouse point - ClearScreen(); - FillCircle(ColorRed(), center_pt.X, center_pt.Y, 5); - DrawLine(ColorBlue(), center_pt, mouse_pt); - DrawText(pt_pt_distance.ToString(), ColorBlack(), mouse_pt.X + 10, mouse_pt.Y - 10); - RefreshScreen(); -} - -// Close all opened windows +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Distance From Center", 600, 600); + +// Define the variables +Point2D center_pt = ScreenCenter(); +Point2D mouse_pt; +float pt_pt_distance; + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Get "current" Mouse Position + mouse_pt = MousePosition(); + + // Calculate the distance between the center point and the current mouse position + pt_pt_distance = PointPointDistance(center_pt, mouse_pt); + + // Draw line and distance between center of window (filled circle) and mouse point + ClearScreen(); + FillCircle(ColorRed(), center_pt.X, center_pt.Y, 5); + DrawLine(ColorBlue(), center_pt, mouse_pt); + DrawText(pt_pt_distance.ToString(), ColorBlack(), mouse_pt.X + 10, mouse_pt.Y - 10); + RefreshScreen(); +} + +// Close all opened windows CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/point_to_string-1-example-oop.cs b/public/usage-examples/geometry/point_to_string-1-example-oop.cs index 90ad9207c..1dd18186f 100644 --- a/public/usage-examples/geometry/point_to_string-1-example-oop.cs +++ b/public/usage-examples/geometry/point_to_string-1-example-oop.cs @@ -1,32 +1,32 @@ -using SplashKitSDK; - -namespace PointToStringExample -{ - public class Program - { - public static void Main() - { - string mousePositionText = "Click to see coordinates..."; - - Window window = new Window("Mouse Clicked Location", 600, 600); - - while (!SplashKit.QuitRequested()) - { - SplashKit.ProcessEvents(); - - // Check for mouse click - if (SplashKit.MouseClicked(MouseButton.LeftButton)) - { - mousePositionText = "Mouse clicked at " + SplashKit.PointToString(SplashKit.MousePosition()); - } - - // Print mouse position to screen - window.Clear(Color.GhostWhite); - window.DrawText(mousePositionText, Color.Black, 100, 300); - window.Refresh(); - } - - window.Close(); - } - } +using SplashKitSDK; + +namespace PointToStringExample +{ + public class Program + { + public static void Main() + { + string mousePositionText = "Click to see coordinates..."; + + Window window = new Window("Mouse Clicked Location", 600, 600); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + // Check for mouse click + if (SplashKit.MouseClicked(MouseButton.LeftButton)) + { + mousePositionText = "Mouse clicked at " + SplashKit.PointToString(SplashKit.MousePosition()); + } + + // Print mouse position to screen + window.Clear(Color.GhostWhite); + window.DrawText(mousePositionText, Color.Black, 100, 300); + window.Refresh(); + } + + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/point_to_string-1-example-top-level.cs b/public/usage-examples/geometry/point_to_string-1-example-top-level.cs index a631ae99a..bc348e094 100644 --- a/public/usage-examples/geometry/point_to_string-1-example-top-level.cs +++ b/public/usage-examples/geometry/point_to_string-1-example-top-level.cs @@ -1,24 +1,24 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -string mousePositionText = "Click to see coordinates..."; - -OpenWindow("Mouse Clicked Location", 600, 600); - -while (!QuitRequested()) -{ - ProcessEvents(); - - // Check for mouse click - if (MouseClicked(MouseButton.LeftButton)) - { - mousePositionText = "Mouse clicked at " + PointToString(MousePosition()); - } - - // Print mouse position to screen - ClearScreen(ColorGhostWhite()); - DrawText(mousePositionText, ColorBlack(), 100, 300); - RefreshScreen(); -} - +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +string mousePositionText = "Click to see coordinates..."; + +OpenWindow("Mouse Clicked Location", 600, 600); + +while (!QuitRequested()) +{ + ProcessEvents(); + + // Check for mouse click + if (MouseClicked(MouseButton.LeftButton)) + { + mousePositionText = "Mouse clicked at " + PointToString(MousePosition()); + } + + // Print mouse position to screen + ClearScreen(ColorGhostWhite()); + DrawText(mousePositionText, ColorBlack(), 100, 300); + RefreshScreen(); +} + CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/random_bitmap_point-1-example-oop.cs b/public/usage-examples/geometry/random_bitmap_point-1-example-oop.cs index 892c0a644..415133db5 100644 --- a/public/usage-examples/geometry/random_bitmap_point-1-example-oop.cs +++ b/public/usage-examples/geometry/random_bitmap_point-1-example-oop.cs @@ -1,33 +1,33 @@ -using SplashKitSDK; - -namespace RandomBitmapPointExample -{ - public class Program - { - public static void Main() - { - // Create Window and empty bitmap - Window window = new Window("Random Bitmap Points with Triangles", 600, 600); - Bitmap bmp = new Bitmap("Random Triangles", 600, 600); - - for (int i = 0; i < 10; i++) - { - // Create triangle using random points on bitmap - Triangle triangle = SplashKit.TriangleFrom( - SplashKit.RandomBitmapPoint(bmp), - SplashKit.RandomBitmapPoint(bmp), - SplashKit.RandomBitmapPoint(bmp)); - - bmp.FillTriangle(Color.Random(), triangle); - } - - // Draw the bitmap - window.Clear(Color.WhiteSmoke); - window.DrawBitmap(bmp, 0, 0); - window.Refresh(); - - SplashKit.Delay(5000); - window.Close(); - } - } +using SplashKitSDK; + +namespace RandomBitmapPointExample +{ + public class Program + { + public static void Main() + { + // Create Window and empty bitmap + Window window = new Window("Random Bitmap Points with Triangles", 600, 600); + Bitmap bmp = new Bitmap("Random Triangles", 600, 600); + + for (int i = 0; i < 10; i++) + { + // Create triangle using random points on bitmap + Triangle triangle = SplashKit.TriangleFrom( + SplashKit.RandomBitmapPoint(bmp), + SplashKit.RandomBitmapPoint(bmp), + SplashKit.RandomBitmapPoint(bmp)); + + bmp.FillTriangle(Color.Random(), triangle); + } + + // Draw the bitmap + window.Clear(Color.WhiteSmoke); + window.DrawBitmap(bmp, 0, 0); + window.Refresh(); + + SplashKit.Delay(5000); + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/random_bitmap_point-1-example-top-level.cs b/public/usage-examples/geometry/random_bitmap_point-1-example-top-level.cs index 5f6986336..b4dde4017 100644 --- a/public/usage-examples/geometry/random_bitmap_point-1-example-top-level.cs +++ b/public/usage-examples/geometry/random_bitmap_point-1-example-top-level.cs @@ -1,25 +1,25 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create Window and empty bitmap -OpenWindow("Random Bitmap Points with Triangles", 600, 600); -Bitmap bmp = CreateBitmap("Random Triangles", 600, 600); - -for (int i = 0; i < 10; i++) -{ - // Create triangle using random points on bitmap - Triangle triangle = TriangleFrom( - RandomBitmapPoint(bmp), - RandomBitmapPoint(bmp), - RandomBitmapPoint(bmp)); - - FillTriangleOnBitmap(bmp, RandomColor(), triangle); -} - -// Draw the bitmap -ClearScreen(ColorWhiteSmoke()); -DrawBitmap(bmp, 0, 0); -RefreshScreen(); - -Delay(5000); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create Window and empty bitmap +OpenWindow("Random Bitmap Points with Triangles", 600, 600); +Bitmap bmp = CreateBitmap("Random Triangles", 600, 600); + +for (int i = 0; i < 10; i++) +{ + // Create triangle using random points on bitmap + Triangle triangle = TriangleFrom( + RandomBitmapPoint(bmp), + RandomBitmapPoint(bmp), + RandomBitmapPoint(bmp)); + + FillTriangleOnBitmap(bmp, RandomColor(), triangle); +} + +// Draw the bitmap +ClearScreen(ColorWhiteSmoke()); +DrawBitmap(bmp, 0, 0); +RefreshScreen(); + +Delay(5000); CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/random_screen_point-1-example-oop.cs b/public/usage-examples/geometry/random_screen_point-1-example-oop.cs index 7f7032b9b..419440fde 100644 --- a/public/usage-examples/geometry/random_screen_point-1-example-oop.cs +++ b/public/usage-examples/geometry/random_screen_point-1-example-oop.cs @@ -1,27 +1,27 @@ -using SplashKitSDK; - -namespace RandomScreenPointExample -{ - public class Program - { - public static void Main() - { - // Create Window - Window window = new Window("Night Sky", 600, 600); - - window.Clear(Color.Black); - for (int i = 0; i < 1000; i++) - { - // Set random pixel location on screen - Point2D pixel = SplashKit.RandomScreenPoint(); - - // Draw the pixel - SplashKit.DrawPixel(Color.RandomRGB(255), pixel); - } - window.Refresh(); - - SplashKit.Delay(5000); - window.Close(); - } - } +using SplashKitSDK; + +namespace RandomScreenPointExample +{ + public class Program + { + public static void Main() + { + // Create Window + Window window = new Window("Night Sky", 600, 600); + + window.Clear(Color.Black); + for (int i = 0; i < 1000; i++) + { + // Set random pixel location on screen + Point2D pixel = SplashKit.RandomScreenPoint(); + + // Draw the pixel + SplashKit.DrawPixel(Color.RandomRGB(255), pixel); + } + window.Refresh(); + + SplashKit.Delay(5000); + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/random_screen_point-1-example-top-level.cs b/public/usage-examples/geometry/random_screen_point-1-example-top-level.cs index ad4fab473..5ee572c52 100644 --- a/public/usage-examples/geometry/random_screen_point-1-example-top-level.cs +++ b/public/usage-examples/geometry/random_screen_point-1-example-top-level.cs @@ -1,19 +1,19 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create Window -OpenWindow("Night Sky", 600, 600); - -ClearScreen(ColorBlack()); -for (int i = 0; i < 1000; i++) -{ - // Set random pixel location on screen - Point2D pixel = RandomScreenPoint(); - - // Draw the pixel - DrawPixel(RandomRGBColor(255), pixel); -} -RefreshScreen(); - -Delay(5000); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create Window +OpenWindow("Night Sky", 600, 600); + +ClearScreen(ColorBlack()); +for (int i = 0; i < 1000; i++) +{ + // Set random pixel location on screen + Point2D pixel = RandomScreenPoint(); + + // Draw the pixel + DrawPixel(RandomRGBColor(255), pixel); +} +RefreshScreen(); + +Delay(5000); CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/geometry/random_window_point-1-example-oop.cs b/public/usage-examples/geometry/random_window_point-1-example-oop.cs index abca7b649..121676d8b 100644 --- a/public/usage-examples/geometry/random_window_point-1-example-oop.cs +++ b/public/usage-examples/geometry/random_window_point-1-example-oop.cs @@ -1,33 +1,33 @@ -using SplashKitSDK; - -namespace RandomWindowPointExample -{ - public class Program - { - public static void Main() - { - // Create Window - Window Window = SplashKit.OpenWindow("Portal", 600, 600); - - // Load portal sprites - Bitmap BluePortal = new Bitmap("BluePortal", "bluePortal.png"); - Bitmap OrangePortal = new Bitmap("OrangePortal", "orangePortal.png"); - Sprite BluePortalSprite = SplashKit.CreateSprite(BluePortal); - Sprite OrangePortalSprite = SplashKit.CreateSprite(OrangePortal); - - // Set random portal location - BluePortalSprite.Position = SplashKit.RandomWindowPoint(Window); - OrangePortalSprite.Position = SplashKit.RandomWindowPoint(Window); - - Window.Clear(Color.Black); - - // Draw the sprite - SplashKit.DrawSprite(BluePortalSprite); - SplashKit.DrawSprite(OrangePortalSprite); - - Window.Refresh(); - SplashKit.Delay(5000); - Window.Close(); - } - } +using SplashKitSDK; + +namespace RandomWindowPointExample +{ + public class Program + { + public static void Main() + { + // Create Window + Window Window = SplashKit.OpenWindow("Portal", 600, 600); + + // Load portal sprites + Bitmap BluePortal = new Bitmap("BluePortal", "bluePortal.png"); + Bitmap OrangePortal = new Bitmap("OrangePortal", "orangePortal.png"); + Sprite BluePortalSprite = SplashKit.CreateSprite(BluePortal); + Sprite OrangePortalSprite = SplashKit.CreateSprite(OrangePortal); + + // Set random portal location + BluePortalSprite.Position = SplashKit.RandomWindowPoint(Window); + OrangePortalSprite.Position = SplashKit.RandomWindowPoint(Window); + + Window.Clear(Color.Black); + + // Draw the sprite + SplashKit.DrawSprite(BluePortalSprite); + SplashKit.DrawSprite(OrangePortalSprite); + + Window.Refresh(); + SplashKit.Delay(5000); + Window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/random_window_point-1-example-top-level.cs b/public/usage-examples/geometry/random_window_point-1-example-top-level.cs index db8b95b4d..6a243b0c3 100644 --- a/public/usage-examples/geometry/random_window_point-1-example-top-level.cs +++ b/public/usage-examples/geometry/random_window_point-1-example-top-level.cs @@ -1,25 +1,25 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create Window -Window Window = OpenWindow("Portal", 600, 600); - -// Load portal sprites -LoadBitmap("BluePortal", "bluePortal.png"); -LoadBitmap("OrangePortal", "orangePortal.png"); -Sprite BluePortal = CreateSprite(BitmapNamed("BluePortal")); -Sprite OrangePortal = CreateSprite(BitmapNamed("OrangePortal")); - -// Set random portal location -SpriteSetPosition(BluePortal, RandomWindowPoint(Window)); -SpriteSetPosition(OrangePortal, RandomWindowPoint(Window)); - -ClearWindow(Window, ColorBlack()); - -// Draw the sprite -DrawSprite(BluePortal); -DrawSprite(OrangePortal); - -RefreshScreen(); -Delay(5000); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create Window +Window Window = OpenWindow("Portal", 600, 600); + +// Load portal sprites +LoadBitmap("BluePortal", "bluePortal.png"); +LoadBitmap("OrangePortal", "orangePortal.png"); +Sprite BluePortal = CreateSprite(BitmapNamed("BluePortal")); +Sprite OrangePortal = CreateSprite(BitmapNamed("OrangePortal")); + +// Set random portal location +SpriteSetPosition(BluePortal, RandomWindowPoint(Window)); +SpriteSetPosition(OrangePortal, RandomWindowPoint(Window)); + +ClearWindow(Window, ColorBlack()); + +// Draw the sprite +DrawSprite(BluePortal); +DrawSprite(OrangePortal); + +RefreshScreen(); +Delay(5000); CloseWindow(Window); \ No newline at end of file diff --git a/public/usage-examples/geometry/same_point-1-example-oop.cs b/public/usage-examples/geometry/same_point-1-example-oop.cs index 72e0dae54..1d3bb7145 100644 --- a/public/usage-examples/geometry/same_point-1-example-oop.cs +++ b/public/usage-examples/geometry/same_point-1-example-oop.cs @@ -1,63 +1,63 @@ -using SplashKitSDK; - -namespace SamePointExample -{ - public class Program - { - public static Point2D GetPoint(string prompt) - { - // Get user input - SplashKit.Write(prompt); - string guessInput = SplashKit.ReadLine(); - List coords = SplashKit.Split(guessInput, ','); - - // Validate input - while (!SplashKit.IsDouble(coords[0]) || !SplashKit.IsDouble(coords[1])) - { - SplashKit.WriteLine("Invalid input. Try again."); - SplashKit.Write(prompt); - guessInput = SplashKit.ReadLine(); - coords = SplashKit.Split(guessInput, ','); - } - - // Convert input - double guessX = SplashKit.ConvertToDouble(coords[0]); - double guessY = SplashKit.ConvertToDouble(coords[1]); - return SplashKit.PointAt(guessX, guessY); - } - - public static void Main() - { - // Variable Declarations - Point2D targetPoint = SplashKit.PointAt(50, 75); - Point2D guessPoint; - - SplashKit.WriteLine("Guess the coordinate inside (100,100) "); - - // Get user input - guessPoint = GetPoint("Enter your coordinates as x,y: "); - - while (!SplashKit.SamePoint(targetPoint, guessPoint)) - { - // Clues - if (targetPoint.X > guessPoint.X) - SplashKit.WriteLine("x is too low"); - else if (targetPoint.X < guessPoint.X) - SplashKit.WriteLine("x is too high"); - else - SplashKit.WriteLine("x is correct !!!"); - - if (targetPoint.Y > guessPoint.Y) - SplashKit.WriteLine("y is too low"); - else if (targetPoint.Y < guessPoint.Y) - SplashKit.WriteLine("y is too high"); - else - SplashKit.WriteLine("y is correct !!!"); - - SplashKit.WriteLine("Try Again!"); - guessPoint = GetPoint("Enter your coordinates as x,y: "); - } - SplashKit.WriteLine("You Win!"); - } - } +using SplashKitSDK; + +namespace SamePointExample +{ + public class Program + { + public static Point2D GetPoint(string prompt) + { + // Get user input + SplashKit.Write(prompt); + string guessInput = SplashKit.ReadLine(); + List coords = SplashKit.Split(guessInput, ','); + + // Validate input + while (!SplashKit.IsDouble(coords[0]) || !SplashKit.IsDouble(coords[1])) + { + SplashKit.WriteLine("Invalid input. Try again."); + SplashKit.Write(prompt); + guessInput = SplashKit.ReadLine(); + coords = SplashKit.Split(guessInput, ','); + } + + // Convert input + double guessX = SplashKit.ConvertToDouble(coords[0]); + double guessY = SplashKit.ConvertToDouble(coords[1]); + return SplashKit.PointAt(guessX, guessY); + } + + public static void Main() + { + // Variable Declarations + Point2D targetPoint = SplashKit.PointAt(50, 75); + Point2D guessPoint; + + SplashKit.WriteLine("Guess the coordinate inside (100,100) "); + + // Get user input + guessPoint = GetPoint("Enter your coordinates as x,y: "); + + while (!SplashKit.SamePoint(targetPoint, guessPoint)) + { + // Clues + if (targetPoint.X > guessPoint.X) + SplashKit.WriteLine("x is too low"); + else if (targetPoint.X < guessPoint.X) + SplashKit.WriteLine("x is too high"); + else + SplashKit.WriteLine("x is correct !!!"); + + if (targetPoint.Y > guessPoint.Y) + SplashKit.WriteLine("y is too low"); + else if (targetPoint.Y < guessPoint.Y) + SplashKit.WriteLine("y is too high"); + else + SplashKit.WriteLine("y is correct !!!"); + + SplashKit.WriteLine("Try Again!"); + guessPoint = GetPoint("Enter your coordinates as x,y: "); + } + SplashKit.WriteLine("You Win!"); + } + } } \ No newline at end of file diff --git a/public/usage-examples/geometry/same_point-1-example-top-level.cs b/public/usage-examples/geometry/same_point-1-example-top-level.cs index 436845223..1f53601d8 100644 --- a/public/usage-examples/geometry/same_point-1-example-top-level.cs +++ b/public/usage-examples/geometry/same_point-1-example-top-level.cs @@ -1,55 +1,55 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -static Point2D GetPoint(string prompt) -{ - // Get user input - Write(prompt); - string guessInput = ReadLine(); - List coords = Split(guessInput, ','); - - // Validate input - while (!IsDouble(coords[0]) || !IsDouble(coords[1])) - { - WriteLine("Invalid input. Try again."); - Write(prompt); - guessInput = ReadLine(); - coords = Split(guessInput, ','); - } - - // Convert input - double guessX = ConvertToDouble(coords[0]); - double guessY = ConvertToDouble(coords[1]); - return PointAt(guessX, guessY); -} - -// Variable Declarations -Point2D targetPoint = PointAt(50, 75); -Point2D guessPoint; - -WriteLine("Guess the coordinate inside (100,100) "); - -// Get user input -guessPoint = GetPoint("Enter your coordinates as x,y: "); - -while (!SamePoint(targetPoint, guessPoint)) -{ - // Clues - if (targetPoint.X > guessPoint.X) - WriteLine("x is too low"); - else if (targetPoint.X < guessPoint.X) - WriteLine("x is too high"); - else - WriteLine("x is correct !!!"); - - if (targetPoint.Y > guessPoint.Y) - WriteLine("y is too low"); - else if (targetPoint.Y < guessPoint.Y) - WriteLine("y is too high"); - else - WriteLine("y is correct !!!"); - - WriteLine("Try Again!"); - guessPoint = GetPoint("Enter your coordinates as x,y: "); -} +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +static Point2D GetPoint(string prompt) +{ + // Get user input + Write(prompt); + string guessInput = ReadLine(); + List coords = Split(guessInput, ','); + + // Validate input + while (!IsDouble(coords[0]) || !IsDouble(coords[1])) + { + WriteLine("Invalid input. Try again."); + Write(prompt); + guessInput = ReadLine(); + coords = Split(guessInput, ','); + } + + // Convert input + double guessX = ConvertToDouble(coords[0]); + double guessY = ConvertToDouble(coords[1]); + return PointAt(guessX, guessY); +} + +// Variable Declarations +Point2D targetPoint = PointAt(50, 75); +Point2D guessPoint; + +WriteLine("Guess the coordinate inside (100,100) "); + +// Get user input +guessPoint = GetPoint("Enter your coordinates as x,y: "); + +while (!SamePoint(targetPoint, guessPoint)) +{ + // Clues + if (targetPoint.X > guessPoint.X) + WriteLine("x is too low"); + else if (targetPoint.X < guessPoint.X) + WriteLine("x is too high"); + else + WriteLine("x is correct !!!"); + + if (targetPoint.Y > guessPoint.Y) + WriteLine("y is too low"); + else if (targetPoint.Y < guessPoint.Y) + WriteLine("y is too high"); + else + WriteLine("y is correct !!!"); + + WriteLine("Try Again!"); + guessPoint = GetPoint("Enter your coordinates as x,y: "); +} WriteLine("You Win!"); \ No newline at end of file diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example-oop.cs b/public/usage-examples/graphics/bitmap_bounding_circle-1-example-oop.cs new file mode 100644 index 000000000..ff9794018 --- /dev/null +++ b/public/usage-examples/graphics/bitmap_bounding_circle-1-example-oop.cs @@ -0,0 +1,33 @@ +using SplashKitSDK; + +namespace BitmapBoundingCircleExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Bitmap Bounding Circle", 800, 600); + + Bitmap vertical_bitmap = SplashKit.LoadBitmap("vertical_bitmap", "image1.jpeg"); + Bitmap horizontal_bitmap = SplashKit.LoadBitmap("horizontal_bitmap", "image2.png"); + + Circle vert_bitmap_circle = SplashKit.BitmapBoundingCircle(vertical_bitmap, SplashKit.PointAt(210, 210)); + Circle hori_bitmap_circle = SplashKit.BitmapBoundingCircle(horizontal_bitmap, SplashKit.PointAt(580, 400)); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + SplashKit.ClearScreen(Color.White); + + SplashKit.DrawBitmap(vertical_bitmap, 141, 60); + SplashKit.DrawBitmap(horizontal_bitmap, 480, 344); + + SplashKit.DrawCircle(Color.Black, vert_bitmap_circle); + SplashKit.DrawCircle(Color.Black, hori_bitmap_circle); + + SplashKit.RefreshScreen(); + } + SplashKit.CloseAllWindows(); + } + } +} \ No newline at end of file diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example-resources.zip b/public/usage-examples/graphics/bitmap_bounding_circle-1-example-resources.zip new file mode 100644 index 000000000..73d1efd74 Binary files /dev/null and b/public/usage-examples/graphics/bitmap_bounding_circle-1-example-resources.zip differ diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example-top-level.cs b/public/usage-examples/graphics/bitmap_bounding_circle-1-example-top-level.cs new file mode 100644 index 000000000..31b08ca73 --- /dev/null +++ b/public/usage-examples/graphics/bitmap_bounding_circle-1-example-top-level.cs @@ -0,0 +1,25 @@ +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Bitmap Bounding Circle", 800, 600); + +Bitmap vertical_bitmap = LoadBitmap("vertical_bitmap", "image1.jpeg"); +Bitmap horizontal_bitmap = LoadBitmap("horizontal_bitmap", "image2.png"); + +Circle vert_bitmap_circle = BitmapBoundingCircle(vertical_bitmap, PointAt(210, 210)); +Circle hori_bitmap_circle = BitmapBoundingCircle(horizontal_bitmap, PointAt(580, 400)); + +while (!QuitRequested()) +{ + ProcessEvents(); + ClearScreen(ColorWhite()); + + DrawBitmap(vertical_bitmap, 141, 60); + DrawBitmap(horizontal_bitmap, 480, 344); + + DrawCircle(ColorBlack(), vert_bitmap_circle); + DrawCircle(ColorBlack(), hori_bitmap_circle); + + RefreshScreen(); +} +CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example.cpp b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.cpp new file mode 100644 index 000000000..1ee9fb3e5 --- /dev/null +++ b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.cpp @@ -0,0 +1,28 @@ +#include "splashkit.h" + +int main() +{ + open_window("Bitmap Bounding Circle", 800, 600); + + bitmap vertical_bitmap = load_bitmap("vertical_bitmap", "image1.jpeg"); + bitmap horizontal_bitmap = load_bitmap("horizontal_bitmap", "image2.png"); + + circle vert_bitmap_circle = bitmap_bounding_circle(vertical_bitmap, point_at(210, 210)); + circle hori_bitmap_circle = bitmap_bounding_circle(horizontal_bitmap, point_at(580, 400)); + + while (!quit_requested()) + { + process_events(); + clear_screen(color_white()); + + draw_bitmap(vertical_bitmap, 141, 60); + draw_bitmap(horizontal_bitmap, 480, 344); + + draw_circle(color_black(), vert_bitmap_circle); + draw_circle(color_black(), hori_bitmap_circle); + + refresh_screen(); + } + close_all_windows(); + return 0; +} \ No newline at end of file diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example.png b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.png new file mode 100644 index 000000000..e49f43534 Binary files /dev/null and b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.png differ diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example.py b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.py new file mode 100644 index 000000000..1c0b5d3ac --- /dev/null +++ b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.py @@ -0,0 +1,23 @@ +from splashkit import * + +open_window("Bitmap Bounding Circle", 800, 600) + +vertical_bitmap = load_bitmap("vertical_bitmap", "image1.jpeg") +horizontal_bitmap = load_bitmap("horizontal_bitmap", "image2.png") + +vert_bitmap_circle = bitmap_bounding_circle(vertical_bitmap, point_at(210, 210)) +hori_bitmap_circle = bitmap_bounding_circle(horizontal_bitmap, point_at(580, 400)) + +while not quit_requested(): + process_events() + clear_screen_to_white() + + draw_bitmap(vertical_bitmap, 141, 60) + draw_bitmap(horizontal_bitmap, 480, 344) + + draw_circle_record(color_black(), vert_bitmap_circle) + draw_circle_record(color_black(), hori_bitmap_circle) + + refresh_screen() + +close_all_windows() \ No newline at end of file diff --git a/public/usage-examples/graphics/bitmap_bounding_circle-1-example.txt b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.txt new file mode 100644 index 000000000..5f0670a83 --- /dev/null +++ b/public/usage-examples/graphics/bitmap_bounding_circle-1-example.txt @@ -0,0 +1,5 @@ +Draw bitmaps surrounded by circles + +:::note +To test this example code you can download these [**Resources**](/usage-examples/graphics/bitmap_bounding_circle-1-example-resources.zip). +::: \ No newline at end of file diff --git a/public/usage-examples/graphics/clear_screen-1-example-beyond.cpp b/public/usage-examples/graphics/clear_screen-1-example-beyond.cpp deleted file mode 100644 index 98e4af214..000000000 --- a/public/usage-examples/graphics/clear_screen-1-example-beyond.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#ifdef __APPLE__ -#include -#else -#include -#endif - -SDL_Window *sdl_open_window(const char *window_title, const int width, const int height) -{ - // Declare Variables - SDL_Window *window = nullptr; - - // Check for successful initialisation - if (SDL_Init(SDL_INIT_VIDEO) < 0) - { - std::cout << "SDL could not be initialized: " << SDL_GetError(); - exit(1); - } - - // Create Window - window = SDL_CreateWindow( - window_title, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - width, - height, - SDL_WINDOW_OPENGL); - - // Error handling for window - if (window == NULL) - { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Could not create window: %s\n", SDL_GetError()); - exit(1); - } - - return window; -} - -int main(int argv, char **args) -{ - // Open window with title and dimensions - SDL_Window *window = sdl_open_window("Blue Background", 800, 600); - - // Create renderer - SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); - if (renderer == NULL) - { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Could not create renderer: %s\n", SDL_GetError()); - exit(1); - } - - // Clear screen to blue - SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); - SDL_RenderClear(renderer); - SDL_RenderPresent(renderer); - - Uint32 start_time = SDL_GetTicks(); // Start timer - SDL_Event event; - - while (SDL_GetTicks() - start_time < 4000) // Run for 4 seconds - { - if (SDL_PollEvent(&event) && event.type == SDL_QUIT) break; - } - - // Cleanup and free memory - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - SDL_Quit(); - - return 0; -} \ No newline at end of file diff --git a/public/usage-examples/graphics/clear_screen-1-example-oop.cs b/public/usage-examples/graphics/clear_screen-1-example-oop.cs index c96c4e032..31b5cb8ea 100644 --- a/public/usage-examples/graphics/clear_screen-1-example-oop.cs +++ b/public/usage-examples/graphics/clear_screen-1-example-oop.cs @@ -1,19 +1,19 @@ -using SplashKitSDK; - -namespace ClearScreenExample -{ - public class Program - { - public static void Main() - { - SplashKit.OpenWindow("Blue Background", 800, 600); - - //Use Clear Screen to change the background color to blue - SplashKit.ClearScreen(Color.Blue); - - SplashKit.RefreshScreen(60); - SplashKit.Delay(4000); - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace ClearScreenExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Blue Background", 800, 600); + + //Use Clear Screen to change the background color to blue + SplashKit.ClearScreen(Color.Blue); + + SplashKit.RefreshScreen(60); + SplashKit.Delay(4000); + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/clear_screen-1-example-sk.cpp b/public/usage-examples/graphics/clear_screen-1-example.cpp similarity index 100% rename from public/usage-examples/graphics/clear_screen-1-example-sk.cpp rename to public/usage-examples/graphics/clear_screen-1-example.cpp diff --git a/public/usage-examples/graphics/draw_bitmap_named-1-example-beyond.cpp b/public/usage-examples/graphics/draw_bitmap_named-1-example-beyond.cpp deleted file mode 100644 index ed70e0e39..000000000 --- a/public/usage-examples/graphics/draw_bitmap_named-1-example-beyond.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include -#ifdef __APPLE__ -#include -#include -#else -#include -#include -#endif - -SDL_Window *sdl_open_window(const char *window_title, const int width, const int height) -{ - // Declare Variables - SDL_Window *window = nullptr; - - // Check for successful initialisation - if (SDL_Init(SDL_INIT_VIDEO) < 0) - { - std::cout << "SDL could not be initialized: " << SDL_GetError(); - exit(1); - } - - // Create Window - window = SDL_CreateWindow( - window_title, - SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, - width, - height, - SDL_WINDOW_OPENGL); - - // Error handling for window - if (window == NULL) - { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Could not create window: %s\n", SDL_GetError()); - exit(1); - } - - return window; -} - -SDL_Renderer *sdl_create_renderer(SDL_Window *window) -{ - SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); - if (renderer == NULL) - { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Could not create rederer: %s\n", SDL_GetError()); - exit(1); - } - return renderer; -} - -int main(int argv, char **args) -{ - // Open Window - SDL_Window *window = sdl_open_window("Basic Bitmap Drawing", 315, 330); - SDL_Renderer *renderer = sdl_create_renderer(window); - - // Load bitmap image - // Create a surface for imported image - SDL_Surface *image = IMG_Load("Resources/images/skbox.png"); - if (image == NULL) - { - std::cout << "Failed to load skbox.png" << SDL_GetError(); - exit(1); - } - - // Convert surface to texture - SDL_Texture *image_texture = SDL_CreateTextureFromSurface(renderer, image); - if (image_texture == NULL) - { - std::cout << "Failed to create texture" << SDL_GetError(); - exit(1); - } - - // Free memory - SDL_FreeSurface(image); - - // Get image size to avoid stretching - int background_width = 0, background_height = 0; - SDL_QueryTexture(image_texture, NULL, NULL, &background_width, &background_height); - - // Hang window until quit - SDL_Event event; - while (event.type != SDL_QUIT) - { - SDL_PollEvent(&event); - - // Clear screen with blue - SDL_SetRenderDrawColor(renderer, 67, 80, 175, 255); - SDL_RenderClear(renderer); - - // Draw image to screen - SDL_Rect image_rect = { 50, 50, background_width, background_height }; - SDL_RenderCopy(renderer, image_texture, NULL, &image_rect); - - // Display drawing - SDL_RenderPresent(renderer); - } - - // Cleanup and free memory - SDL_DestroyWindow(window); - SDL_DestroyRenderer(renderer); - - return 0; -} \ No newline at end of file diff --git a/public/usage-examples/graphics/draw_bitmap_named-1-example-sk.cpp b/public/usage-examples/graphics/draw_bitmap_named-1-example.cpp similarity index 100% rename from public/usage-examples/graphics/draw_bitmap_named-1-example-sk.cpp rename to public/usage-examples/graphics/draw_bitmap_named-1-example.cpp diff --git a/public/usage-examples/graphics/draw_circle_record-1-example-oop.cs b/public/usage-examples/graphics/draw_circle_record-1-example-oop.cs index b45d8c133..d5c378275 100644 --- a/public/usage-examples/graphics/draw_circle_record-1-example-oop.cs +++ b/public/usage-examples/graphics/draw_circle_record-1-example-oop.cs @@ -1,29 +1,29 @@ -using SplashKitSDK; - -namespace DrawCircleExample -{ - public class Program - { - public static void Main() - { - SplashKit.OpenWindow("Draw Circles", 800, 600); - - // Create circles with different radii - Circle circle1 = new Circle { Center = SplashKit.ScreenCenter(), Radius = 50 }; - Circle circle2 = new Circle { Center = SplashKit.ScreenCenter(), Radius = 100 }; - - SplashKit.ClearScreen(); - - // Draw the circles with different colors - circle1.Draw(Color.Red); - circle2.Draw(Color.Blue); - SplashKit.DrawCircle(Color.Orange, SplashKit.CircleAt(SplashKit.ScreenCenter(), 150)); - SplashKit.DrawCircle(Color.Green, SplashKit.CircleAt(SplashKit.ScreenCenter(), 200 )); - - SplashKit.RefreshScreen(); - - SplashKit.Delay(4000); - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace DrawCircleExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Draw Circles", 800, 600); + + // Create circles with different radii + Circle circle1 = new Circle { Center = SplashKit.ScreenCenter(), Radius = 50 }; + Circle circle2 = new Circle { Center = SplashKit.ScreenCenter(), Radius = 100 }; + + SplashKit.ClearScreen(); + + // Draw the circles with different colors + circle1.Draw(Color.Red); + circle2.Draw(Color.Blue); + SplashKit.DrawCircle(Color.Orange, SplashKit.CircleAt(SplashKit.ScreenCenter(), 150)); + SplashKit.DrawCircle(Color.Green, SplashKit.CircleAt(SplashKit.ScreenCenter(), 200 )); + + SplashKit.RefreshScreen(); + + SplashKit.Delay(4000); + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/draw_circle_record-1-example-top-level.cs b/public/usage-examples/graphics/draw_circle_record-1-example-top-level.cs index 861d9994b..cf0fcaf38 100644 --- a/public/usage-examples/graphics/draw_circle_record-1-example-top-level.cs +++ b/public/usage-examples/graphics/draw_circle_record-1-example-top-level.cs @@ -1,21 +1,21 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -OpenWindow("Draw Circles", 800, 600); - -// Create circles with different radii -Circle circle1 = CircleAt(ScreenCenter(), 50); -Circle circle2 = CircleAt(ScreenCenter(), 100); - -ClearScreen(); - -// Draw the circles with different colors -DrawCircle(ColorRed(), circle1); -DrawCircle(ColorBlue(), circle2); -DrawCircle(ColorOrange(), CircleAt(ScreenCenter(), 150)); -DrawCircle(ColorGreen(), CircleAt(ScreenCenter(), 200)); - -RefreshScreen(); - -Delay(4000); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Draw Circles", 800, 600); + +// Create circles with different radii +Circle circle1 = CircleAt(ScreenCenter(), 50); +Circle circle2 = CircleAt(ScreenCenter(), 100); + +ClearScreen(); + +// Draw the circles with different colors +DrawCircle(ColorRed(), circle1); +DrawCircle(ColorBlue(), circle2); +DrawCircle(ColorOrange(), CircleAt(ScreenCenter(), 150)); +DrawCircle(ColorGreen(), CircleAt(ScreenCenter(), 200)); + +RefreshScreen(); + +Delay(4000); CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/graphics/draw_line-1-example-oop.cs b/public/usage-examples/graphics/draw_line-1-example-oop.cs index 21e070db5..f582da7ae 100644 --- a/public/usage-examples/graphics/draw_line-1-example-oop.cs +++ b/public/usage-examples/graphics/draw_line-1-example-oop.cs @@ -1,28 +1,28 @@ -using SplashKitSDK; - -namespace DrawLineExample -{ - public class Program - { - public static void Main() - { - Window window = new Window("Colourful Starburst", 600, 600); - window.Clear(Color.Black); - - // Draws starburst pattern with changing colours to window - window.DrawLine(Color.Yellow, 0, 0, 600, 600); - window.DrawLine(Color.Green, 0, 150, 600, 450); - window.DrawLine(Color.Teal, 0, 300, 600, 300); - window.DrawLine(Color.Blue, 0, 450, 600, 150); - window.DrawLine(Color.Violet, 0, 600, 600, 0); - window.DrawLine(Color.Purple, 150, 0, 450, 600); - window.DrawLine(Color.Pink, 300, 0, 300, 600); - window.DrawLine(Color.Red, 450, 0, 150, 600); - window.DrawLine(Color.Orange, 600, 0, 0, 600); - - window.Refresh(); - SplashKit.Delay(5000); - window.Close(); - } - } +using SplashKitSDK; + +namespace DrawLineExample +{ + public class Program + { + public static void Main() + { + Window window = new Window("Colourful Starburst", 600, 600); + window.Clear(Color.Black); + + // Draws starburst pattern with changing colours to window + window.DrawLine(Color.Yellow, 0, 0, 600, 600); + window.DrawLine(Color.Green, 0, 150, 600, 450); + window.DrawLine(Color.Teal, 0, 300, 600, 300); + window.DrawLine(Color.Blue, 0, 450, 600, 150); + window.DrawLine(Color.Violet, 0, 600, 600, 0); + window.DrawLine(Color.Purple, 150, 0, 450, 600); + window.DrawLine(Color.Pink, 300, 0, 300, 600); + window.DrawLine(Color.Red, 450, 0, 150, 600); + window.DrawLine(Color.Orange, 600, 0, 0, 600); + + window.Refresh(); + SplashKit.Delay(5000); + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/draw_line-1-example-top-level.cs b/public/usage-examples/graphics/draw_line-1-example-top-level.cs index bcd129983..ffe391079 100644 --- a/public/usage-examples/graphics/draw_line-1-example-top-level.cs +++ b/public/usage-examples/graphics/draw_line-1-example-top-level.cs @@ -1,19 +1,19 @@ -using static SplashKitSDK.SplashKit; - -OpenWindow("Colourful Starburst", 600, 600); -ClearScreen(ColorBlack()); - -// Draws starburst pattern with changing colours -DrawLine(ColorYellow(), 0, 0, 600, 600); -DrawLine(ColorGreen(), 0, 150, 600, 450); -DrawLine(ColorTeal(), 0, 300, 600, 300); -DrawLine(ColorBlue(), 0, 450, 600, 150); -DrawLine(ColorViolet(), 0, 600, 600, 0); -DrawLine(ColorPurple(), 150, 0, 450, 600); -DrawLine(ColorPink(), 300, 0, 300, 600); -DrawLine(ColorRed(), 450, 0, 150, 600); -DrawLine(ColorOrange(), 600, 0, 0, 600); - -RefreshScreen(); -Delay(5000); -CloseAllWindows(); +using static SplashKitSDK.SplashKit; + +OpenWindow("Colourful Starburst", 600, 600); +ClearScreen(ColorBlack()); + +// Draws starburst pattern with changing colours +DrawLine(ColorYellow(), 0, 0, 600, 600); +DrawLine(ColorGreen(), 0, 150, 600, 450); +DrawLine(ColorTeal(), 0, 300, 600, 300); +DrawLine(ColorBlue(), 0, 450, 600, 150); +DrawLine(ColorViolet(), 0, 600, 600, 0); +DrawLine(ColorPurple(), 150, 0, 450, 600); +DrawLine(ColorPink(), 300, 0, 300, 600); +DrawLine(ColorRed(), 450, 0, 150, 600); +DrawLine(ColorOrange(), 600, 0, 0, 600); + +RefreshScreen(); +Delay(5000); +CloseAllWindows(); diff --git a/public/usage-examples/graphics/draw_line_on_window-1-example-oop.cs b/public/usage-examples/graphics/draw_line_on_window-1-example-oop.cs index 13533c6f8..9e19a4285 100644 --- a/public/usage-examples/graphics/draw_line_on_window-1-example-oop.cs +++ b/public/usage-examples/graphics/draw_line_on_window-1-example-oop.cs @@ -1,31 +1,31 @@ -using SplashKitSDK; - -namespace DrawLineOnWindowExample -{ - public class Program - { - public static void Main() - { - // Create Window - Window window = new Window("Colourful Starburst", 600, 600); - - window.Clear(Color.Black); - - // Draws starburst pattern with changing colours to specific window - window.DrawLine(Color.Yellow, 0, 0, 600, 600); - window.DrawLine(Color.Green, 0, 150, 600, 450); - window.DrawLine(Color.Teal, 0, 300, 600, 300); - window.DrawLine(Color.Blue, 0, 450, 600, 150); - window.DrawLine(Color.Violet, 0, 600, 600, 0); - window.DrawLine(Color.Purple, 150, 0, 450, 600); - window.DrawLine(Color.Pink, 300, 0, 300, 600); - window.DrawLine(Color.Red, 450, 0, 150, 600); - window.DrawLine(Color.Orange, 600, 0, 0, 600); - - window.Refresh(); - - SplashKit.Delay(5000); - window.Close(); - } - } -} +using SplashKitSDK; + +namespace DrawLineOnWindowExample +{ + public class Program + { + public static void Main() + { + // Create Window + Window window = new Window("Colourful Starburst", 600, 600); + + window.Clear(Color.Black); + + // Draws starburst pattern with changing colours to specific window + window.DrawLine(Color.Yellow, 0, 0, 600, 600); + window.DrawLine(Color.Green, 0, 150, 600, 450); + window.DrawLine(Color.Teal, 0, 300, 600, 300); + window.DrawLine(Color.Blue, 0, 450, 600, 150); + window.DrawLine(Color.Violet, 0, 600, 600, 0); + window.DrawLine(Color.Purple, 150, 0, 450, 600); + window.DrawLine(Color.Pink, 300, 0, 300, 600); + window.DrawLine(Color.Red, 450, 0, 150, 600); + window.DrawLine(Color.Orange, 600, 0, 0, 600); + + window.Refresh(); + + SplashKit.Delay(5000); + window.Close(); + } + } +} diff --git a/public/usage-examples/graphics/draw_line_on_window-1-example-top-level.cs b/public/usage-examples/graphics/draw_line_on_window-1-example-top-level.cs index 57175b421..98e9f6318 100644 --- a/public/usage-examples/graphics/draw_line_on_window-1-example-top-level.cs +++ b/public/usage-examples/graphics/draw_line_on_window-1-example-top-level.cs @@ -1,24 +1,24 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - - -// Create Window -Window window = OpenWindow("Colourful Starburst", 600, 600); - -ClearScreen(ColorBlack()); - -// Draws starburst pattern with changing colours to specific window -DrawLineOnWindow(window, ColorYellow(), 0, 0, 600, 600); -DrawLineOnWindow(window, ColorGreen(), 0, 150, 600, 450); -DrawLineOnWindow(window, ColorTeal(), 0, 300, 600, 300); -DrawLineOnWindow(window, ColorBlue(), 0, 450, 600, 150); -DrawLineOnWindow(window, ColorViolet(), 0, 600, 600, 0); -DrawLineOnWindow(window, ColorPurple(), 150, 0, 450, 600); -DrawLineOnWindow(window, ColorPink(), 300, 0, 300, 600); -DrawLineOnWindow(window, ColorRed(), 450, 0, 150, 600); -DrawLineOnWindow(window, ColorOrange(), 600, 0, 0, 600); - -RefreshScreen(); - -Delay(5000); -CloseAllWindows(); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + + +// Create Window +Window window = OpenWindow("Colourful Starburst", 600, 600); + +ClearScreen(ColorBlack()); + +// Draws starburst pattern with changing colours to specific window +DrawLineOnWindow(window, ColorYellow(), 0, 0, 600, 600); +DrawLineOnWindow(window, ColorGreen(), 0, 150, 600, 450); +DrawLineOnWindow(window, ColorTeal(), 0, 300, 600, 300); +DrawLineOnWindow(window, ColorBlue(), 0, 450, 600, 150); +DrawLineOnWindow(window, ColorViolet(), 0, 600, 600, 0); +DrawLineOnWindow(window, ColorPurple(), 150, 0, 450, 600); +DrawLineOnWindow(window, ColorPink(), 300, 0, 300, 600); +DrawLineOnWindow(window, ColorRed(), 450, 0, 150, 600); +DrawLineOnWindow(window, ColorOrange(), 600, 0, 0, 600); + +RefreshScreen(); + +Delay(5000); +CloseAllWindows(); diff --git a/public/usage-examples/graphics/draw_pixel-1-example-oop.cs b/public/usage-examples/graphics/draw_pixel-1-example-oop.cs index 1c6e1c402..f157f679a 100644 --- a/public/usage-examples/graphics/draw_pixel-1-example-oop.cs +++ b/public/usage-examples/graphics/draw_pixel-1-example-oop.cs @@ -1,42 +1,42 @@ -using SplashKitSDK; - -namespace DrawPixelExample -{ - public class Program - { - public static void Main() - { - // Declare variables - const int TrailLength = 50; - Point2D mousePoint; - Point2D[] mouseHistory = new Point2D[TrailLength]; - Color[] colorList = { Color.Blue, Color.Red, Color.Green, Color.Yellow, Color.Pink }; - - Window window = new Window("Cursor Trail", 600, 600); - - while (!SplashKit.QuitRequested()) - { - mousePoint = SplashKit.MousePosition(); - window.Clear(Color.Black); - // Set mouse position history - for (int i = 0; i < TrailLength - 1; i++) - { - // Shuffle forward - mouseHistory[i] = mouseHistory[i + 1]; - } - - mouseHistory[TrailLength - 1] = mousePoint; - - // Draw mouse trail - for (int i = 0; i < TrailLength; i++) - { - SplashKit.DrawPixel(colorList[i % 5], mouseHistory[i]); - } - - SplashKit.ProcessEvents(); - window.Refresh(60); - } - window.Close(); - } - } +using SplashKitSDK; + +namespace DrawPixelExample +{ + public class Program + { + public static void Main() + { + // Declare variables + const int TrailLength = 50; + Point2D mousePoint; + Point2D[] mouseHistory = new Point2D[TrailLength]; + Color[] colorList = { Color.Blue, Color.Red, Color.Green, Color.Yellow, Color.Pink }; + + Window window = new Window("Cursor Trail", 600, 600); + + while (!SplashKit.QuitRequested()) + { + mousePoint = SplashKit.MousePosition(); + window.Clear(Color.Black); + // Set mouse position history + for (int i = 0; i < TrailLength - 1; i++) + { + // Shuffle forward + mouseHistory[i] = mouseHistory[i + 1]; + } + + mouseHistory[TrailLength - 1] = mousePoint; + + // Draw mouse trail + for (int i = 0; i < TrailLength; i++) + { + SplashKit.DrawPixel(colorList[i % 5], mouseHistory[i]); + } + + SplashKit.ProcessEvents(); + window.Refresh(60); + } + window.Close(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/draw_pixel-1-example-top-level.cs b/public/usage-examples/graphics/draw_pixel-1-example-top-level.cs index 31e04d76f..8f2ff80ba 100644 --- a/public/usage-examples/graphics/draw_pixel-1-example-top-level.cs +++ b/public/usage-examples/graphics/draw_pixel-1-example-top-level.cs @@ -1,36 +1,36 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Declare variables -const int TrailLength = 50; -Point2D mousePoint; -Point2D[] mouseHistory = new Point2D[TrailLength]; -Color[] colorList = { ColorBlue(), ColorRed(), ColorGreen(), ColorYellow(), ColorPink() }; - -OpenWindow("Cursor Trail", 600, 600); - -while (!QuitRequested()) -{ - mousePoint = MousePosition(); - ClearScreen(ColorBlack()); - - // Set mouse position history - for (int i = 0; i < TrailLength - 1; i++) - { - // Shuffle forward - mouseHistory[i] = mouseHistory[i + 1]; - } - - mouseHistory[TrailLength - 1] = mousePoint; - - // Draw mouse trail - for (int i = 0; i < TrailLength; i++) - { - DrawPixel(colorList[i % 5], mouseHistory[i]); - } - - ProcessEvents(); - RefreshScreen(60); -} - -CloseAllWindows(); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Declare variables +const int TrailLength = 50; +Point2D mousePoint; +Point2D[] mouseHistory = new Point2D[TrailLength]; +Color[] colorList = { ColorBlue(), ColorRed(), ColorGreen(), ColorYellow(), ColorPink() }; + +OpenWindow("Cursor Trail", 600, 600); + +while (!QuitRequested()) +{ + mousePoint = MousePosition(); + ClearScreen(ColorBlack()); + + // Set mouse position history + for (int i = 0; i < TrailLength - 1; i++) + { + // Shuffle forward + mouseHistory[i] = mouseHistory[i + 1]; + } + + mouseHistory[TrailLength - 1] = mousePoint; + + // Draw mouse trail + for (int i = 0; i < TrailLength; i++) + { + DrawPixel(colorList[i % 5], mouseHistory[i]); + } + + ProcessEvents(); + RefreshScreen(60); +} + +CloseAllWindows(); diff --git a/public/usage-examples/graphics/draw_quad-1-example-oop.cs b/public/usage-examples/graphics/draw_quad-1-example-oop.cs index 27bde59d1..f343c8dfe 100644 --- a/public/usage-examples/graphics/draw_quad-1-example-oop.cs +++ b/public/usage-examples/graphics/draw_quad-1-example-oop.cs @@ -1,29 +1,29 @@ -using SplashKitSDK; - -namespace DrawQuadExample -{ - public class Program - { - public static void Main() - { - // Create 4 diamond shapes using quads - Quad q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); - Quad q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); - Quad q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); - Quad q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - - SplashKit.OpenWindow("Ninja Star", 600, 600); - SplashKit.ClearScreen(Color.White); - - // Draw the quads - SplashKit.DrawQuad(Color.Black, q1); - SplashKit.DrawQuad(Color.Green, q2); - SplashKit.DrawQuad(Color.Red, q3); - SplashKit.DrawQuad(Color.Blue, q4); - - SplashKit.RefreshScreen(); - SplashKit.Delay(5000); - SplashKit.CloseAllWindows(); - } - } -} +using SplashKitSDK; + +namespace DrawQuadExample +{ + public class Program + { + public static void Main() + { + // Create 4 diamond shapes using quads + Quad q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); + Quad q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); + Quad q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); + Quad q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + + SplashKit.OpenWindow("Ninja Star", 600, 600); + SplashKit.ClearScreen(Color.White); + + // Draw the quads + SplashKit.DrawQuad(Color.Black, q1); + SplashKit.DrawQuad(Color.Green, q2); + SplashKit.DrawQuad(Color.Red, q3); + SplashKit.DrawQuad(Color.Blue, q4); + + SplashKit.RefreshScreen(); + SplashKit.Delay(5000); + SplashKit.CloseAllWindows(); + } + } +} diff --git a/public/usage-examples/graphics/draw_quad-1-example-top-level.cs b/public/usage-examples/graphics/draw_quad-1-example-top-level.cs index cc40ae964..6ea7092c7 100644 --- a/public/usage-examples/graphics/draw_quad-1-example-top-level.cs +++ b/public/usage-examples/graphics/draw_quad-1-example-top-level.cs @@ -1,21 +1,21 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create 4 diamond shapes using quads -Quad q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); -Quad q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); -Quad q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); -Quad q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - -OpenWindow("Ninja Star", 600, 600); -ClearScreen(ColorWhite()); - -// Draw the quads -DrawQuad(ColorBlack(), q1); -DrawQuad(ColorGreen(), q2); -DrawQuad(ColorRed(), q3); -DrawQuad(ColorBlue(), q4); - -RefreshScreen(); -Delay(5000); -CloseAllWindows(); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create 4 diamond shapes using quads +Quad q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); +Quad q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); +Quad q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); +Quad q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + +OpenWindow("Ninja Star", 600, 600); +ClearScreen(ColorWhite()); + +// Draw the quads +DrawQuad(ColorBlack(), q1); +DrawQuad(ColorGreen(), q2); +DrawQuad(ColorRed(), q3); +DrawQuad(ColorBlue(), q4); + +RefreshScreen(); +Delay(5000); +CloseAllWindows(); diff --git a/public/usage-examples/graphics/draw_quad_on_window-1-example-oop.cs b/public/usage-examples/graphics/draw_quad_on_window-1-example-oop.cs index 68b62779c..fde44e3b5 100644 --- a/public/usage-examples/graphics/draw_quad_on_window-1-example-oop.cs +++ b/public/usage-examples/graphics/draw_quad_on_window-1-example-oop.cs @@ -1,37 +1,37 @@ -using SplashKitSDK; - -namespace DrawQuadOnWindowExample -{ - public class Program - { - public static void Main() - { - // Create diamond shaped quads - Quad q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); - Quad q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); - Quad q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); - Quad q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - - // Create two Windows - Window window1 = SplashKit.OpenWindow("Diamonds On Window 1", 600, 600); - Window window2 = SplashKit.OpenWindow("Diamonds On Window 2", 600, 600); - - // Move windows to see both side by side - window1.MoveTo(0, 0); - window2.MoveTo(window1.Width, 0); - - SplashKit.ClearScreen(Color.White); - - // Draw the first and second quad on first window - window1.DrawQuad(Color.Black, q1); - window1.DrawQuad(Color.Green, q2); - // Draw the third and fourth quad on second window - window2.DrawQuad(Color.Red, q3); - window2.DrawQuad(Color.Blue, q4); - - SplashKit.RefreshScreen(); - SplashKit.Delay(5000); - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace DrawQuadOnWindowExample +{ + public class Program + { + public static void Main() + { + // Create diamond shaped quads + Quad q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); + Quad q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); + Quad q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); + Quad q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + + // Create two Windows + Window window1 = SplashKit.OpenWindow("Diamonds On Window 1", 600, 600); + Window window2 = SplashKit.OpenWindow("Diamonds On Window 2", 600, 600); + + // Move windows to see both side by side + window1.MoveTo(0, 0); + window2.MoveTo(window1.Width, 0); + + SplashKit.ClearScreen(Color.White); + + // Draw the first and second quad on first window + window1.DrawQuad(Color.Black, q1); + window1.DrawQuad(Color.Green, q2); + // Draw the third and fourth quad on second window + window2.DrawQuad(Color.Red, q3); + window2.DrawQuad(Color.Blue, q4); + + SplashKit.RefreshScreen(); + SplashKit.Delay(5000); + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/draw_quad_on_window-1-example-top-level.cs b/public/usage-examples/graphics/draw_quad_on_window-1-example-top-level.cs index 11ffe65f5..7c13651ae 100644 --- a/public/usage-examples/graphics/draw_quad_on_window-1-example-top-level.cs +++ b/public/usage-examples/graphics/draw_quad_on_window-1-example-top-level.cs @@ -1,30 +1,30 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create diamond shaped quads -Quad q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); -Quad q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); -Quad q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); -Quad q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - -// Create two Windows -Window window1 = OpenWindow("Diamonds On Window 1", 600, 600); -Window window2 = OpenWindow("Diamonds On Window 2", 600, 600); - -// Move windows to see both side by side -MoveWindowTo(window1, 0, 0); -MoveWindowTo(window2, WindowWidth(window1), 0); - -ClearScreen(ColorWhite()); - -// Draw the first and second quad on first window -DrawQuadOnWindow(window1, ColorBlack(), q1); -DrawQuadOnWindow(window1, ColorGreen(), q2); - -// Draw the third and fourth quad on second window -DrawQuadOnWindow(window2, ColorRed(), q3); -DrawQuadOnWindow(window2, ColorBlue(), q4); - -RefreshScreen(); -Delay(5000); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create diamond shaped quads +Quad q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); +Quad q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); +Quad q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); +Quad q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + +// Create two Windows +Window window1 = OpenWindow("Diamonds On Window 1", 600, 600); +Window window2 = OpenWindow("Diamonds On Window 2", 600, 600); + +// Move windows to see both side by side +MoveWindowTo(window1, 0, 0); +MoveWindowTo(window2, WindowWidth(window1), 0); + +ClearScreen(ColorWhite()); + +// Draw the first and second quad on first window +DrawQuadOnWindow(window1, ColorBlack(), q1); +DrawQuadOnWindow(window1, ColorGreen(), q2); + +// Draw the third and fourth quad on second window +DrawQuadOnWindow(window2, ColorRed(), q3); +DrawQuadOnWindow(window2, ColorBlue(), q4); + +RefreshScreen(); +Delay(5000); CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/graphics/fill_circle_on_window-1-example-oop.cs b/public/usage-examples/graphics/fill_circle_on_window-1-example-oop.cs index 100ecf891..23f01a3b6 100644 --- a/public/usage-examples/graphics/fill_circle_on_window-1-example-oop.cs +++ b/public/usage-examples/graphics/fill_circle_on_window-1-example-oop.cs @@ -1,27 +1,27 @@ -using SplashKitSDK; - -namespace FillCircleOnWindowExample -{ - public class Program - { - public static void Main() - { - // Open a new window and initialize to a window variable - Window window = SplashKit.OpenWindow("Traffic Lights", 800, 600); - - window.Clear(Color.White); - - // Use function to place 3 circles in destination window as traffic lights - window.FillCircle(Color.Red, 400, 100, 50); - window.FillCircle(Color.Yellow, 400, 250, 50); - window.FillCircle(Color.Green, 400, 400, 50); - - window.Refresh(); - SplashKit.Delay(5000); - - // Close loaded window - window.Close(); - - } - } +using SplashKitSDK; + +namespace FillCircleOnWindowExample +{ + public class Program + { + public static void Main() + { + // Open a new window and initialize to a window variable + Window window = SplashKit.OpenWindow("Traffic Lights", 800, 600); + + window.Clear(Color.White); + + // Use function to place 3 circles in destination window as traffic lights + window.FillCircle(Color.Red, 400, 100, 50); + window.FillCircle(Color.Yellow, 400, 250, 50); + window.FillCircle(Color.Green, 400, 400, 50); + + window.Refresh(); + SplashKit.Delay(5000); + + // Close loaded window + window.Close(); + + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/fill_circle_on_window-1-example-top-level.cs b/public/usage-examples/graphics/fill_circle_on_window-1-example-top-level.cs index 3bccf8db2..d75008be8 100644 --- a/public/usage-examples/graphics/fill_circle_on_window-1-example-top-level.cs +++ b/public/usage-examples/graphics/fill_circle_on_window-1-example-top-level.cs @@ -1,17 +1,17 @@ -using static SplashKitSDK.SplashKit; - -// Open a new window and initialize to a window variable -SplashKitSDK.Window window = OpenWindow("Traffic Lights", 800, 600); - -ClearScreen(ColorWhite()); - -// Use function to place 3 circles in destination window as traffic lights -FillCircleOnWindow(window, ColorRed(), 400, 100, 50); -FillCircleOnWindow(window, ColorYellow(), 400, 250, 50); -FillCircleOnWindow(window, ColorGreen(), 400, 400, 50); - -RefreshScreen(); -Delay(5000); - -// Close all windows +using static SplashKitSDK.SplashKit; + +// Open a new window and initialize to a window variable +SplashKitSDK.Window window = OpenWindow("Traffic Lights", 800, 600); + +ClearScreen(ColorWhite()); + +// Use function to place 3 circles in destination window as traffic lights +FillCircleOnWindow(window, ColorRed(), 400, 100, 50); +FillCircleOnWindow(window, ColorYellow(), 400, 250, 50); +FillCircleOnWindow(window, ColorGreen(), 400, 400, 50); + +RefreshScreen(); +Delay(5000); + +// Close all windows CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/graphics/fill_quad-1-example-oop.cs b/public/usage-examples/graphics/fill_quad-1-example-oop.cs index 713126dec..f8c268554 100644 --- a/public/usage-examples/graphics/fill_quad-1-example-oop.cs +++ b/public/usage-examples/graphics/fill_quad-1-example-oop.cs @@ -1,29 +1,29 @@ -using SplashKitSDK; - -namespace FillQuadExample -{ - public class Program - { - public static void Main() - { - // Create 4 diamond shapes using quads - Quad Q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); - Quad Q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); - Quad Q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); - Quad Q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - - SplashKit.OpenWindow("Coloured Star", 600, 600); - SplashKit.ClearScreen(Color.White); - - // Draw filled-in quads - SplashKit.FillQuad(Color.Black, Q1); - SplashKit.FillQuad(Color.Green, Q2); - SplashKit.FillQuad(Color.Red, Q3); - SplashKit.FillQuad(Color.Blue, Q4); - - SplashKit.RefreshScreen(); - SplashKit.Delay(5000); - SplashKit.CloseAllWindows(); - } - } -} +using SplashKitSDK; + +namespace FillQuadExample +{ + public class Program + { + public static void Main() + { + // Create 4 diamond shapes using quads + Quad Q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); + Quad Q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); + Quad Q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); + Quad Q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + + SplashKit.OpenWindow("Coloured Star", 600, 600); + SplashKit.ClearScreen(Color.White); + + // Draw filled-in quads + SplashKit.FillQuad(Color.Black, Q1); + SplashKit.FillQuad(Color.Green, Q2); + SplashKit.FillQuad(Color.Red, Q3); + SplashKit.FillQuad(Color.Blue, Q4); + + SplashKit.RefreshScreen(); + SplashKit.Delay(5000); + SplashKit.CloseAllWindows(); + } + } +} diff --git a/public/usage-examples/graphics/fill_quad-1-example-top-level.cs b/public/usage-examples/graphics/fill_quad-1-example-top-level.cs index 9da75491c..af034ad38 100644 --- a/public/usage-examples/graphics/fill_quad-1-example-top-level.cs +++ b/public/usage-examples/graphics/fill_quad-1-example-top-level.cs @@ -1,21 +1,21 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create 4 diamond shapes using quads -Quad Q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); -Quad Q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); -Quad Q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); -Quad Q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - -OpenWindow("Coloured Star", 600, 600); -ClearScreen(ColorWhite()); - -// Draw filled-in quads -FillQuad(ColorBlack(), Q1); -FillQuad(ColorGreen(), Q2); -FillQuad(ColorRed(), Q3); -FillQuad(ColorBlue(), Q4); - -RefreshScreen(); -Delay(5000); -CloseAllWindows(); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create 4 diamond shapes using quads +Quad Q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); +Quad Q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); +Quad Q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); +Quad Q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + +OpenWindow("Coloured Star", 600, 600); +ClearScreen(ColorWhite()); + +// Draw filled-in quads +FillQuad(ColorBlack(), Q1); +FillQuad(ColorGreen(), Q2); +FillQuad(ColorRed(), Q3); +FillQuad(ColorBlue(), Q4); + +RefreshScreen(); +Delay(5000); +CloseAllWindows(); diff --git a/public/usage-examples/graphics/fill_quad_on_window-1-example-oop.cs b/public/usage-examples/graphics/fill_quad_on_window-1-example-oop.cs index ab58da285..241e666b7 100644 --- a/public/usage-examples/graphics/fill_quad_on_window-1-example-oop.cs +++ b/public/usage-examples/graphics/fill_quad_on_window-1-example-oop.cs @@ -1,38 +1,38 @@ -using SplashKitSDK; - -namespace FillQuadOnWindowExample -{ - public class Program - { - public static void Main() - { - // Create diamond shaped quads - Quad q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); - Quad q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); - Quad q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); - Quad q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - - // Create two Windows - Window window1 = new Window("Filled Diamond On Window 1", 600, 600); - Window window2 = new Window("Filled Diamond On Window 2", 600, 600); - - // Move windows to see both side by side - window1.MoveTo(0, 0); - window2.MoveTo(window1.Width, 0); - - SplashKit.ClearScreen(Color.White); - - // Draw the first and second quad on first window - window1.FillQuad(Color.Black, q1); - window1.FillQuad(Color.Green, q2); - - // Draw the third and fourth quad on second window - window2.FillQuad(Color.Red, q3); - window2.FillQuad(Color.Blue, q4); - - SplashKit.RefreshScreen(); - SplashKit.Delay(5000); - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace FillQuadOnWindowExample +{ + public class Program + { + public static void Main() + { + // Create diamond shaped quads + Quad q1 = SplashKit.QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); + Quad q2 = SplashKit.QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); + Quad q3 = SplashKit.QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); + Quad q4 = SplashKit.QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + + // Create two Windows + Window window1 = new Window("Filled Diamond On Window 1", 600, 600); + Window window2 = new Window("Filled Diamond On Window 2", 600, 600); + + // Move windows to see both side by side + window1.MoveTo(0, 0); + window2.MoveTo(window1.Width, 0); + + SplashKit.ClearScreen(Color.White); + + // Draw the first and second quad on first window + window1.FillQuad(Color.Black, q1); + window1.FillQuad(Color.Green, q2); + + // Draw the third and fourth quad on second window + window2.FillQuad(Color.Red, q3); + window2.FillQuad(Color.Blue, q4); + + SplashKit.RefreshScreen(); + SplashKit.Delay(5000); + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/fill_quad_on_window-1-example-top-level.cs b/public/usage-examples/graphics/fill_quad_on_window-1-example-top-level.cs index e54b80ff2..4a8a5edd4 100644 --- a/public/usage-examples/graphics/fill_quad_on_window-1-example-top-level.cs +++ b/public/usage-examples/graphics/fill_quad_on_window-1-example-top-level.cs @@ -1,30 +1,30 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Create diamond shaped quads -Quad q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); -Quad q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); -Quad q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); -Quad q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); - -// Create two Windows -Window window1 = OpenWindow("Filled Diamond On Window 1", 600, 600); -Window window2 = OpenWindow("Filled Diamond On Window 2", 600, 600); - -// Move windows to see both side by side -MoveWindowTo(window1, 0, 0); -MoveWindowTo(window2, WindowWidth(window1), 0); - -ClearScreen(ColorWhite()); - -// Draw the first and second quad on first window -FillQuadOnWindow(window1, ColorBlack(), q1); -FillQuadOnWindow(window1, ColorGreen(), q2); - -// Draw the third and fourth quad on second window -FillQuadOnWindow(window2, ColorRed(), q3); -FillQuadOnWindow(window2, ColorBlue(), q4); - -RefreshScreen(); -Delay(5000); -CloseAllWindows(); +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Create diamond shaped quads +Quad q1 = QuadFrom(400, 200, 300, 300, 300, 0, 200, 200); +Quad q2 = QuadFrom(400, 210, 310, 300, 600, 300, 400, 390); +Quad q3 = QuadFrom(200, 400, 300, 300, 300, 600, 400, 400); +Quad q4 = QuadFrom(200, 390, 290, 300, 0, 300, 200, 210); + +// Create two Windows +Window window1 = OpenWindow("Filled Diamond On Window 1", 600, 600); +Window window2 = OpenWindow("Filled Diamond On Window 2", 600, 600); + +// Move windows to see both side by side +MoveWindowTo(window1, 0, 0); +MoveWindowTo(window2, WindowWidth(window1), 0); + +ClearScreen(ColorWhite()); + +// Draw the first and second quad on first window +FillQuadOnWindow(window1, ColorBlack(), q1); +FillQuadOnWindow(window1, ColorGreen(), q2); + +// Draw the third and fourth quad on second window +FillQuadOnWindow(window2, ColorRed(), q3); +FillQuadOnWindow(window2, ColorBlue(), q4); + +RefreshScreen(); +Delay(5000); +CloseAllWindows(); diff --git a/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-oop.cs b/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-oop.cs index 5ef8ea12f..c3e8e8a1c 100644 --- a/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-oop.cs +++ b/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-oop.cs @@ -1,59 +1,59 @@ -using SplashKitSDK; - -namespace FillRectangleOnBitmapExample -{ - public class Program - { - public static void Main() - { - // Create a new window with title and dimensions - SplashKit.OpenWindow("Night Sky", 500, 533); - // Create and load new bitmap using the picture file and initialise new bitmap variable - Bitmap night_sky = SplashKit.LoadBitmap("night_sky", "sky.jpg"); - - // Create black rectangles for buildings, with x and y axis and dimensions - SplashKit.FillRectangleOnBitmap(night_sky, Color.Black, 40, 200, 100, 400); // Building 1 - SplashKit.FillRectangleOnBitmap(night_sky, Color.Black, 200, 400, 100, 400); // Building 2 - SplashKit.FillRectangleOnBitmap(night_sky, Color.Black, 350, 300, 100, 300); // Building 3 - - // For loop to create the illumimated windows on each building with different numbers depending - // on the placement of the building - // Building 1 - for (int j = 220; j < 700; j += 50) - { - for (int i = 55; i < 135; i += 20) - { - SplashKit.FillRectangleOnBitmap(night_sky, Color.Orange, i, j, 10, 20); - } - } - - // Building 2 - for (int j = 420; j < 570; j += 50) - { - for (int i = 215; i < 295; i += 20) - { - SplashKit.FillRectangleOnBitmap(night_sky, Color.Yellow, i, j, 10, 20); - } - } - - // Building 3 - for (int j = 320; j < 700; j += 50) - { - for (int i = 365; i < 440; i += 20) - { - SplashKit.FillRectangleOnBitmap(night_sky, Color.Orange, i, j, 10, 20); - } - } - - // Clear screen and draw bitmap - SplashKit.ClearScreen(); - SplashKit.DrawBitmap(night_sky, 0, 0); - SplashKit.RefreshScreen(); - SplashKit.Delay(5000); - - // Free resources and close window/s - SplashKit.FreeAllBitmaps(); - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace FillRectangleOnBitmapExample +{ + public class Program + { + public static void Main() + { + // Create a new window with title and dimensions + SplashKit.OpenWindow("Night Sky", 500, 533); + // Create and load new bitmap using the picture file and initialise new bitmap variable + Bitmap night_sky = SplashKit.LoadBitmap("night_sky", "sky.jpg"); + + // Create black rectangles for buildings, with x and y axis and dimensions + SplashKit.FillRectangleOnBitmap(night_sky, Color.Black, 40, 200, 100, 400); // Building 1 + SplashKit.FillRectangleOnBitmap(night_sky, Color.Black, 200, 400, 100, 400); // Building 2 + SplashKit.FillRectangleOnBitmap(night_sky, Color.Black, 350, 300, 100, 300); // Building 3 + + // For loop to create the illumimated windows on each building with different numbers depending + // on the placement of the building + // Building 1 + for (int j = 220; j < 700; j += 50) + { + for (int i = 55; i < 135; i += 20) + { + SplashKit.FillRectangleOnBitmap(night_sky, Color.Orange, i, j, 10, 20); + } + } + + // Building 2 + for (int j = 420; j < 570; j += 50) + { + for (int i = 215; i < 295; i += 20) + { + SplashKit.FillRectangleOnBitmap(night_sky, Color.Yellow, i, j, 10, 20); + } + } + + // Building 3 + for (int j = 320; j < 700; j += 50) + { + for (int i = 365; i < 440; i += 20) + { + SplashKit.FillRectangleOnBitmap(night_sky, Color.Orange, i, j, 10, 20); + } + } + + // Clear screen and draw bitmap + SplashKit.ClearScreen(); + SplashKit.DrawBitmap(night_sky, 0, 0); + SplashKit.RefreshScreen(); + SplashKit.Delay(5000); + + // Free resources and close window/s + SplashKit.FreeAllBitmaps(); + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-top-level.cs b/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-top-level.cs index 967014fae..99c086dff 100644 --- a/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-top-level.cs +++ b/public/usage-examples/graphics/fill_rectangle_on_bitmap-1-example-top-level.cs @@ -1,51 +1,51 @@ -using static SplashKitSDK.SplashKit; - -// Create a new window with title and dimensions -OpenWindow("Night Sky", 500, 533); - -// Create and load new bitmap using the picture file and initialise new bitmap variable -SplashKitSDK.Bitmap night_sky = LoadBitmap("night_sky", "sky.jpg"); - -// Create black rectangles for buildings, with x and y axis and dimensions -FillRectangleOnBitmap(night_sky, ColorBlack(), 40, 200, 100, 400); //Building 1 -FillRectangleOnBitmap(night_sky, ColorBlack(), 200, 400, 100, 400); // Building 2 -FillRectangleOnBitmap(night_sky, ColorBlack(), 350, 300, 100, 300); // Building 3 - -// For loop to create the illumimated windows on each building with different numbers depending -// on the placement of the building -// Building 1 -for (int j = 220; j < 700; j += 50) -{ - for (int i = 55; i < 135; i += 20) - { - FillRectangleOnBitmap(night_sky, ColorOrange(), i, j, 10, 20); - } -} - -// Building 2 -for (int j = 420; j < 570; j += 50) -{ - for (int i = 215; i < 295; i += 20) - { - FillRectangleOnBitmap(night_sky, ColorYellow(), i, j, 10, 20); - } -} - -// Building 3 -for (int j = 320; j < 700; j += 50) -{ - for (int i = 365; i < 440; i += 20) - { - FillRectangleOnBitmap(night_sky, ColorOrange(), i, j, 10, 20); - } -} - -// Clear screen and draw bitmap -ClearScreen(); -DrawBitmap(night_sky, 0, 0); -RefreshScreen(); -Delay(5000); - -// Free resources and close windows -FreeAllBitmaps(); +using static SplashKitSDK.SplashKit; + +// Create a new window with title and dimensions +OpenWindow("Night Sky", 500, 533); + +// Create and load new bitmap using the picture file and initialise new bitmap variable +SplashKitSDK.Bitmap night_sky = LoadBitmap("night_sky", "sky.jpg"); + +// Create black rectangles for buildings, with x and y axis and dimensions +FillRectangleOnBitmap(night_sky, ColorBlack(), 40, 200, 100, 400); //Building 1 +FillRectangleOnBitmap(night_sky, ColorBlack(), 200, 400, 100, 400); // Building 2 +FillRectangleOnBitmap(night_sky, ColorBlack(), 350, 300, 100, 300); // Building 3 + +// For loop to create the illumimated windows on each building with different numbers depending +// on the placement of the building +// Building 1 +for (int j = 220; j < 700; j += 50) +{ + for (int i = 55; i < 135; i += 20) + { + FillRectangleOnBitmap(night_sky, ColorOrange(), i, j, 10, 20); + } +} + +// Building 2 +for (int j = 420; j < 570; j += 50) +{ + for (int i = 215; i < 295; i += 20) + { + FillRectangleOnBitmap(night_sky, ColorYellow(), i, j, 10, 20); + } +} + +// Building 3 +for (int j = 320; j < 700; j += 50) +{ + for (int i = 365; i < 440; i += 20) + { + FillRectangleOnBitmap(night_sky, ColorOrange(), i, j, 10, 20); + } +} + +// Clear screen and draw bitmap +ClearScreen(); +DrawBitmap(night_sky, 0, 0); +RefreshScreen(); +Delay(5000); + +// Free resources and close windows +FreeAllBitmaps(); CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/graphics/free_font-1-example-oop.cs b/public/usage-examples/graphics/free_font-1-example-oop.cs index 7a79707c5..33f67ff9c 100644 --- a/public/usage-examples/graphics/free_font-1-example-oop.cs +++ b/public/usage-examples/graphics/free_font-1-example-oop.cs @@ -1,51 +1,51 @@ -using SplashKitSDK; - -namespace FreeFontExample -{ - public class Program - { - public static void Main() - { - SplashKit.OpenWindow("Freeing Fonts", 800, 200); - Font bebasNeue = SplashKit.LoadFont("BebasNeue", "BebasNeue.ttf"); - - while (!SplashKit.QuitRequested()) - { - SplashKit.ProcessEvents(); - - SplashKit.ClearScreen(); - if (SplashKit.HasFont(bebasNeue)) - { - SplashKit.DrawText("Using BebasNeue Font: Press Space bar to free font", Color.Black, bebasNeue, 30, 20, 50); - } - else - { - SplashKit.DrawText("Using System Font: BebasNeue font has been freed", Color.Black, SplashKit.GetSystemFont(), 30, 20, 50); - SplashKit.DrawText("Press Space bar to load BebasNeue font again", Color.Black, SplashKit.GetSystemFont(), 30, 20, 100); - } - SplashKit.RefreshScreen(); - - if (SplashKit.KeyTyped(KeyCode.SpaceKey)) - { - // If the font is loaded, it is freed - // If the font has been free, it is loaded again - if (SplashKit.HasFont(bebasNeue)) - { - SplashKit.FreeFont(bebasNeue); - } - else - { - bebasNeue = SplashKit.LoadFont("BebasNeue", "BebasNeue.ttf"); - } - } - } - - // Clean up - if (SplashKit.HasFont(bebasNeue)) - { - SplashKit.FreeFont(bebasNeue); - } - SplashKit.CloseAllWindows(); - } - } +using SplashKitSDK; + +namespace FreeFontExample +{ + public class Program + { + public static void Main() + { + SplashKit.OpenWindow("Freeing Fonts", 800, 200); + Font bebasNeue = SplashKit.LoadFont("BebasNeue", "BebasNeue.ttf"); + + while (!SplashKit.QuitRequested()) + { + SplashKit.ProcessEvents(); + + SplashKit.ClearScreen(); + if (SplashKit.HasFont(bebasNeue)) + { + SplashKit.DrawText("Using BebasNeue Font: Press Space bar to free font", Color.Black, bebasNeue, 30, 20, 50); + } + else + { + SplashKit.DrawText("Using System Font: BebasNeue font has been freed", Color.Black, SplashKit.GetSystemFont(), 30, 20, 50); + SplashKit.DrawText("Press Space bar to load BebasNeue font again", Color.Black, SplashKit.GetSystemFont(), 30, 20, 100); + } + SplashKit.RefreshScreen(); + + if (SplashKit.KeyTyped(KeyCode.SpaceKey)) + { + // If the font is loaded, it is freed + // If the font has been free, it is loaded again + if (SplashKit.HasFont(bebasNeue)) + { + SplashKit.FreeFont(bebasNeue); + } + else + { + bebasNeue = SplashKit.LoadFont("BebasNeue", "BebasNeue.ttf"); + } + } + } + + // Clean up + if (SplashKit.HasFont(bebasNeue)) + { + SplashKit.FreeFont(bebasNeue); + } + SplashKit.CloseAllWindows(); + } + } } \ No newline at end of file diff --git a/public/usage-examples/graphics/free_font-1-example-top-level.cs b/public/usage-examples/graphics/free_font-1-example-top-level.cs index 3e900dcc0..05017bb85 100644 --- a/public/usage-examples/graphics/free_font-1-example-top-level.cs +++ b/public/usage-examples/graphics/free_font-1-example-top-level.cs @@ -1,43 +1,43 @@ -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -OpenWindow("Freeing Fonts", 800, 200); -Font bebasNeue = LoadFont("BebasNeue", "BebasNeue.ttf"); - -while (!QuitRequested()) -{ - ProcessEvents(); - - ClearScreen(); - if (HasFont(bebasNeue)) - { - DrawText("Using BebasNeue Font: Press Space bar to free font", ColorBlack(), bebasNeue, 30, 20, 50); - } - else - { - DrawText("Using System Font: BebasNeue font has been freed", ColorBlack(), GetSystemFont(), 30, 20, 50); - DrawText("Press Space bar to load BebasNeue font again", ColorBlack(), GetSystemFont(), 30, 20, 100); - } - RefreshScreen(); - - if (KeyTyped(KeyCode.SpaceKey)) - { - // If the font is loaded, it is freed - // If the font has been free, it is loaded again - if (HasFont(bebasNeue)) - { - FreeFont(bebasNeue); - } - else - { - bebasNeue = LoadFont("BebasNeue", "BebasNeue.ttf"); - } - } -} - -// Clean up -if (HasFont(bebasNeue)) -{ - FreeFont(bebasNeue); -} +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +OpenWindow("Freeing Fonts", 800, 200); +Font bebasNeue = LoadFont("BebasNeue", "BebasNeue.ttf"); + +while (!QuitRequested()) +{ + ProcessEvents(); + + ClearScreen(); + if (HasFont(bebasNeue)) + { + DrawText("Using BebasNeue Font: Press Space bar to free font", ColorBlack(), bebasNeue, 30, 20, 50); + } + else + { + DrawText("Using System Font: BebasNeue font has been freed", ColorBlack(), GetSystemFont(), 30, 20, 50); + DrawText("Press Space bar to load BebasNeue font again", ColorBlack(), GetSystemFont(), 30, 20, 100); + } + RefreshScreen(); + + if (KeyTyped(KeyCode.SpaceKey)) + { + // If the font is loaded, it is freed + // If the font has been free, it is loaded again + if (HasFont(bebasNeue)) + { + FreeFont(bebasNeue); + } + else + { + bebasNeue = LoadFont("BebasNeue", "BebasNeue.ttf"); + } + } +} + +// Clean up +if (HasFont(bebasNeue)) +{ + FreeFont(bebasNeue); +} CloseAllWindows(); \ No newline at end of file diff --git a/public/usage-examples/terminal/write_line-1-example-oop.cs b/public/usage-examples/terminal/write_line-1-example-oop.cs index 7bdcfbc63..1e822bf21 100644 --- a/public/usage-examples/terminal/write_line-1-example-oop.cs +++ b/public/usage-examples/terminal/write_line-1-example-oop.cs @@ -1,22 +1,22 @@ -using SplashKitSDK; - -namespace WriteLine -{ - public class Program - { - public static void Main() - { - // Example 1: Print explicit string - SplashKit.WriteLine("Hello World"); - - // Example 2: Print value of string variable - string message = "Hello World from 'message' variable"; - SplashKit.WriteLine(message); - - // Example 3: Print combination of explicit string and value of string variable - string hello = "Hello"; - SplashKit.WriteLine(hello + " World!\nDon't forget spaces between words when printing to the terminal!"); - SplashKit.WriteLine("Otherwise you get this: " + hello + "World!"); - } - } +using SplashKitSDK; + +namespace WriteLine +{ + public class Program + { + public static void Main() + { + // Example 1: Print explicit string + SplashKit.WriteLine("Hello World"); + + // Example 2: Print value of string variable + string message = "Hello World from 'message' variable"; + SplashKit.WriteLine(message); + + // Example 3: Print combination of explicit string and value of string variable + string hello = "Hello"; + SplashKit.WriteLine(hello + " World!\nDon't forget spaces between words when printing to the terminal!"); + SplashKit.WriteLine("Otherwise you get this: " + hello + "World!"); + } + } } \ No newline at end of file diff --git a/public/usage-examples/terminal/write_line-1-example-top-level.cs b/public/usage-examples/terminal/write_line-1-example-top-level.cs index b6630c1ea..fea55150b 100644 --- a/public/usage-examples/terminal/write_line-1-example-top-level.cs +++ b/public/usage-examples/terminal/write_line-1-example-top-level.cs @@ -1,13 +1,13 @@ -using static SplashKitSDK.SplashKit; - -// Example 1: Print explicit string -WriteLine("Hello World"); - -// Example 2: Print value of string variable -string message = "Hello World from 'message' variable"; -WriteLine(message); - -// Example 3: Print combination of explicit string and value of string variable -string hello = "Hello"; -WriteLine(hello + " World!\nDon't forget spaces between words when printing to the terminal!"); +using static SplashKitSDK.SplashKit; + +// Example 1: Print explicit string +WriteLine("Hello World"); + +// Example 2: Print value of string variable +string message = "Hello World from 'message' variable"; +WriteLine(message); + +// Example 3: Print combination of explicit string and value of string variable +string hello = "Hello"; +WriteLine(hello + " World!\nDon't forget spaces between words when printing to the terminal!"); WriteLine("Otherwise you get this: " + hello + "World!"); \ No newline at end of file diff --git a/public/usage-examples/terminal/write_line-2-example-oop.cs b/public/usage-examples/terminal/write_line-2-example-oop.cs index 39dc28666..57254e053 100644 --- a/public/usage-examples/terminal/write_line-2-example-oop.cs +++ b/public/usage-examples/terminal/write_line-2-example-oop.cs @@ -1,67 +1,67 @@ -using SplashKitSDK; - -namespace WriteLine -{ - public class Program - { - public static void Main() - { - SplashKit.WriteLine(""); - SplashKit.WriteLine("CHARRRLLIIEEEE! WE'RE GOING TO CANDY MOUNTAIN CHARLIE!"); - SplashKit.WriteLine(""); - SplashKit.WriteLine(""); - SplashKit.WriteLine(" ###@ "); - SplashKit.WriteLine(" %% #*=# "); - SplashKit.WriteLine(" @#*# ##*-*% "); - SplashKit.WriteLine(" #+*% %**%+--#% "); - SplashKit.WriteLine(" %#=-#% %%###*++::+@ "); - SplashKit.WriteLine(" %#*%#=:+%@ @%#*+==+++-:-*% "); - SplashKit.WriteLine(" @%%#*+*-:-#% @%#+=========-::*% "); - SplashKit.WriteLine(" @%#*++=+**=::=%@@%*================*@ "); - SplashKit.WriteLine(" %%#++++=====-::-%%#*+====-===++===+==+-*@ "); - SplashKit.WriteLine(" @%#+==+==========-=-#*+=======-+*++====----+% "); - SplashKit.WriteLine(" @#*+=========+====+--++#*==-==--=+*+++====----+% %%@ "); - SplashKit.WriteLine(" @@#++==+=======++++====+---%*=-=--===#%#*++===----:* @#%@ "); - SplashKit.WriteLine(" @%*+=============*++++====----**=-----*@ @@@@%#**=---+# @=%% "); - SplashKit.WriteLine(" @%++===============***++=====----*#=-==+% @@%#+*+=*@ @++% "); - SplashKit.WriteLine(" #%%##**++====++*#%%#+++======--===-===*%%%#*++==-----+%+==#@ @%#+*@ #-*% "); - SplashKit.WriteLine("====------:::::=#*+========---===--===+%#*#%@@%#**+-===*#+*@ @@ @--%% "); - SplashKit.WriteLine("+====----:::=#%*--==========----=-====%#*+===+#@@#**=-=###@ %*:-%% "); - SplashKit.WriteLine("+===----=*%%+=--------=-------=======#%*+=-----=+%%#**%%#%@ #::+%%%%% "); - SplashKit.WriteLine("#***#%@%*====-----------------======*%#*+=----::--+####*#@ #=:-*@@+*@ "); - SplashKit.WriteLine("-:---:----====-::--::::::----=-====+%#*+=-------:::-=++*%@ @+::=*%*+%% "); - SplashKit.WriteLine("-::::--------==-------::::::----===#%*+==----==-------=#@ @%=::--=**#%% "); - SplashKit.WriteLine("-:::::--:-----==------::::::::--==+@*+==-----==-------=%@ @#-:-=*+--=***%@ "); - SplashKit.WriteLine("-::::::::::---==--=-----::::::---=##*+====------------+@ @%#=:=##==++++++++#%%% "); - SplashKit.WriteLine("-::::::::::-::-==----==---:::----*%**+=====---------==#@ @#=::---==:-*+++++++*++*%%%%%%@%% "); - SplashKit.WriteLine("-:---:---::::--==----====-------=%#*+==+++=====---===+% @%+---------=++++++++++++------=====+*#%%%%%@@@@ "); - SplashKit.WriteLine("------------------=---===-------+%#*++++***+========+%@ @#+---==--======+++++++++++=-------=------=====++++**##%%%@ "); - SplashKit.WriteLine("---------------=====-----=---===*@%#*****#***++===+%@ @=:++++====-====+++++++**+++++===---=------=---------------=+%%%@ "); - SplashKit.WriteLine("===------------=====---------===%@@%%%%%%%#*+==--+% #:-+======++++=+++***++*+++++=+===+=========-==--------:-------=*#%%# "); - SplashKit.WriteLine("+===============+++======-=====*@@@@@@@@ @%*+===-*@ *--+*+==++**###********+++++==+====+++=========--------::::-------=+%@% @%%@%%####%%%%%###* "); - SplashKit.WriteLine("+++++===========+***+=========*%@ %*+====#@ @@@@@%#%%@@@@@@@@@@@@%#**+++*++======+===========-::::::::---::-----==*%%%%## #%%@@%%#*=-::::::::::----=+*#"); - SplashKit.WriteLine("*******++++++++++*#**++++===*%@ %#*===+@ @@%%%%######*#*#*#%%@@@#*+++++++==============--::::::::----::---==-----=+*******+==-::::::::::::::::---------"); - SplashKit.WriteLine("###############**###*++==-=#@ %#*==+%% %@%#*++++=++============-::::::::-------=----------::::::::::::::::::::::::::----------="); - SplashKit.WriteLine("@@@@@%%%%%%%%@@@@@@#*++==-=%@ %#*==+@ @@@%#*++=++==========:::::::::::-------------:::::::::::::::::::::::::::::-----------="); - SplashKit.WriteLine("#***##*#@% @%*+++==*@ %#+=-+@ %%@%#+++*+=======-::::::::--------==-----::::::::::::::::::::::::::---------------="); - SplashKit.WriteLine("%**==++=#@ @%**++==#@ %#+--*@ %@%**++++++++-::::::::---------=--::---:::::::::::::::::::::::::::::-----------="); - SplashKit.WriteLine(" %*=-=*--%@ %#*=++*@ %%*==% @@%#*+++*+=--::::-------------------::::::::::::::::::----:::::::------------="); - SplashKit.WriteLine(" #*--#+:=%@ @#*=++%@ @#*=+% @@%***+=--::::------------=------:---------------------::::::-------------=="); - SplashKit.WriteLine(" @#+-=*=:=%@ @#*==+@% %#+-+% @#==--===------------------------------------------------:::---------========"); - SplashKit.WriteLine(" %*=:=+=:+@ @*+--+@ %#+-=# @--=-=-------------------------------------------------=-::---------=========+"); - SplashKit.WriteLine(" #+-:=++%% @*+--*% %*=-+% @+----==+=----::-----------==----------------------======-:--------=========+++"); - SplashKit.WriteLine(" %#=----#%# @#*==#@ %*+-=# @#--++======-:::::--------------------==----============+=-------=====++++++++++"); - SplashKit.WriteLine(" %*===+*%# @#*=+% @#+-+#%% #=-*##%+==-----:::--------==--====================+++++++==-------=+++++++++++++"); - SplashKit.WriteLine(" @*=-=%@#### @#+=*@ %#=:+%%% @@=-**#@@%+=------:-------=======================++++++++*#*++=-------=+**********"); - SplashKit.WriteLine(" **++*#@### @*+-+% @%%%%%%% @+:-+*#@@@#%+=-----:----=====++===+++++++=====++++++**********+**=------=+*******##"); - SplashKit.WriteLine(" %%%##%%## %*=-+% %@@@@@@ @+:-+**==-+#%@*=--------==+*****+++++****++++*****************###**+==----==*#####% "); - SplashKit.WriteLine(" %#%%%## @%*=-+@ @#:=****--:+%%%@#==-----=++*********###################**####%@@@@%**#+=----===+# "); - SplashKit.WriteLine(" %*+--*% @#:-=+#%@%#*#%%%%%%+===+++*****#%%%%%%%%%%%%%%#######%%%%%%#==+%@+--=+****+---===+* "); - SplashKit.WriteLine(" @#=-*%%%% %++***%@%#%@@@@@@%%%%#*+++****#%@@@%%%%%%%@@@@@%%%@@@@@@@%%*---=+#@%##***++=--=====* "); - SplashKit.WriteLine(" %*=:*@@@ @#%%%%%%%@ @@%#####%@% %%%%%%% %%@*--------------==++=====%@ "); - SplashKit.WriteLine(" @@%%%%%%@ %%%%%#%%%@ @@@@@@ *=---=========---=====+*%@ "); - SplashKit.WriteLine(" %@@@@@@ @%%#%%@@% *=========+*#%%@@@@@@@@%% "); - SplashKit.WriteLine(" @%%%%@%# ++*%@@@@@%%% "); - } - } +using SplashKitSDK; + +namespace WriteLine +{ + public class Program + { + public static void Main() + { + SplashKit.WriteLine(""); + SplashKit.WriteLine("CHARRRLLIIEEEE! WE'RE GOING TO CANDY MOUNTAIN CHARLIE!"); + SplashKit.WriteLine(""); + SplashKit.WriteLine(""); + SplashKit.WriteLine(" ###@ "); + SplashKit.WriteLine(" %% #*=# "); + SplashKit.WriteLine(" @#*# ##*-*% "); + SplashKit.WriteLine(" #+*% %**%+--#% "); + SplashKit.WriteLine(" %#=-#% %%###*++::+@ "); + SplashKit.WriteLine(" %#*%#=:+%@ @%#*+==+++-:-*% "); + SplashKit.WriteLine(" @%%#*+*-:-#% @%#+=========-::*% "); + SplashKit.WriteLine(" @%#*++=+**=::=%@@%*================*@ "); + SplashKit.WriteLine(" %%#++++=====-::-%%#*+====-===++===+==+-*@ "); + SplashKit.WriteLine(" @%#+==+==========-=-#*+=======-+*++====----+% "); + SplashKit.WriteLine(" @#*+=========+====+--++#*==-==--=+*+++====----+% %%@ "); + SplashKit.WriteLine(" @@#++==+=======++++====+---%*=-=--===#%#*++===----:* @#%@ "); + SplashKit.WriteLine(" @%*+=============*++++====----**=-----*@ @@@@%#**=---+# @=%% "); + SplashKit.WriteLine(" @%++===============***++=====----*#=-==+% @@%#+*+=*@ @++% "); + SplashKit.WriteLine(" #%%##**++====++*#%%#+++======--===-===*%%%#*++==-----+%+==#@ @%#+*@ #-*% "); + SplashKit.WriteLine("====------:::::=#*+========---===--===+%#*#%@@%#**+-===*#+*@ @@ @--%% "); + SplashKit.WriteLine("+====----:::=#%*--==========----=-====%#*+===+#@@#**=-=###@ %*:-%% "); + SplashKit.WriteLine("+===----=*%%+=--------=-------=======#%*+=-----=+%%#**%%#%@ #::+%%%%% "); + SplashKit.WriteLine("#***#%@%*====-----------------======*%#*+=----::--+####*#@ #=:-*@@+*@ "); + SplashKit.WriteLine("-:---:----====-::--::::::----=-====+%#*+=-------:::-=++*%@ @+::=*%*+%% "); + SplashKit.WriteLine("-::::--------==-------::::::----===#%*+==----==-------=#@ @%=::--=**#%% "); + SplashKit.WriteLine("-:::::--:-----==------::::::::--==+@*+==-----==-------=%@ @#-:-=*+--=***%@ "); + SplashKit.WriteLine("-::::::::::---==--=-----::::::---=##*+====------------+@ @%#=:=##==++++++++#%%% "); + SplashKit.WriteLine("-::::::::::-::-==----==---:::----*%**+=====---------==#@ @#=::---==:-*+++++++*++*%%%%%%@%% "); + SplashKit.WriteLine("-:---:---::::--==----====-------=%#*+==+++=====---===+% @%+---------=++++++++++++------=====+*#%%%%%@@@@ "); + SplashKit.WriteLine("------------------=---===-------+%#*++++***+========+%@ @#+---==--======+++++++++++=-------=------=====++++**##%%%@ "); + SplashKit.WriteLine("---------------=====-----=---===*@%#*****#***++===+%@ @=:++++====-====+++++++**+++++===---=------=---------------=+%%%@ "); + SplashKit.WriteLine("===------------=====---------===%@@%%%%%%%#*+==--+% #:-+======++++=+++***++*+++++=+===+=========-==--------:-------=*#%%# "); + SplashKit.WriteLine("+===============+++======-=====*@@@@@@@@ @%*+===-*@ *--+*+==++**###********+++++==+====+++=========--------::::-------=+%@% @%%@%%####%%%%%###* "); + SplashKit.WriteLine("+++++===========+***+=========*%@ %*+====#@ @@@@@%#%%@@@@@@@@@@@@%#**+++*++======+===========-::::::::---::-----==*%%%%## #%%@@%%#*=-::::::::::----=+*#"); + SplashKit.WriteLine("*******++++++++++*#**++++===*%@ %#*===+@ @@%%%%######*#*#*#%%@@@#*+++++++==============--::::::::----::---==-----=+*******+==-::::::::::::::::---------"); + SplashKit.WriteLine("###############**###*++==-=#@ %#*==+%% %@%#*++++=++============-::::::::-------=----------::::::::::::::::::::::::::----------="); + SplashKit.WriteLine("@@@@@%%%%%%%%@@@@@@#*++==-=%@ %#*==+@ @@@%#*++=++==========:::::::::::-------------:::::::::::::::::::::::::::::-----------="); + SplashKit.WriteLine("#***##*#@% @%*+++==*@ %#+=-+@ %%@%#+++*+=======-::::::::--------==-----::::::::::::::::::::::::::---------------="); + SplashKit.WriteLine("%**==++=#@ @%**++==#@ %#+--*@ %@%**++++++++-::::::::---------=--::---:::::::::::::::::::::::::::::-----------="); + SplashKit.WriteLine(" %*=-=*--%@ %#*=++*@ %%*==% @@%#*+++*+=--::::-------------------::::::::::::::::::----:::::::------------="); + SplashKit.WriteLine(" #*--#+:=%@ @#*=++%@ @#*=+% @@%***+=--::::------------=------:---------------------::::::-------------=="); + SplashKit.WriteLine(" @#+-=*=:=%@ @#*==+@% %#+-+% @#==--===------------------------------------------------:::---------========"); + SplashKit.WriteLine(" %*=:=+=:+@ @*+--+@ %#+-=# @--=-=-------------------------------------------------=-::---------=========+"); + SplashKit.WriteLine(" #+-:=++%% @*+--*% %*=-+% @+----==+=----::-----------==----------------------======-:--------=========+++"); + SplashKit.WriteLine(" %#=----#%# @#*==#@ %*+-=# @#--++======-:::::--------------------==----============+=-------=====++++++++++"); + SplashKit.WriteLine(" %*===+*%# @#*=+% @#+-+#%% #=-*##%+==-----:::--------==--====================+++++++==-------=+++++++++++++"); + SplashKit.WriteLine(" @*=-=%@#### @#+=*@ %#=:+%%% @@=-**#@@%+=------:-------=======================++++++++*#*++=-------=+**********"); + SplashKit.WriteLine(" **++*#@### @*+-+% @%%%%%%% @+:-+*#@@@#%+=-----:----=====++===+++++++=====++++++**********+**=------=+*******##"); + SplashKit.WriteLine(" %%%##%%## %*=-+% %@@@@@@ @+:-+**==-+#%@*=--------==+*****+++++****++++*****************###**+==----==*#####% "); + SplashKit.WriteLine(" %#%%%## @%*=-+@ @#:=****--:+%%%@#==-----=++*********###################**####%@@@@%**#+=----===+# "); + SplashKit.WriteLine(" %*+--*% @#:-=+#%@%#*#%%%%%%+===+++*****#%%%%%%%%%%%%%%#######%%%%%%#==+%@+--=+****+---===+* "); + SplashKit.WriteLine(" @#=-*%%%% %++***%@%#%@@@@@@%%%%#*+++****#%@@@%%%%%%%@@@@@%%%@@@@@@@%%*---=+#@%##***++=--=====* "); + SplashKit.WriteLine(" %*=:*@@@ @#%%%%%%%@ @@%#####%@% %%%%%%% %%@*--------------==++=====%@ "); + SplashKit.WriteLine(" @@%%%%%%@ %%%%%#%%%@ @@@@@@ *=---=========---=====+*%@ "); + SplashKit.WriteLine(" %@@@@@@ @%%#%%@@% *=========+*#%%@@@@@@@@%% "); + SplashKit.WriteLine(" @%%%%@%# ++*%@@@@@%%% "); + } + } } \ No newline at end of file diff --git a/public/usage-examples/terminal/write_line-2-example-top-level.cs b/public/usage-examples/terminal/write_line-2-example-top-level.cs index ccf5af1cd..dec3a962f 100644 --- a/public/usage-examples/terminal/write_line-2-example-top-level.cs +++ b/public/usage-examples/terminal/write_line-2-example-top-level.cs @@ -1,58 +1,58 @@ -using static SplashKitSDK.SplashKit; - -WriteLine(""); -WriteLine("CHARRRLLIIEEEE! WE'RE GOING TO CANDY MOUNTAIN CHARLIE!"); -WriteLine(""); -WriteLine(""); -WriteLine(" ###@ "); -WriteLine(" %% #*=# "); -WriteLine(" @#*# ##*-*% "); -WriteLine(" #+*% %**%+--#% "); -WriteLine(" %#=-#% %%###*++::+@ "); -WriteLine(" %#*%#=:+%@ @%#*+==+++-:-*% "); -WriteLine(" @%%#*+*-:-#% @%#+=========-::*% "); -WriteLine(" @%#*++=+**=::=%@@%*================*@ "); -WriteLine(" %%#++++=====-::-%%#*+====-===++===+==+-*@ "); -WriteLine(" @%#+==+==========-=-#*+=======-+*++====----+% "); -WriteLine(" @#*+=========+====+--++#*==-==--=+*+++====----+% %%@ "); -WriteLine(" @@#++==+=======++++====+---%*=-=--===#%#*++===----:* @#%@ "); -WriteLine(" @%*+=============*++++====----**=-----*@ @@@@%#**=---+# @=%% "); -WriteLine(" @%++===============***++=====----*#=-==+% @@%#+*+=*@ @++% "); -WriteLine(" #%%##**++====++*#%%#+++======--===-===*%%%#*++==-----+%+==#@ @%#+*@ #-*% "); -WriteLine("====------:::::=#*+========---===--===+%#*#%@@%#**+-===*#+*@ @@ @--%% "); -WriteLine("+====----:::=#%*--==========----=-====%#*+===+#@@#**=-=###@ %*:-%% "); -WriteLine("+===----=*%%+=--------=-------=======#%*+=-----=+%%#**%%#%@ #::+%%%%% "); -WriteLine("#***#%@%*====-----------------======*%#*+=----::--+####*#@ #=:-*@@+*@ "); -WriteLine("-:---:----====-::--::::::----=-====+%#*+=-------:::-=++*%@ @+::=*%*+%% "); -WriteLine("-::::--------==-------::::::----===#%*+==----==-------=#@ @%=::--=**#%% "); -WriteLine("-:::::--:-----==------::::::::--==+@*+==-----==-------=%@ @#-:-=*+--=***%@ "); -WriteLine("-::::::::::---==--=-----::::::---=##*+====------------+@ @%#=:=##==++++++++#%%% "); -WriteLine("-::::::::::-::-==----==---:::----*%**+=====---------==#@ @#=::---==:-*+++++++*++*%%%%%%@%% "); -WriteLine("-:---:---::::--==----====-------=%#*+==+++=====---===+% @%+---------=++++++++++++------=====+*#%%%%%@@@@ "); -WriteLine("------------------=---===-------+%#*++++***+========+%@ @#+---==--======+++++++++++=-------=------=====++++**##%%%@ "); -WriteLine("---------------=====-----=---===*@%#*****#***++===+%@ @=:++++====-====+++++++**+++++===---=------=---------------=+%%%@ "); -WriteLine("===------------=====---------===%@@%%%%%%%#*+==--+% #:-+======++++=+++***++*+++++=+===+=========-==--------:-------=*#%%# "); -WriteLine("+===============+++======-=====*@@@@@@@@ @%*+===-*@ *--+*+==++**###********+++++==+====+++=========--------::::-------=+%@% @%%@%%####%%%%%###* "); -WriteLine("+++++===========+***+=========*%@ %*+====#@ @@@@@%#%%@@@@@@@@@@@@%#**+++*++======+===========-::::::::---::-----==*%%%%## #%%@@%%#*=-::::::::::----=+*#"); -WriteLine("*******++++++++++*#**++++===*%@ %#*===+@ @@%%%%######*#*#*#%%@@@#*+++++++==============--::::::::----::---==-----=+*******+==-::::::::::::::::---------"); -WriteLine("###############**###*++==-=#@ %#*==+%% %@%#*++++=++============-::::::::-------=----------::::::::::::::::::::::::::----------="); -WriteLine("@@@@@%%%%%%%%@@@@@@#*++==-=%@ %#*==+@ @@@%#*++=++==========:::::::::::-------------:::::::::::::::::::::::::::::-----------="); -WriteLine("#***##*#@% @%*+++==*@ %#+=-+@ %%@%#+++*+=======-::::::::--------==-----::::::::::::::::::::::::::---------------="); -WriteLine("%**==++=#@ @%**++==#@ %#+--*@ %@%**++++++++-::::::::---------=--::---:::::::::::::::::::::::::::::-----------="); -WriteLine(" %*=-=*--%@ %#*=++*@ %%*==% @@%#*+++*+=--::::-------------------::::::::::::::::::----:::::::------------="); -WriteLine(" #*--#+:=%@ @#*=++%@ @#*=+% @@%***+=--::::------------=------:---------------------::::::-------------=="); -WriteLine(" @#+-=*=:=%@ @#*==+@% %#+-+% @#==--===------------------------------------------------:::---------========"); -WriteLine(" %*=:=+=:+@ @*+--+@ %#+-=# @--=-=-------------------------------------------------=-::---------=========+"); -WriteLine(" #+-:=++%% @*+--*% %*=-+% @+----==+=----::-----------==----------------------======-:--------=========+++"); -WriteLine(" %#=----#%# @#*==#@ %*+-=# @#--++======-:::::--------------------==----============+=-------=====++++++++++"); -WriteLine(" %*===+*%# @#*=+% @#+-+#%% #=-*##%+==-----:::--------==--====================+++++++==-------=+++++++++++++"); -WriteLine(" @*=-=%@#### @#+=*@ %#=:+%%% @@=-**#@@%+=------:-------=======================++++++++*#*++=-------=+**********"); -WriteLine(" **++*#@### @*+-+% @%%%%%%% @+:-+*#@@@#%+=-----:----=====++===+++++++=====++++++**********+**=------=+*******##"); -WriteLine(" %%%##%%## %*=-+% %@@@@@@ @+:-+**==-+#%@*=--------==+*****+++++****++++*****************###**+==----==*#####% "); -WriteLine(" %#%%%## @%*=-+@ @#:=****--:+%%%@#==-----=++*********###################**####%@@@@%**#+=----===+# "); -WriteLine(" %*+--*% @#:-=+#%@%#*#%%%%%%+===+++*****#%%%%%%%%%%%%%%#######%%%%%%#==+%@+--=+****+---===+* "); -WriteLine(" @#=-*%%%% %++***%@%#%@@@@@@%%%%#*+++****#%@@@%%%%%%%@@@@@%%%@@@@@@@%%*---=+#@%##***++=--=====* "); -WriteLine(" %*=:*@@@ @#%%%%%%%@ @@%#####%@% %%%%%%% %%@*--------------==++=====%@ "); -WriteLine(" @@%%%%%%@ %%%%%#%%%@ @@@@@@ *=---=========---=====+*%@ "); -WriteLine(" %@@@@@@ @%%#%%@@% *=========+*#%%@@@@@@@@%% "); -WriteLine(" @%%%%@%# ++*%@@@@@%%% "); +using static SplashKitSDK.SplashKit; + +WriteLine(""); +WriteLine("CHARRRLLIIEEEE! WE'RE GOING TO CANDY MOUNTAIN CHARLIE!"); +WriteLine(""); +WriteLine(""); +WriteLine(" ###@ "); +WriteLine(" %% #*=# "); +WriteLine(" @#*# ##*-*% "); +WriteLine(" #+*% %**%+--#% "); +WriteLine(" %#=-#% %%###*++::+@ "); +WriteLine(" %#*%#=:+%@ @%#*+==+++-:-*% "); +WriteLine(" @%%#*+*-:-#% @%#+=========-::*% "); +WriteLine(" @%#*++=+**=::=%@@%*================*@ "); +WriteLine(" %%#++++=====-::-%%#*+====-===++===+==+-*@ "); +WriteLine(" @%#+==+==========-=-#*+=======-+*++====----+% "); +WriteLine(" @#*+=========+====+--++#*==-==--=+*+++====----+% %%@ "); +WriteLine(" @@#++==+=======++++====+---%*=-=--===#%#*++===----:* @#%@ "); +WriteLine(" @%*+=============*++++====----**=-----*@ @@@@%#**=---+# @=%% "); +WriteLine(" @%++===============***++=====----*#=-==+% @@%#+*+=*@ @++% "); +WriteLine(" #%%##**++====++*#%%#+++======--===-===*%%%#*++==-----+%+==#@ @%#+*@ #-*% "); +WriteLine("====------:::::=#*+========---===--===+%#*#%@@%#**+-===*#+*@ @@ @--%% "); +WriteLine("+====----:::=#%*--==========----=-====%#*+===+#@@#**=-=###@ %*:-%% "); +WriteLine("+===----=*%%+=--------=-------=======#%*+=-----=+%%#**%%#%@ #::+%%%%% "); +WriteLine("#***#%@%*====-----------------======*%#*+=----::--+####*#@ #=:-*@@+*@ "); +WriteLine("-:---:----====-::--::::::----=-====+%#*+=-------:::-=++*%@ @+::=*%*+%% "); +WriteLine("-::::--------==-------::::::----===#%*+==----==-------=#@ @%=::--=**#%% "); +WriteLine("-:::::--:-----==------::::::::--==+@*+==-----==-------=%@ @#-:-=*+--=***%@ "); +WriteLine("-::::::::::---==--=-----::::::---=##*+====------------+@ @%#=:=##==++++++++#%%% "); +WriteLine("-::::::::::-::-==----==---:::----*%**+=====---------==#@ @#=::---==:-*+++++++*++*%%%%%%@%% "); +WriteLine("-:---:---::::--==----====-------=%#*+==+++=====---===+% @%+---------=++++++++++++------=====+*#%%%%%@@@@ "); +WriteLine("------------------=---===-------+%#*++++***+========+%@ @#+---==--======+++++++++++=-------=------=====++++**##%%%@ "); +WriteLine("---------------=====-----=---===*@%#*****#***++===+%@ @=:++++====-====+++++++**+++++===---=------=---------------=+%%%@ "); +WriteLine("===------------=====---------===%@@%%%%%%%#*+==--+% #:-+======++++=+++***++*+++++=+===+=========-==--------:-------=*#%%# "); +WriteLine("+===============+++======-=====*@@@@@@@@ @%*+===-*@ *--+*+==++**###********+++++==+====+++=========--------::::-------=+%@% @%%@%%####%%%%%###* "); +WriteLine("+++++===========+***+=========*%@ %*+====#@ @@@@@%#%%@@@@@@@@@@@@%#**+++*++======+===========-::::::::---::-----==*%%%%## #%%@@%%#*=-::::::::::----=+*#"); +WriteLine("*******++++++++++*#**++++===*%@ %#*===+@ @@%%%%######*#*#*#%%@@@#*+++++++==============--::::::::----::---==-----=+*******+==-::::::::::::::::---------"); +WriteLine("###############**###*++==-=#@ %#*==+%% %@%#*++++=++============-::::::::-------=----------::::::::::::::::::::::::::----------="); +WriteLine("@@@@@%%%%%%%%@@@@@@#*++==-=%@ %#*==+@ @@@%#*++=++==========:::::::::::-------------:::::::::::::::::::::::::::::-----------="); +WriteLine("#***##*#@% @%*+++==*@ %#+=-+@ %%@%#+++*+=======-::::::::--------==-----::::::::::::::::::::::::::---------------="); +WriteLine("%**==++=#@ @%**++==#@ %#+--*@ %@%**++++++++-::::::::---------=--::---:::::::::::::::::::::::::::::-----------="); +WriteLine(" %*=-=*--%@ %#*=++*@ %%*==% @@%#*+++*+=--::::-------------------::::::::::::::::::----:::::::------------="); +WriteLine(" #*--#+:=%@ @#*=++%@ @#*=+% @@%***+=--::::------------=------:---------------------::::::-------------=="); +WriteLine(" @#+-=*=:=%@ @#*==+@% %#+-+% @#==--===------------------------------------------------:::---------========"); +WriteLine(" %*=:=+=:+@ @*+--+@ %#+-=# @--=-=-------------------------------------------------=-::---------=========+"); +WriteLine(" #+-:=++%% @*+--*% %*=-+% @+----==+=----::-----------==----------------------======-:--------=========+++"); +WriteLine(" %#=----#%# @#*==#@ %*+-=# @#--++======-:::::--------------------==----============+=-------=====++++++++++"); +WriteLine(" %*===+*%# @#*=+% @#+-+#%% #=-*##%+==-----:::--------==--====================+++++++==-------=+++++++++++++"); +WriteLine(" @*=-=%@#### @#+=*@ %#=:+%%% @@=-**#@@%+=------:-------=======================++++++++*#*++=-------=+**********"); +WriteLine(" **++*#@### @*+-+% @%%%%%%% @+:-+*#@@@#%+=-----:----=====++===+++++++=====++++++**********+**=------=+*******##"); +WriteLine(" %%%##%%## %*=-+% %@@@@@@ @+:-+**==-+#%@*=--------==+*****+++++****++++*****************###**+==----==*#####% "); +WriteLine(" %#%%%## @%*=-+@ @#:=****--:+%%%@#==-----=++*********###################**####%@@@@%**#+=----===+# "); +WriteLine(" %*+--*% @#:-=+#%@%#*#%%%%%%+===+++*****#%%%%%%%%%%%%%%#######%%%%%%#==+%@+--=+****+---===+* "); +WriteLine(" @#=-*%%%% %++***%@%#%@@@@@@%%%%#*+++****#%@@@%%%%%%%@@@@@%%%@@@@@@@%%*---=+#@%##***++=--=====* "); +WriteLine(" %*=:*@@@ @#%%%%%%%@ @@%#####%@% %%%%%%% %%@*--------------==++=====%@ "); +WriteLine(" @@%%%%%%@ %%%%%#%%%@ @@@@@@ *=---=========---=====+*%@ "); +WriteLine(" %@@@@@@ @%%#%%@@% *=========+*#%%@@@@@@@@%% "); +WriteLine(" @%%%%@%# ++*%@@@@@%%% "); diff --git a/public/usage-examples/terminal/write_line_int-1-example-oop.cs b/public/usage-examples/terminal/write_line_int-1-example-oop.cs index b80d7bc27..c7ce6af31 100644 --- a/public/usage-examples/terminal/write_line_int-1-example-oop.cs +++ b/public/usage-examples/terminal/write_line_int-1-example-oop.cs @@ -1,32 +1,32 @@ -using SplashKitSDK; - -namespace WriteLineIntExample -{ - public class Program - { - public static void Main() - { - // Example 1: Print single integer - SplashKit.WriteLine(1); - SplashKit.WriteLine(2); - SplashKit.WriteLine(3); - SplashKit.WriteLine(-1); - SplashKit.WriteLine(-2); - SplashKit.WriteLine(-3); - - // Example 2: Print multi-digit integer - SplashKit.WriteLine(12345); - SplashKit.WriteLine(953221311); - SplashKit.WriteLine(-165746); - - // Example 3: Print integer after calculation - int a = 222 - 111; - int b = 10 * 12; - int c = 100 / 5; - - SplashKit.WriteLine(a - b); - SplashKit.WriteLine(b); - SplashKit.WriteLine(c); - } - } -} +using SplashKitSDK; + +namespace WriteLineIntExample +{ + public class Program + { + public static void Main() + { + // Example 1: Print single integer + SplashKit.WriteLine(1); + SplashKit.WriteLine(2); + SplashKit.WriteLine(3); + SplashKit.WriteLine(-1); + SplashKit.WriteLine(-2); + SplashKit.WriteLine(-3); + + // Example 2: Print multi-digit integer + SplashKit.WriteLine(12345); + SplashKit.WriteLine(953221311); + SplashKit.WriteLine(-165746); + + // Example 3: Print integer after calculation + int a = 222 - 111; + int b = 10 * 12; + int c = 100 / 5; + + SplashKit.WriteLine(a - b); + SplashKit.WriteLine(b); + SplashKit.WriteLine(c); + } + } +} diff --git a/public/usage-examples/terminal/write_line_int-1-example-top-level.cs b/public/usage-examples/terminal/write_line_int-1-example-top-level.cs index 84e96e705..a07b0488f 100644 --- a/public/usage-examples/terminal/write_line_int-1-example-top-level.cs +++ b/public/usage-examples/terminal/write_line_int-1-example-top-level.cs @@ -1,23 +1,23 @@ -using static SplashKitSDK.SplashKit; - -// Example 1: Print single integer -WriteLine(1); -WriteLine(2); -WriteLine(3); -WriteLine(-1); -WriteLine(-2); -WriteLine(-3); - -// Example 2: Print multi-digit integer -WriteLine(12345); -WriteLine(953221311); -WriteLine(-165746); - -// Example 3: Print integer after calculation -int a = 222 - 111; -int b = 10 * 12; -int c = 100 / 5; - -WriteLine(a - b); -WriteLine(b); -WriteLine(c); +using static SplashKitSDK.SplashKit; + +// Example 1: Print single integer +WriteLine(1); +WriteLine(2); +WriteLine(3); +WriteLine(-1); +WriteLine(-2); +WriteLine(-3); + +// Example 2: Print multi-digit integer +WriteLine(12345); +WriteLine(953221311); +WriteLine(-165746); + +// Example 3: Print integer after calculation +int a = 222 - 111; +int b = 10 * 12; +int c = 100 / 5; + +WriteLine(a - b); +WriteLine(b); +WriteLine(c); diff --git a/scripts/api-pages-script.cjs b/scripts/api-pages-script.cjs index 9151bb6c4..4488b32b3 100644 --- a/scripts/api-pages-script.cjs +++ b/scripts/api-pages-script.cjs @@ -173,9 +173,9 @@ function extractEnumValues(signature, language) { let regex; if (language === 'cpp') { - regex = /(\w+)\s*=\s*\d+/g; // Handles the cpp pattern which has no dot in the name + regex = /(\w+)\s*=\s*/g; // Handles the cpp pattern which has no dot in the name } else { - regex = /(\w+\.\w+)\s*=\s*\d+/g; // Handles the other languages which have a dot in the name + regex = /(\w+\.\w+)\s*=\s*/g; // Handles the other languages which have a dot in the name } let match; @@ -382,23 +382,6 @@ function getUsageExampleContent(jsonData, categoryKey, groupName, functionKey) { } // Check for cpp files and generate nested tabs else if (lang == "cpp" && cppFiles.length > 0) { - mdxData += "\n \n"; - cppFiles.slice().reverse().forEach(file => { - if (file.includes(exampleKey)) { - if (file.includes("-sk")) { - mdxData += ` \n`; - mdxData += ` \n`; - mdxData += " \n"; - } - if (file.includes("-beyond")) { - mdxData += ` \n`; - mdxData += ` See the [Graphics](https://splashkit.io/beyond-splashkit/graphics/0-getting-started-with-graphics/#getting-started-without-splashkit) or [Audio](https://splashkit.io/beyond-splashkit/audio/0-sound-effects/#getting-started-without-splashkit) Beyond SplashKit guides for help compiling without SplashKit.\n`; - mdxData += ` \n`; - mdxData += " \n"; - } - } - }); - mdxData += " \n\n"; mdxData += " \n"; } else { @@ -562,9 +545,9 @@ for (const categoryKey in jsonData) { .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join(" "); const formattedLink = formattedFunctionName.toLowerCase().replace(/\s+/g, "-"); - + // Put {} symbol at the end of header if function has a usage example - const hasSymbol = (hasExampleInGroup || hasGuideInGroup) ? `  {</>}`: ""; + const hasSymbol = (hasExampleInGroup || hasGuideInGroup) ? `  {</>}` : ""; const formattedGroupLink = `${formattedLink}-functions`; mdxContent += `\n### [${formattedFunctionName}](#${formattedGroupLink})${hasSymbol} \\{#${formattedGroupLink}\\}\n\n`; @@ -598,7 +581,7 @@ for (const categoryKey in jsonData) { // Put bolded {} symbol at the end of heading link if function has a usage example const hasExample = usageExamples.some(example => example.endsWith(func.unique_global_name + "-1-example.txt")); - const hasGuide = guidesCategories.some((category) => category.some((guide) => guide.functions.includes(func.unique_global_name))); + const hasGuide = guidesCategories.some((category) => category.some((guide) => guide.functions.includes(func.unique_global_name))); if (hasExample || hasGuide) { mdxContent += "  {</>}"; @@ -623,12 +606,12 @@ for (const categoryKey in jsonData) { const formattedLink = formattedName3.toLowerCase().replace(/\s+/g, "-"); const formattedUniqueLink = func.unique_global_name.toLowerCase().replace(/_/g, "-"); const hasExample = usageExamples.some(example => example.endsWith(func.unique_global_name + "-1-example.txt")); - const hasGuide = guidesCategories.some((category) => category.some((guide) => guide.functions.includes(func.unique_global_name))); - + const hasGuide = guidesCategories.some((category) => category.some((guide) => guide.functions.includes(func.unique_global_name))); + // Put {} symbol at the end of headers of overloaded functions with usage example or else just keep empty const formattedName = isOverloaded - ? `\n#### [${functionName2}](#${formattedUniqueLink})${(hasExample || hasGuide) ? '  {</>}' : ''} \\{#${formattedUniqueLink}\\}` - : `\n### [${functionName2}](#${formattedLink})${(hasExample || hasGuide) ? '  {</>}' : ''}`; + ? `\n#### [${functionName2}](#${formattedUniqueLink})${(hasExample || hasGuide) ? '  {</>}' : ''} \\{#${formattedUniqueLink}\\}` + : `\n### [${functionName2}](#${formattedLink})${(hasExample || hasGuide) ? '  {</>}' : ''}`; // Replace type names in the description with formatted versions let description = func.description || ""; @@ -668,6 +651,7 @@ for (const categoryKey in jsonData) { // Add Parameters section only if there are parameters if (Object.keys(func.parameters).length > 0) { mdxContent += "**Parameters:**\n\n"; + mdxContent += `
\n\n`; mdxContent += "| Name | Type | Description |\n"; mdxContent += @@ -675,7 +659,10 @@ for (const categoryKey in jsonData) { for (const paramName in func.parameters) { const param = func.parameters[paramName]; - const paramType = typeMappings[param.type] || param.type; + let paramType = typeMappings[param.type] || param.type; + if (paramType == 'unsigned int') { + paramType = "`Unsigned Integer`"; + } let description2 = param.description || ""; for (const typeName in typeMappings) { const typeMapping = typeMappings[typeName]; @@ -701,12 +688,26 @@ for (const categoryKey in jsonData) { } mdxContent += "\n"; + mdxContent += `
\n\n`; } if (func.return.type == 'unsigned int') { mdxContent += "**Return Type:** Unsigned Integer\n\n"; } else if (func.return.type != 'void') { mdxContent += "**Return Type:** " + typeMappings[func.return.type] + "\n\n"; + + mdxContent += "*Returns:* "; + let returnDescription = func.return.description || ""; + for (const typeName in typeMappings) { + const typeMapping = typeMappings[typeName]; + + returnDescription = returnDescription.replace( + new RegExp(`\`\\b${typeName}\\b\``, "g"), + typeMapping + ); + } + + mdxContent += `${returnDescription}\n\n`; } mdxContent += "**Signatures:**\n\n"; diff --git a/scripts/json-files-script.cjs b/scripts/json-files-script.cjs index 68bc2ab4a..8523e17f7 100644 --- a/scripts/json-files-script.cjs +++ b/scripts/json-files-script.cjs @@ -14,7 +14,7 @@ const path = require('path'); // Handle and transform file paths // Paths constants // ------------------------------------------------------------------------------ const guidesDir = './src/content/docs/guides'; // Path to base directory containing the "Guides" groups -const beyondDir = './src/content/docs/beyond-splashkit'; // Path to base directory containing the "Beyond SplashKit" groups +const beyondDir = './src/content/docs/guides/beyond-splashkit'; // Path to base directory containing the "Beyond SplashKit" groups const guidesGrouptsOutputJson = './scripts/json-files/guides-groups.json'; // Path where the "Guides" groups output JSON files will be saved const beyondSkGroupsOutputJson = './scripts/json-files/beyond-splashkit-groups.json'; // Path where the "Beyond SplashKit" groups output JSON files will be saved diff --git a/scripts/json-files/api.json b/scripts/json-files/api.json index 293ff8763..fbbf1a167 100644 --- a/scripts/json-files/api.json +++ b/scripts/json-files/api.json @@ -1808,9 +1808,9 @@ { "signature": "void free_animation(animation ani);", "name": "free_animation", - "method_name": null, + "method_name": "free", "unique_global_name": "free_animation", - "unique_method_name": null, + "unique_method_name": "animation.free", "suffix_name": null, "description": "Disposes of the resources used in the animation.", "brief": null, @@ -1840,6 +1840,7 @@ "attributes": { "class": "animation", "destructor": true, + "method": "free", "self": "ani", "group": "animations", "static": "animation" @@ -1852,6 +1853,7 @@ "def free_animation(ani):" ], "csharp": [ + "public void Animation.Free();", "public static void SplashKit.FreeAnimation(Animation ani);" ], "pascal": [ @@ -1862,9 +1864,9 @@ { "signature": "void free_animation_script(animation_script script_to_free);", "name": "free_animation_script", - "method_name": null, + "method_name": "free", "unique_global_name": "free_animation_script", - "unique_method_name": null, + "unique_method_name": "animation_script.free", "suffix_name": null, "description": "Frees loaded animation frames data. Use this when you will no\nlonger be using the animation for any purpose, including within\nsprite.", "brief": null, @@ -1894,6 +1896,7 @@ "attributes": { "class": "animation_script", "destructor": true, + "method": "free", "self": "script_to_free", "group": "animations", "static": "animation" @@ -1906,6 +1909,7 @@ "def free_animation_script(script_to_free):" ], "csharp": [ + "public void AnimationScript.Free();", "public static void SplashKit.FreeAnimationScript(AnimationScript scriptToFree);" ], "pascal": [ @@ -2998,9 +3002,9 @@ { "signature": "void free_music(music effect);", "name": "free_music", - "method_name": null, + "method_name": "free", "unique_global_name": "free_music", - "unique_method_name": null, + "unique_method_name": "music.free", "suffix_name": null, "description": "Releases the SplashKit resources associated with music.", "brief": null, @@ -3030,6 +3034,7 @@ "attributes": { "class": "music", "destructor": true, + "method": "free", "self": "effect", "group": "audio", "static": "audio" @@ -3042,6 +3047,7 @@ "def free_music(effect):" ], "csharp": [ + "public void Music.Free();", "public static void SplashKit.FreeMusic(Music effect);" ], "pascal": [ @@ -18491,9 +18497,9 @@ { "signature": "point_2d random_window_point(window wind);", "name": "random_window_point", - "method_name": null, + "method_name": "random_point", "unique_global_name": "random_window_point", - "unique_method_name": null, + "unique_method_name": "window.random_point", "suffix_name": null, "description": "Returns a random point on the provided window.", "brief": null, @@ -18521,8 +18527,11 @@ } }, "attributes": { + "class": "window", + "method": "random_point", "group": "geometry", - "static": "geometry" + "static": "geometry", + "self": "wind" }, "signatures": { "cpp": [ @@ -18532,6 +18541,7 @@ "def random_window_point(wind):" ], "csharp": [ + "public Point2D Window.RandomPoint();", "public static Point2D SplashKit.RandomWindowPoint(Window wind);" ], "pascal": [ @@ -21488,6 +21498,173 @@ ] } }, + { + "signature": "void draw_circle(color clr,const point_2d &pt,double radius);", + "name": "draw_circle", + "method_name": null, + "unique_global_name": "draw_circle_at_point", + "unique_method_name": null, + "suffix_name": null, + "description": "Draw a circle at a point, with a specified radius, onto the current window.", + "brief": null, + "return": { + "type": "void", + "description": null, + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "clr": { + "type": "color", + "description": "The color of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "pt": { + "type": "point_2d", + "description": "The location of the center of the circle", + "is_pointer": false, + "is_const": true, + "is_reference": true, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "radius": { + "type": "double", + "description": "The radius of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "suffix": "at_point", + "group": "graphics" + }, + "signatures": { + "cpp": [ + "void draw_circle(color clr, const point_2d &pt, double radius)" + ], + "python": [ + "def draw_circle_at_point(clr, pt, radius):" + ], + "csharp": [ + "public static void SplashKit.DrawCircle(Color clr, Point2D pt, double radius);" + ], + "pascal": [ + "procedure DrawCircle(clr: Color; const pt: Point2D; radius: Double)" + ] + } + }, + { + "signature": "void draw_circle(color clr,const point_2d &pt,double radius,drawing_options opts);", + "name": "draw_circle", + "method_name": null, + "unique_global_name": "draw_circle_at_point_with_options", + "unique_method_name": null, + "suffix_name": null, + "description": "Draw a circle at a point, with a specified radius, using the supplied drawing options. This will use `drawing_options` to determine\nthe destination.", + "brief": null, + "return": { + "type": "void", + "description": null, + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "clr": { + "type": "color", + "description": "The color of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "pt": { + "type": "point_2d", + "description": "The location of the center of the circle", + "is_pointer": false, + "is_const": true, + "is_reference": true, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "radius": { + "type": "double", + "description": "The radius of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "opts": { + "type": "drawing_options", + "description": "Drawing options to configure the drawing operation", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "suffix": "at_point_with_options", + "group": "graphics" + }, + "signatures": { + "cpp": [ + "void draw_circle(color clr, const point_2d &pt, double radius, drawing_options opts)" + ], + "python": [ + "def draw_circle_at_point_with_options(clr, pt, radius, opts):" + ], + "csharp": [ + "public static void SplashKit.DrawCircle(Color clr, Point2D pt, double radius, DrawingOptions opts);" + ], + "pascal": [ + "procedure DrawCircle(clr: Color; const pt: Point2D; radius: Double; opts: DrawingOptions)" + ] + } + }, { "signature": "void draw_circle(color clr,double x,double y,double radius);", "name": "draw_circle", @@ -22282,13 +22459,13 @@ } }, { - "signature": "void fill_circle(color clr,double x,double y,double radius);", + "signature": "void fill_circle(color clr,const point_2d &pt,double radius);", "name": "fill_circle", "method_name": null, - "unique_global_name": "fill_circle", + "unique_global_name": "fill_circle_at_point", "unique_method_name": null, "suffix_name": null, - "description": "Fill a circle onto the current window. The circle is centred on its x, y\ncoordinates, and has the provided radius.", + "description": "Fill a circle at a point, with a specified radius, onto the current window.", "brief": null, "return": { "type": "void", @@ -22312,25 +22489,12 @@ "is_vector": false, "type_parameter": null }, - "x": { - "type": "double", - "description": "The x location of the circle", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - }, - "y": { - "type": "double", - "description": "The y location of the circle", + "pt": { + "type": "point_2d", + "description": "The location of the center of the circle", "is_pointer": false, - "is_const": false, - "is_reference": false, + "is_const": true, + "is_reference": true, "is_array": false, "array_dimension_sizes": [ @@ -22353,31 +22517,32 @@ } }, "attributes": { + "suffix": "at_point", "group": "graphics" }, "signatures": { "cpp": [ - "void fill_circle(color clr, double x, double y, double radius)" + "void fill_circle(color clr, const point_2d &pt, double radius)" ], "python": [ - "def fill_circle(clr, x, y, radius):" + "def fill_circle_at_point(clr, pt, radius):" ], "csharp": [ - "public static void SplashKit.FillCircle(Color clr, double x, double y, double radius);" + "public static void SplashKit.FillCircle(Color clr, Point2D pt, double radius);" ], "pascal": [ - "procedure FillCircle(clr: Color; x: Double; y: Double; radius: Double)" + "procedure FillCircle(clr: Color; const pt: Point2D; radius: Double)" ] } }, { - "signature": "void fill_circle(color clr,double x,double y,double radius,drawing_options opts);", + "signature": "void fill_circle(color clr,const point_2d &pt,double radius,drawing_options opts);", "name": "fill_circle", "method_name": null, - "unique_global_name": "fill_circle_with_options", + "unique_global_name": "fill_circle_at_point_with_options", "unique_method_name": null, "suffix_name": null, - "description": "Fill a circle using the supplied drawing options. The circle is centred on its x, y\ncoordinates, and has the provided radius. This will use `drawing_options` to determine\nthe destination.", + "description": "Fill a circle at a point, with a specified radius, using the supplied drawing options. This will use `drawing_options` to determine\nthe destination.", "brief": null, "return": { "type": "void", @@ -22401,25 +22566,12 @@ "is_vector": false, "type_parameter": null }, - "x": { - "type": "double", - "description": "The x location of the circle", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - }, - "y": { - "type": "double", - "description": "The y location of the circle", + "pt": { + "type": "point_2d", + "description": "The location of the center of the circle", "is_pointer": false, - "is_const": false, - "is_reference": false, + "is_const": true, + "is_reference": true, "is_array": false, "array_dimension_sizes": [ @@ -22455,32 +22607,32 @@ } }, "attributes": { - "suffix": "with_options", + "suffix": "at_point_with_options", "group": "graphics" }, "signatures": { "cpp": [ - "void fill_circle(color clr, double x, double y, double radius, drawing_options opts)" + "void fill_circle(color clr, const point_2d &pt, double radius, drawing_options opts)" ], "python": [ - "def fill_circle_with_options(clr, x, y, radius, opts):" + "def fill_circle_at_point_with_options(clr, pt, radius, opts):" ], "csharp": [ - "public static void SplashKit.FillCircle(Color clr, double x, double y, double radius, DrawingOptions opts);" + "public static void SplashKit.FillCircle(Color clr, Point2D pt, double radius, DrawingOptions opts);" ], "pascal": [ - "procedure FillCircle(clr: Color; x: Double; y: Double; radius: Double; opts: DrawingOptions)" + "procedure FillCircle(clr: Color; const pt: Point2D; radius: Double; opts: DrawingOptions)" ] } }, { - "signature": "void fill_circle_on_bitmap(bitmap destination,color clr,double x,double y,double radius);", - "name": "fill_circle_on_bitmap", - "method_name": "fill_circle", - "unique_global_name": "fill_circle_on_bitmap", - "unique_method_name": "bitmap.fill_circle", + "signature": "void fill_circle(color clr,double x,double y,double radius);", + "name": "fill_circle", + "method_name": null, + "unique_global_name": "fill_circle", + "unique_method_name": null, "suffix_name": null, - "description": "Fill a circle onto the destination bitmap. The circle is centred on its x, y\ncoordinates, and has the provided radius.", + "description": "Fill a circle onto the current window. The circle is centred on its x, y\ncoordinates, and has the provided radius.", "brief": null, "return": { "type": "void", @@ -22491,19 +22643,211 @@ "type_parameter": null }, "parameters": { - "destination": { - "type": "bitmap", - "description": "The destination bitmap", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - }, + "clr": { + "type": "color", + "description": "The color of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "x": { + "type": "double", + "description": "The x location of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "y": { + "type": "double", + "description": "The y location of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "radius": { + "type": "double", + "description": "The radius of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "group": "graphics" + }, + "signatures": { + "cpp": [ + "void fill_circle(color clr, double x, double y, double radius)" + ], + "python": [ + "def fill_circle(clr, x, y, radius):" + ], + "csharp": [ + "public static void SplashKit.FillCircle(Color clr, double x, double y, double radius);" + ], + "pascal": [ + "procedure FillCircle(clr: Color; x: Double; y: Double; radius: Double)" + ] + } + }, + { + "signature": "void fill_circle(color clr,double x,double y,double radius,drawing_options opts);", + "name": "fill_circle", + "method_name": null, + "unique_global_name": "fill_circle_with_options", + "unique_method_name": null, + "suffix_name": null, + "description": "Fill a circle using the supplied drawing options. The circle is centred on its x, y\ncoordinates, and has the provided radius. This will use `drawing_options` to determine\nthe destination.", + "brief": null, + "return": { + "type": "void", + "description": null, + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "clr": { + "type": "color", + "description": "The color of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "x": { + "type": "double", + "description": "The x location of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "y": { + "type": "double", + "description": "The y location of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "radius": { + "type": "double", + "description": "The radius of the circle", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "opts": { + "type": "drawing_options", + "description": "Drawing options to configure the drawing operation", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "suffix": "with_options", + "group": "graphics" + }, + "signatures": { + "cpp": [ + "void fill_circle(color clr, double x, double y, double radius, drawing_options opts)" + ], + "python": [ + "def fill_circle_with_options(clr, x, y, radius, opts):" + ], + "csharp": [ + "public static void SplashKit.FillCircle(Color clr, double x, double y, double radius, DrawingOptions opts);" + ], + "pascal": [ + "procedure FillCircle(clr: Color; x: Double; y: Double; radius: Double; opts: DrawingOptions)" + ] + } + }, + { + "signature": "void fill_circle_on_bitmap(bitmap destination,color clr,double x,double y,double radius);", + "name": "fill_circle_on_bitmap", + "method_name": "fill_circle", + "unique_global_name": "fill_circle_on_bitmap", + "unique_method_name": "bitmap.fill_circle", + "suffix_name": null, + "description": "Fill a circle onto the destination bitmap. The circle is centred on its x, y\ncoordinates, and has the provided radius.", + "brief": null, + "return": { + "type": "void", + "description": null, + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "destination": { + "type": "bitmap", + "description": "The destination bitmap", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, "clr": { "type": "color", "description": "The color of the circle", @@ -23016,9 +23360,9 @@ { "signature": "rectangle current_clip(window wnd);", "name": "current_clip", - "method_name": null, + "method_name": "current_clip", "unique_global_name": "current_clip_for_window", - "unique_method_name": null, + "unique_method_name": "window.current_clip_for_window", "suffix_name": null, "description": "Returns the rectangle of the current clip area for a window", "brief": null, @@ -23046,6 +23390,9 @@ } }, "attributes": { + "class": "window", + "method": "current_clip", + "self": "wnd", "suffix": "for_window", "group": "graphics" }, @@ -23057,6 +23404,7 @@ "def current_clip_for_window(wnd):" ], "csharp": [ + "public Rectangle Window.CurrentClip();", "public static Rectangle SplashKit.CurrentClip(Window wnd);" ], "pascal": [ @@ -23067,9 +23415,9 @@ { "signature": "void pop_clip(window wnd);", "name": "pop_clip", - "method_name": null, + "method_name": "pop_clip", "unique_global_name": "pop_clip_for_window", - "unique_method_name": null, + "unique_method_name": "window.pop_clip_for_window", "suffix_name": null, "description": "Remove the last clipping rectangle pushed to the window. This\nwill then apply the previously pushed clipping rectangle.", "brief": null, @@ -23097,6 +23445,9 @@ } }, "attributes": { + "class": "window", + "method": "pop_clip", + "self": "wnd", "suffix": "for_window", "group": "graphics" }, @@ -23108,6 +23459,7 @@ "def pop_clip_for_window(wnd):" ], "csharp": [ + "public void Window.PopClip();", "public static void SplashKit.PopClip(Window wnd);" ], "pascal": [ @@ -23206,9 +23558,9 @@ { "signature": "void push_clip(window wnd,const rectangle &r);", "name": "push_clip", - "method_name": null, + "method_name": "push_clip", "unique_global_name": "push_clip_for_window", - "unique_method_name": null, + "unique_method_name": "window.push_clip_for_window", "suffix_name": null, "description": "Add the clipping rectangle of a window and uses the intersect between\nthe new rectangle and previous clip.\n\nWhen a clipping rectangle is provided, drawing operations will only\naffect the area specified in the current clipping rectangle.", "brief": null, @@ -23249,6 +23601,9 @@ } }, "attributes": { + "class": "window", + "method": "push_clip", + "self": "wnd", "suffix": "for_window", "group": "graphics" }, @@ -23260,6 +23615,7 @@ "def push_clip_for_window(wnd, r):" ], "csharp": [ + "public void Window.PushClip(Rectangle r);", "public static void SplashKit.PushClip(Window wnd, Rectangle r);" ], "pascal": [ @@ -23472,9 +23828,9 @@ { "signature": "void reset_clip(window wnd);", "name": "reset_clip", - "method_name": null, + "method_name": "reset_clip", "unique_global_name": "reset_clip_for_window", - "unique_method_name": null, + "unique_method_name": "window.reset_clip_for_window", "suffix_name": null, "description": "Reset the clipping rectangle on a window. This will clear all\nof the clipping rectangles pushed to the window.", "brief": null, @@ -23502,6 +23858,9 @@ } }, "attributes": { + "class": "window", + "method": "reset_clip", + "self": "wnd", "suffix": "for_window", "group": "graphics" }, @@ -23513,6 +23872,7 @@ "def reset_clip_for_window(wnd):" ], "csharp": [ + "public void Window.ResetClip();", "public static void SplashKit.ResetClip(Window wnd);" ], "pascal": [ @@ -23637,9 +23997,9 @@ { "signature": "void set_clip(window wnd,const rectangle &r);", "name": "set_clip", - "method_name": null, + "method_name": "set_clip", "unique_global_name": "set_clip_for_window", - "unique_method_name": null, + "unique_method_name": "window.set_clip_for_window", "suffix_name": null, "description": "Set the clip rectangle of the window. This will clear any existing\nclipping rectangles pushed to the window, and use the supplied rectangle\nfor clipping.", "brief": null, @@ -23680,6 +24040,9 @@ } }, "attributes": { + "class": "window", + "method": "set_clip", + "self": "wnd", "suffix": "for_window", "group": "graphics" }, @@ -23691,6 +24054,7 @@ "def set_clip_for_window(wnd, r):" ], "csharp": [ + "public void Window.SetClip(Rectangle r);", "public static void SplashKit.SetClip(Window wnd, Rectangle r);" ], "pascal": [ @@ -23853,9 +24217,9 @@ { "signature": "drawing_options option_draw_to(window dest);", "name": "option_draw_to", - "method_name": null, + "method_name": "option_draw_to", "unique_global_name": "option_draw_to_window", - "unique_method_name": null, + "unique_method_name": "window.option_draw_to_window", "suffix_name": null, "description": "Use this option to draw to a specified Window. Pass dest the Window you want to draw on.", "brief": null, @@ -23883,6 +24247,9 @@ } }, "attributes": { + "class": "window", + "method": "option_draw_to", + "self": "dest", "suffix": "window", "group": "graphics" }, @@ -23894,6 +24261,7 @@ "def option_draw_to_window(dest):" ], "csharp": [ + "public DrawingOptions Window.OptionDrawTo();", "public static DrawingOptions SplashKit.OptionDrawTo(Window dest);" ], "pascal": [ @@ -23904,9 +24272,9 @@ { "signature": "drawing_options option_draw_to(window dest,drawing_options opts);", "name": "option_draw_to", - "method_name": null, + "method_name": "option_draw_to", "unique_global_name": "option_draw_to_window_with_options", - "unique_method_name": null, + "unique_method_name": "window.option_draw_to_window_with_options", "suffix_name": null, "description": "Use this option to draw to a Bitmap. Pass dest the Bitmap you want to draw on to.\nPass opts the other options you want use.", "brief": null, @@ -23947,6 +24315,9 @@ } }, "attributes": { + "class": "window", + "method": "option_draw_to", + "self": "dest", "suffix": "window_with_options", "group": "graphics" }, @@ -23958,6 +24329,7 @@ "def option_draw_to_window_with_options(dest, opts):" ], "csharp": [ + "public DrawingOptions Window.OptionDrawTo(DrawingOptions opts);", "public static DrawingOptions SplashKit.OptionDrawTo(Window dest, DrawingOptions opts);" ], "pascal": [ @@ -28624,9 +28996,9 @@ { "signature": "void take_screenshot(window wind,const string &basename);", "name": "take_screenshot", - "method_name": null, + "method_name": "take_screenshot", "unique_global_name": "take_screenshot_of_window", - "unique_method_name": null, + "unique_method_name": "window.take_screenshot_of_window", "suffix_name": null, "description": "Saves a screenshot of the current window to a bitmap file. The file will\nbe saved onto the user's desktop.", "brief": null, @@ -28667,6 +29039,9 @@ } }, "attributes": { + "class": "window", + "method": "take_screenshot", + "self": "wind", "suffix": "of_window", "group": "graphics" }, @@ -28678,6 +29053,7 @@ "def take_screenshot_of_window(wind, basename):" ], "csharp": [ + "public void Window.TakeScreenshot(string basename);", "public static void SplashKit.TakeScreenshot(Window wind, string basename);" ], "pascal": [ @@ -34337,9 +34713,9 @@ { "signature": "void draw_pixel_on_window(window destination,color clr,const point_2d &pt);", "name": "draw_pixel_on_window", - "method_name": null, + "method_name": "draw_pixel", "unique_global_name": "draw_pixel_on_window_at_point", - "unique_method_name": null, + "unique_method_name": "window.draw_pixel_at_point", "suffix_name": null, "description": "Draws an individual pixel to the given window.", "brief": null, @@ -34394,8 +34770,10 @@ }, "attributes": { "class": "window", + "method": "draw_pixel", "suffix": "at_point", - "group": "graphics" + "group": "graphics", + "self": "destination" }, "signatures": { "cpp": [ @@ -34405,6 +34783,7 @@ "def draw_pixel_on_window_at_point(destination, clr, pt):" ], "csharp": [ + "public void Window.DrawPixel(Color clr, Point2D pt);", "public static void SplashKit.DrawPixelOnWindow(Window destination, Color clr, Point2D pt);" ], "pascal": [ @@ -34415,9 +34794,9 @@ { "signature": "void draw_pixel_on_window(window destination,color clr,const point_2d &pt,drawing_options opts);", "name": "draw_pixel_on_window", - "method_name": null, + "method_name": "draw_pixel", "unique_global_name": "draw_pixel_on_window_at_point_with_options", - "unique_method_name": null, + "unique_method_name": "window.draw_pixel_at_point_with_options", "suffix_name": null, "description": "Draws an individual pixel to the given window with the given drawing options.", "brief": null, @@ -34485,8 +34864,10 @@ }, "attributes": { "class": "window", + "method": "draw_pixel", "suffix": "at_point_with_options", - "group": "graphics" + "group": "graphics", + "self": "destination" }, "signatures": { "cpp": [ @@ -34496,6 +34877,7 @@ "def draw_pixel_on_window_at_point_with_options(destination, clr, pt, opts):" ], "csharp": [ + "public void Window.DrawPixel(Color clr, Point2D pt, DrawingOptions opts);", "public static void SplashKit.DrawPixelOnWindow(Window destination, Color clr, Point2D pt, DrawingOptions opts);" ], "pascal": [ @@ -34506,9 +34888,9 @@ { "signature": "void draw_pixel_on_window(window destination,color clr,double x,double y);", "name": "draw_pixel_on_window", - "method_name": null, + "method_name": "draw_pixel", "unique_global_name": "draw_pixel_on_window", - "unique_method_name": null, + "unique_method_name": "window.draw_pixel", "suffix_name": null, "description": "Draws an individual pixel to the given window.", "brief": null, @@ -34576,7 +34958,9 @@ }, "attributes": { "class": "window", - "group": "graphics" + "method": "draw_pixel", + "group": "graphics", + "self": "destination" }, "signatures": { "cpp": [ @@ -34586,6 +34970,7 @@ "def draw_pixel_on_window(destination, clr, x, y):" ], "csharp": [ + "public void Window.DrawPixel(Color clr, double x, double y);", "public static void SplashKit.DrawPixelOnWindow(Window destination, Color clr, double x, double y);" ], "pascal": [ @@ -34596,9 +34981,9 @@ { "signature": "void draw_pixel_on_window(window destination,color clr,double x,double y,drawing_options opts);", "name": "draw_pixel_on_window", - "method_name": null, + "method_name": "draw_pixel", "unique_global_name": "draw_pixel_on_window_with_options", - "unique_method_name": null, + "unique_method_name": "window.draw_pixel_with_options", "suffix_name": null, "description": "Draws an individual pixel to the given window with the given drawing options.", "brief": null, @@ -34679,8 +35064,10 @@ }, "attributes": { "class": "window", + "method": "draw_pixel", "suffix": "with_options", - "group": "graphics" + "group": "graphics", + "self": "destination" }, "signatures": { "cpp": [ @@ -34690,6 +35077,7 @@ "def draw_pixel_on_window_with_options(destination, clr, x, y, opts):" ], "csharp": [ + "public void Window.DrawPixel(Color clr, double x, double y, DrawingOptions opts);", "public static void SplashKit.DrawPixelOnWindow(Window destination, Color clr, double x, double y, DrawingOptions opts);" ], "pascal": [ @@ -35093,148 +35481,6 @@ ] } }, - { - "signature": "color get_pixel_from_window(window destination,const point_2d &pt);", - "name": "get_pixel_from_window", - "method_name": null, - "unique_global_name": "get_pixel_from_window_at_point_from_window", - "unique_method_name": null, - "suffix_name": null, - "description": "Returns the color of the pixel at the x,y location on the given\nwindow.", - "brief": null, - "return": { - "type": "color", - "description": "The color of the pixel at the supplied location", - "is_pointer": false, - "is_reference": false, - "is_vector": false, - "type_parameter": null - }, - "parameters": { - "destination": { - "type": "window", - "description": "The window to draw the pixel on", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - }, - "pt": { - "type": "point_2d", - "description": "The position of the pixel", - "is_pointer": false, - "is_const": true, - "is_reference": true, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - } - }, - "attributes": { - "suffix": "at_point_from_window", - "group": "graphics" - }, - "signatures": { - "cpp": [ - "color get_pixel_from_window(window destination, const point_2d &pt)" - ], - "python": [ - "def get_pixel_from_window_at_point_from_window(destination, pt):" - ], - "csharp": [ - "public static Color SplashKit.GetPixelFromWindow(Window destination, Point2D pt);" - ], - "pascal": [ - "function GetPixelFromWindow(destination: Window; const pt: Point2D): Color" - ] - } - }, - { - "signature": "color get_pixel_from_window(window destination,double x,double y);", - "name": "get_pixel_from_window", - "method_name": null, - "unique_global_name": "get_pixel_from_window_from_window", - "unique_method_name": null, - "suffix_name": null, - "description": "Returns the color of the pixel at the x,y location on the given\nwindow.", - "brief": null, - "return": { - "type": "color", - "description": "The color of the pixel at the supplied location", - "is_pointer": false, - "is_reference": false, - "is_vector": false, - "type_parameter": null - }, - "parameters": { - "destination": { - "type": "window", - "description": "The window to draw the pixel on", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - }, - "x": { - "type": "double", - "description": "The distance from the left edge of the window to the pixel\nto read", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - }, - "y": { - "type": "double", - "description": "The distance from the top of the window to the pixel to read", - "is_pointer": false, - "is_const": false, - "is_reference": false, - "is_array": false, - "array_dimension_sizes": [ - - ], - "is_vector": false, - "type_parameter": null - } - }, - "attributes": { - "class": "window", - "suffix": "from_window", - "group": "graphics" - }, - "signatures": { - "cpp": [ - "color get_pixel_from_window(window destination, double x, double y)" - ], - "python": [ - "def get_pixel_from_window_from_window(destination, x, y):" - ], - "csharp": [ - "public static Color SplashKit.GetPixelFromWindow(Window destination, double x, double y);" - ], - "pascal": [ - "function GetPixelFromWindow(destination: Window; x: Double; y: Double): Color" - ] - } - }, { "signature": "void draw_quad(color clr,const quad &q);", "name": "draw_quad", @@ -37333,9 +37579,9 @@ { "signature": "void fill_quad_on_window(window destination,color clr,const quad &q,const drawing_options &opts);", "name": "fill_quad_on_window", - "method_name": null, + "method_name": "fill_quad", "unique_global_name": "fill_quad_on_window_with_options", - "unique_method_name": null, + "unique_method_name": "window.fill_quad_with_options", "suffix_name": null, "description": "Fill a quad on the supplied window using the supplied drawing options.", "brief": null, @@ -37403,8 +37649,10 @@ }, "attributes": { "class": "window", + "method": "fill_quad", "suffix": "with_options", - "group": "graphics" + "group": "graphics", + "self": "destination" }, "signatures": { "cpp": [ @@ -37414,6 +37662,7 @@ "def fill_quad_on_window_with_options(destination, clr, q, opts):" ], "csharp": [ + "public void Window.FillQuad(Color clr, Quad q, DrawingOptions opts);", "public static void SplashKit.FillQuadOnWindow(Window destination, Color clr, Quad q, DrawingOptions opts);" ], "pascal": [ @@ -46315,9 +46564,9 @@ { "signature": "void end_reading_text(window wind);", "name": "end_reading_text", - "method_name": null, + "method_name": "end_reading_text", "unique_global_name": "end_reading_text_in_window", - "unique_method_name": null, + "unique_method_name": "window.end_reading_text_in_window", "suffix_name": null, "description": "Ends reading text for the passed in window.", "brief": null, @@ -46345,6 +46594,9 @@ } }, "attributes": { + "class": "window", + "method": "end_reading_text", + "self": "wind", "suffix": "in_window", "group": "input" }, @@ -46356,6 +46608,7 @@ "def end_reading_text_in_window(wind):" ], "csharp": [ + "public void Window.EndReadingText();", "public static void SplashKit.EndReadingText(Window wind);" ], "pascal": [ @@ -46403,9 +46656,9 @@ { "signature": "bool reading_text(window wind);", "name": "reading_text", - "method_name": null, + "method_name": "reading_text", "unique_global_name": "reading_text_in_window", - "unique_method_name": null, + "unique_method_name": "window.reading_text_in_window", "suffix_name": null, "description": "Returns true when the window is reading text.", "brief": null, @@ -46433,6 +46686,9 @@ } }, "attributes": { + "class": "window", + "method": "reading_text", + "self": "wind", "suffix": "in_window", "group": "input" }, @@ -46444,6 +46700,7 @@ "def reading_text_in_window(wind):" ], "csharp": [ + "public bool Window.ReadingText();", "public static bool SplashKit.ReadingText(Window wind);" ], "pascal": [ @@ -46568,9 +46825,9 @@ { "signature": "void start_reading_text(window wind,rectangle rect);", "name": "start_reading_text", - "method_name": null, + "method_name": "start_reading_text", "unique_global_name": "start_reading_text_in_window", - "unique_method_name": null, + "unique_method_name": "window.start_reading_text_in_window", "suffix_name": null, "description": "Start reading text in the window within the bounds of the\nsupplied rectangle.", "brief": null, @@ -46611,6 +46868,9 @@ } }, "attributes": { + "class": "window", + "method": "start_reading_text", + "self": "wind", "suffix": "in_window", "group": "input" }, @@ -46622,6 +46882,7 @@ "def start_reading_text_in_window(wind, rect):" ], "csharp": [ + "public void Window.StartReadingText(Rectangle rect);", "public static void SplashKit.StartReadingText(Window wind, Rectangle rect);" ], "pascal": [ @@ -46632,9 +46893,9 @@ { "signature": "void start_reading_text(window wind,rectangle rect,string initial_text);", "name": "start_reading_text", - "method_name": null, + "method_name": "start_reading_text", "unique_global_name": "start_reading_text_in_window_with_initial_text", - "unique_method_name": null, + "unique_method_name": "window.start_reading_text_in_window_with_initial_text", "suffix_name": null, "description": "Start reading text in the window within the bounds of the\nsupplied rectangle. The text will start with an initial value.", "brief": null, @@ -46688,6 +46949,9 @@ } }, "attributes": { + "class": "window", + "method": "start_reading_text", + "self": "wind", "suffix": "in_window_with_initial_text", "group": "input" }, @@ -46699,6 +46963,7 @@ "def start_reading_text_in_window_with_initial_text(wind, rect, initial_text):" ], "csharp": [ + "public void Window.StartReadingText(Rectangle rect, string initialText);", "public static void SplashKit.StartReadingText(Window wind, Rectangle rect, string initialText);" ], "pascal": [ @@ -46746,9 +47011,9 @@ { "signature": "bool text_entry_cancelled(window wind);", "name": "text_entry_cancelled", - "method_name": null, + "method_name": "text_entry_cancelled", "unique_global_name": "text_entry_cancelled_in_window", - "unique_method_name": null, + "unique_method_name": "window.text_entry_cancelled_in_window", "suffix_name": null, "description": "Did the user press escape and cancel the enterring of text?", "brief": null, @@ -46776,6 +47041,9 @@ } }, "attributes": { + "class": "window", + "method": "text_entry_cancelled", + "self": "wind", "suffix": "in_window", "group": "input" }, @@ -46787,6 +47055,7 @@ "def text_entry_cancelled_in_window(wind):" ], "csharp": [ + "public bool Window.TextEntryCancelled();", "public static bool SplashKit.TextEntryCancelled(Window wind);" ], "pascal": [ @@ -46834,9 +47103,9 @@ { "signature": "string text_input(window wind);", "name": "text_input", - "method_name": null, + "method_name": "text_input", "unique_global_name": "text_input_in_window", - "unique_method_name": null, + "unique_method_name": "window.text_input_in_window", "suffix_name": null, "description": "The text the user has currently enterred on the current window.", "brief": null, @@ -46864,6 +47133,9 @@ } }, "attributes": { + "class": "window", + "method": "text_input", + "self": "wind", "suffix": "in_window", "group": "input" }, @@ -46875,6 +47147,7 @@ "def text_input_in_window(wind):" ], "csharp": [ + "public string Window.TextInput();", "public static string SplashKit.TextInput(Window wind);" ], "pascal": [ @@ -51818,13 +52091,13 @@ } }, { - "signature": "string text_box(const string& value);", + "signature": "string text_box(const string& label_text,const string& value,const rectangle& rect);", "name": "text_box", "method_name": null, - "unique_global_name": "text_box", + "unique_global_name": "text_box_at_position", "unique_method_name": null, "suffix_name": null, - "description": "Creates a text entry box with a label.\nReturns the updated value of the text box.", + "description": "Creates a text entry box at a specific position on screen.\nReturns the updated value of the text box.\n\nExample usage:\n```c++\nmy_string = text_box(\"Name\", my_string, rectangle_from(0,0,100,100));\n```", "brief": null, "return": { "type": "string", @@ -51835,6 +52108,19 @@ "type_parameter": null }, "parameters": { + "label_text": { + "type": "string", + "description": "Unique identifier for the text box (not drawn)", + "is_pointer": false, + "is_const": true, + "is_reference": true, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, "value": { "type": "string", "description": "The current value of the text box", @@ -51844,38 +52130,52 @@ "is_array": false, "array_dimension_sizes": [ + ], + "is_vector": false, + "type_parameter": null + }, + "rect": { + "type": "rectangle", + "description": "The rectangle to display the button in", + "is_pointer": false, + "is_const": true, + "is_reference": true, + "is_array": false, + "array_dimension_sizes": [ + ], "is_vector": false, "type_parameter": null } }, "attributes": { + "suffix": "at_position", "group": "interface", "static": "interface" }, "signatures": { "cpp": [ - "string text_box(const string &value)" + "string text_box(const string &label_text, const string &value, const rectangle &rect)" ], "python": [ - "def text_box(value):" + "def text_box_at_position(label_text, value, rect):" ], "csharp": [ - "public static string SplashKit.TextBox(string value);" + "public static string SplashKit.TextBox(string labelText, string value, Rectangle rect);" ], "pascal": [ - "function TextBox(const value: String): String" + "function TextBox(const labelText: String; const value: String; const rect: Rectangle): String" ] } }, { - "signature": "string text_box(const string& value,const rectangle& rect);", + "signature": "string text_box(const string& label_text,const string& value);", "name": "text_box", "method_name": null, - "unique_global_name": "text_box_at_position", + "unique_global_name": "text_box", "unique_method_name": null, "suffix_name": null, - "description": "Creates a text entry box at a specific position on screen.\nReturns the updated value of the text box.\n\nExample usage:\n```c++\nmy_string = text_box(\"Name\", my_string);\n```", + "description": "Creates a text entry box with a label.\nReturns the updated value of the text box.\n\nExample usage:\n```c++\nmy_string = text_box(\"Name\", my_string);\n```", "brief": null, "return": { "type": "string", @@ -51886,9 +52186,9 @@ "type_parameter": null }, "parameters": { - "value": { + "label_text": { "type": "string", - "description": "The current value of the text box", + "description": "Unique identifier for the text box (not drawn)", "is_pointer": false, "is_const": true, "is_reference": true, @@ -51899,9 +52199,9 @@ "is_vector": false, "type_parameter": null }, - "rect": { - "type": "rectangle", - "description": "The rectangle to display the button in", + "value": { + "type": "string", + "description": "The current value of the text box", "is_pointer": false, "is_const": true, "is_reference": true, @@ -51914,33 +52214,32 @@ } }, "attributes": { - "suffix": "at_position", "group": "interface", "static": "interface" }, "signatures": { "cpp": [ - "string text_box(const string &value, const rectangle &rect)" + "string text_box(const string &label_text, const string &value)" ], "python": [ - "def text_box_at_position(value, rect):" + "def text_box(label_text, value):" ], "csharp": [ - "public static string SplashKit.TextBox(string value, Rectangle rect);" + "public static string SplashKit.TextBox(string labelText, string value);" ], "pascal": [ - "function TextBox(const value: String; const rect: Rectangle): String" + "function TextBox(const labelText: String; const value: String): String" ] } }, { - "signature": "string text_box(const string& label_text,const string& value);", + "signature": "string text_box(const string& label_text,const string& value,bool show_label);", "name": "text_box", "method_name": null, "unique_global_name": "text_box_labeled", "unique_method_name": null, "suffix_name": null, - "description": "Creates a text entry box with a label.\nReturns the updated value of the text box.\n\nExample usage:\n```c++\nmy_string = text_box(\"Name\", my_string);\n```", + "description": "Creates a text entry box with a label that can be shown.\nReturns the updated value of the text box.\n\nExample usage:\n```c++\nmy_string = text_box(\"Name\", my_string, true);\n```", "brief": null, "return": { "type": "string", @@ -51953,7 +52252,7 @@ "parameters": { "label_text": { "type": "string", - "description": "The label to show in front of the text box", + "description": "Unique identifier for the text box (not drawn)", "is_pointer": false, "is_const": true, "is_reference": true, @@ -51973,6 +52272,19 @@ "is_array": false, "array_dimension_sizes": [ + ], + "is_vector": false, + "type_parameter": null + }, + "show_label": { + "type": "bool", + "description": "Whether to show the label or not", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + ], "is_vector": false, "type_parameter": null @@ -51985,16 +52297,16 @@ }, "signatures": { "cpp": [ - "string text_box(const string &label_text, const string &value)" + "string text_box(const string &label_text, const string &value, bool show_label)" ], "python": [ - "def text_box_labeled(label_text, value):" + "def text_box_labeled(label_text, value, show_label):" ], "csharp": [ - "public static string SplashKit.TextBox(string labelText, string value);" + "public static string SplashKit.TextBox(string labelText, string value, bool showLabel);" ], "pascal": [ - "function TextBox(const labelText: String; const value: String): String" + "function TextBox(const labelText: String; const value: String; showLabel: Boolean): String" ] } } @@ -52155,9 +52467,9 @@ { "signature": "void free_json(json j);", "name": "free_json", - "method_name": null, + "method_name": "free", "unique_global_name": "free_json", - "unique_method_name": null, + "unique_method_name": "json.free", "suffix_name": null, "description": "Frees the SplashKit resources associated with the `json` object.", "brief": null, @@ -52187,6 +52499,7 @@ "attributes": { "class": "json", "destructor": true, + "method": "free", "self": "j", "group": "json", "static": "json" @@ -52199,6 +52512,7 @@ "def free_json(j):" ], "csharp": [ + "public void Json.Free();", "public static void SplashKit.FreeJson(Json j);" ], "pascal": [ @@ -72798,9 +73112,9 @@ { "signature": "void close_adc(adc_device adc);", "name": "close_adc", - "method_name": null, + "method_name": "close", "unique_global_name": "close_adc", - "unique_method_name": null, + "unique_method_name": "adc_device.close", "suffix_name": null, "description": "Closes an ADC device given its pointer.", "brief": null, @@ -72830,6 +73144,7 @@ "attributes": { "class": "adc_device", "destructor": true, + "method": "close", "self": "adc", "group": "raspberry", "static": "raspberry" @@ -72842,6 +73157,7 @@ "def close_adc(adc):" ], "csharp": [ + "public void AdcDevice.Close();", "public static void SplashKit.CloseAdc(AdcDevice adc);" ], "pascal": [ @@ -73284,6 +73600,57 @@ ] } }, + { + "signature": "int gpio_pin_to_int(gpio_pin_value value);", + "name": "gpio_pin_to_int", + "method_name": null, + "unique_global_name": "gpio_pin_to_int", + "unique_method_name": null, + "suffix_name": null, + "description": "Converts the specified pin value to an integer, to use in calculations.", + "brief": "Converts a GPIO Pin Value to an integer.", + "return": { + "type": "int", + "description": "The pin value as an integer.", + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "value": { + "type": "gpio_pin_value", + "description": "The pin to read the value from.", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "group": "raspberry", + "static": "raspberry" + }, + "signatures": { + "cpp": [ + "int gpio_pin_to_int(gpio_pin_value value)" + ], + "python": [ + "def gpio_pin_to_int(value):" + ], + "csharp": [ + "public static int SplashKit.GpioPinToInt(GpioPinValue value);" + ], + "pascal": [ + "function GpioPinToInt(value: GpioPinValue): Integer" + ] + } + }, { "signature": "bool has_gpio();", "name": "has_gpio", @@ -73411,6 +73778,57 @@ ] } }, + { + "signature": "int raspi_get_servo_pulsewidth(gpio_pin pin);", + "name": "raspi_get_servo_pulsewidth", + "method_name": null, + "unique_global_name": "raspi_get_servo_pulsewidth", + "unique_method_name": null, + "suffix_name": null, + "description": "This function retrieves the pulse width for the specified pin.", + "brief": "Gets the pulse width for the specified pin.", + "return": { + "type": "int", + "description": "The pulse width of the pin.", + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "pin": { + "type": "gpio_pin", + "description": "The pin to get the pulse width for.", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "group": "raspberry", + "static": "raspberry" + }, + "signatures": { + "cpp": [ + "int raspi_get_servo_pulsewidth(gpio_pin pin)" + ], + "python": [ + "def raspi_get_servo_pulsewidth(pin):" + ], + "csharp": [ + "public static int SplashKit.RaspiGetServoPulsewidth(GpioPin pin);" + ], + "pascal": [ + "function RaspiGetServoPulsewidth(pin: GpioPin): Integer" + ] + } + }, { "signature": "void raspi_init();", "name": "raspi_init", @@ -73820,6 +74238,70 @@ ] } }, + { + "signature": "void raspi_set_servo_pulsewidth(gpio_pin pin,int pulsewidth);", + "name": "raspi_set_servo_pulsewidth", + "method_name": null, + "unique_global_name": "raspi_set_servo_pulsewidth", + "unique_method_name": null, + "suffix_name": null, + "description": "This function sets the pulse width for the specified pin.", + "brief": "Sets the pulse width for the specified pin.", + "return": { + "type": "void", + "description": null, + "is_pointer": false, + "is_reference": false, + "is_vector": false, + "type_parameter": null + }, + "parameters": { + "pin": { + "type": "gpio_pin", + "description": "The pin to set the pulse width for.", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + }, + "pulsewidth": { + "type": "int", + "description": "The pulse width to set for the pin.", + "is_pointer": false, + "is_const": false, + "is_reference": false, + "is_array": false, + "array_dimension_sizes": [ + + ], + "is_vector": false, + "type_parameter": null + } + }, + "attributes": { + "group": "raspberry", + "static": "raspberry" + }, + "signatures": { + "cpp": [ + "void raspi_set_servo_pulsewidth(gpio_pin pin, int pulsewidth)" + ], + "python": [ + "def raspi_set_servo_pulsewidth(pin, pulsewidth):" + ], + "csharp": [ + "public static void SplashKit.RaspiSetServoPulsewidth(GpioPin pin, int pulsewidth);" + ], + "pascal": [ + "procedure RaspiSetServoPulsewidth(pin: GpioPin; pulsewidth: Integer)" + ] + } + }, { "signature": "int raspi_spi_close(int handle);", "name": "raspi_spi_close", @@ -74825,7 +75307,7 @@ { "signature": "typedef struct _adc_data *adc_device;", "name": "adc_device", - "description": "The `adc_device` type is used to refer to ADC (Analog-to-Digital Converter)\ndevices that can be managed by the SplashKit ADC code. ADC devices are:\n\n- loaded with `load_adc_device`,\n\n- accessed using `adc_device_named` or checked with `has_adc_device`,\n\n- read using `read_adc_channel` to retrieve analog values from specific channels,\n\n- and must be released using `free_adc_device` (to release a specific\nADC device) or `free_all_adc_devices` (to release all loaded ADC devices).\n\nADC devices allow you to interface with external analog sensors or inputs,\nconverting their signals into digital values for processing in your application.\n\nYou can check if an ADC device is loaded using `has_adc_device`.\n\nUse `free_adc_device` to release resources associated with a specific ADC device,\nor `free_all_adc_devices` to clean up all ADC devices.", + "description": "The `adc_device` type is used to refer to ADC (Analog-to-Digital Converter)\ndevices that can be managed by the SplashKit ADC code, such as ADS7830.\nADC devices are:\n\n- loaded with `open_adc`,\n- accessed using `adc_device_named` or checked with `has_adc_device`,\n- read using `read_adc` to retrieve analog values from specific channels,\n- and must be closed using `close_adc` (to release a specific\nADC device) or `close_all_adc` (to release all loaded ADC devices).\n\nADC devices allow you to interface with external analog sensors or inputs,\nconverting their signals into digital values for processing in your application.", "brief": null, "attributes": { "class": "adc_device", @@ -85043,9 +85525,9 @@ { "signature": "void free_timer(timer to_free);", "name": "free_timer", - "method_name": null, + "method_name": "free", "unique_global_name": "free_timer", - "unique_method_name": null, + "unique_method_name": "timer.free", "suffix_name": null, "description": "Free the memory used to store this timer.", "brief": null, @@ -85075,9 +85557,10 @@ "attributes": { "class": "timer", "destructor": true, + "method": "free", + "self": "to_free", "group": "timers", - "static": "timers", - "self": "to_free" + "static": "timers" }, "signatures": { "cpp": [ @@ -85087,6 +85570,7 @@ "def free_timer(to_free):" ], "csharp": [ + "public void Timer.Free();", "public static void SplashKit.FreeTimer(Timer toFree);" ], "pascal": [ @@ -93901,19 +94385,19 @@ "number": 3 }, "ADC_PIN_4": { - "description": "Analog Input Channel 4", + "description": "Analog Input Channel 4 (only available for ADS7830)", "number": 4 }, "ADC_PIN_5": { - "description": "Analog Input Channel 5", + "description": "Analog Input Channel 5 (only available for ADS7830)", "number": 5 }, "ADC_PIN_6": { - "description": "Analog Input Channel 6", + "description": "Analog Input Channel 6 (only available for ADS7830)", "number": 6 }, "ADC_PIN_7": { - "description": "Analog Input Channel 7", + "description": "Analog Input Channel 7 (only available for ADS7830)", "number": 7 } }, @@ -93928,7 +94412,7 @@ } }, { - "signature": "enum adc_type {ADS7830 = 0,// PCF8591 = 1,};", + "signature": "enum adc_type {ADS7830 = 0,PCF8591 = 1,};", "name": "adc_type", "description": "ADC Type:", "brief": null, @@ -93936,16 +94420,20 @@ "ADS7830": { "description": "8-Bit, 8-Channel Sampling A/D Converter with I2C Interface", "number": 0 + }, + "PCF8591": { + "description": "8-Bit, 4-Channel Sampling A/D Converter with I2C Interface", + "number": 1 } }, "attributes": { "group": "types" }, "signatures": { - "cpp": "class adc_type {ADS7830 = 0};", - "python": "public enum {AdcType.ads7830 = 0}", - "csharp": "public enum {AdcType.Ads7830 = 0}", - "pascal": "public enum {AdcType.Ads7830 = 0}" + "cpp": "class adc_type {ADS7830 = 0, PCF8591 = 1};", + "python": "public enum {AdcType.ads7830 = 0, AdcType.pcf8591 = 1}", + "csharp": "public enum {AdcType.Ads7830 = 0, AdcType.Pcf8591 = 1}", + "pascal": "public enum {AdcType.Ads7830 = 0, AdcType.Pcf8591 = 1}" } }, { @@ -94022,7 +94510,7 @@ "number": 2 }, "PIN_3": { - "description": "GPIO2 / SDA (I2C)", + "description": "GPIO 2 / SDA (I2C)", "number": 3 }, "PIN_4": { @@ -94030,7 +94518,7 @@ "number": 4 }, "PIN_5": { - "description": "GPIO3 / SCL (I2C)", + "description": "GPIO 3 / SCL (I2C)", "number": 5 }, "PIN_6": { @@ -94038,11 +94526,11 @@ "number": 6 }, "PIN_7": { - "description": "GPIO4", + "description": "GPIO 4 / GPCLK0", "number": 7 }, "PIN_8": { - "description": "GPIO14 / TXD (UART)", + "description": "GPIO 14 / TXD (UART)", "number": 8 }, "PIN_9": { @@ -94050,19 +94538,19 @@ "number": 9 }, "PIN_10": { - "description": "GPIO15 / RXD (UART)", + "description": "GPIO 15 / RXD (UART)", "number": 10 }, "PIN_11": { - "description": "GPIO17", + "description": "GPIO 17", "number": 11 }, "PIN_12": { - "description": "GPIO18 / PCM_CLK", + "description": "GPIO 18 / PCM_CLK", "number": 12 }, "PIN_13": { - "description": "GPIO27", + "description": "GPIO 27", "number": 13 }, "PIN_14": { @@ -94070,11 +94558,11 @@ "number": 14 }, "PIN_15": { - "description": "GPIO22", + "description": "GPIO 22", "number": 15 }, "PIN_16": { - "description": "GPIO23", + "description": "GPIO 23", "number": 16 }, "PIN_17": { @@ -94082,11 +94570,11 @@ "number": 17 }, "PIN_18": { - "description": "GPIO24", + "description": "GPIO 24", "number": 18 }, "PIN_19": { - "description": "GPIO10 / MOSI (SPI)", + "description": "GPIO 10 / MOSI (SPI)", "number": 19 }, "PIN_20": { @@ -94094,19 +94582,19 @@ "number": 20 }, "PIN_21": { - "description": "GPIO9 / MISO (SPI)", + "description": "GPIO 9 / MISO (SPI)", "number": 21 }, "PIN_22": { - "description": "GPIO25", + "description": "GPIO 25", "number": 22 }, "PIN_23": { - "description": "GPIO11 / SCLK (SPI)", + "description": "GPIO 11 / SCLK (SPI)", "number": 23 }, "PIN_24": { - "description": "GPIO8 / CE0 (SPI)", + "description": "GPIO 8 / CE0 (SPI)", "number": 24 }, "PIN_25": { @@ -94114,7 +94602,7 @@ "number": 25 }, "PIN_26": { - "description": "GPIO7 / CE1 (SPI)", + "description": "GPIO 7 / CE1 (SPI)", "number": 26 }, "PIN_27": { @@ -94126,7 +94614,7 @@ "number": 28 }, "PIN_29": { - "description": "GPIO5", + "description": "GPIO 5", "number": 29 }, "PIN_30": { @@ -94134,15 +94622,15 @@ "number": 30 }, "PIN_31": { - "description": "GPIO6", + "description": "GPIO 6", "number": 31 }, "PIN_32": { - "description": "GPIO12", + "description": "GPIO 12 / PWM0", "number": 32 }, "PIN_33": { - "description": "GPIO13", + "description": "GPIO 13", "number": 33 }, "PIN_34": { @@ -94150,19 +94638,19 @@ "number": 34 }, "PIN_35": { - "description": "GPIO19 / MISO (PCM)", + "description": "GPIO 19 / MISO (PCM)", "number": 35 }, "PIN_36": { - "description": "GPIO16 / CE0 (PCM)", + "description": "GPIO 16 / CE0 (PCM_FS)", "number": 36 }, "PIN_37": { - "description": "GPIO26", + "description": "GPIO 26", "number": 37 }, "PIN_38": { - "description": "GPIO20 / MOSI (PCM)", + "description": "GPIO 20 / MOSI (PCM_DIN)", "number": 38 }, "PIN_39": { @@ -94170,7 +94658,7 @@ "number": 39 }, "PIN_40": { - "description": "GPIO21 / SCLK (PCM)", + "description": "GPIO 21 / SCLK (PCM_DOUT)", "number": 40 } }, @@ -94388,6 +94876,50 @@ "pascal": "public enum {InterfaceStyle.FlatDarkStyle = 0, InterfaceStyle.ShadedDarkStyle = 1, InterfaceStyle.FlatLightStyle = 2, InterfaceStyle.ShadedLightStyle = 3, InterfaceStyle.Bubble = 4, InterfaceStyle.BubbleMulticolored = 5}" } }, + { + "signature": "enum motor_direction {MOTOR_FORWARD,MOTOR_BACKWARD};", + "name": "motor_direction", + "description": "Motor Movement Directions:", + "brief": null, + "constants": { + "MOTOR_FORWARD": { + "description": "Motor moves forward." + }, + "MOTOR_BACKWARD": { + "description": "Motor moves backward." + } + }, + "attributes": { + "group": "types" + }, + "signatures": { + "cpp": "class motor_direction {MOTOR_FORWARD = 0, MOTOR_BACKWARD = 0};", + "python": "public enum {MotorDirection.motor_forward = 0, MotorDirection.motor_backward = 0}", + "csharp": "public enum {MotorDirection.MotorForward = 0, MotorDirection.MotorBackward = 0}", + "pascal": "public enum {MotorDirection.MotorForward = 0, MotorDirection.MotorBackward = 0}" + } + }, + { + "signature": "enum motor_driver_type {L298N = 0,// L293D = 1,// TB6612FNG = 2,// DRV8835 = 3,// DRV8834 = 4,// DRV8825 = 5,// A4988 = 6,};", + "name": "motor_driver_type", + "description": "Motor Driver Types:", + "brief": null, + "constants": { + "L298N": { + "description": "Dual H-Bridge Motor Driver", + "number": 0 + } + }, + "attributes": { + "group": "types" + }, + "signatures": { + "cpp": "class motor_driver_type {L298N = 0};", + "python": "public enum {MotorDriverType.l298n = 0}", + "csharp": "public enum {MotorDriverType.L298n = 0}", + "pascal": "public enum {MotorDriverType.L298n = 0}" + } + }, { "signature": "enum pull_up_down {PUD_OFF = 0,PUD_DOWN = 1,PUD_UP = 2};", "name": "pull_up_down", @@ -94960,7 +95492,7 @@ "brief": "Calculates the greatest common divisor of two numbers", "return": { "type": "int", - "description": "Greatest common divisor of the two numbers, or 0 if either of the numbers is not a valid integer above 0", + "description": "Greatest common divisor of the two numbers, or 0 if both numbers are 0", "is_pointer": false, "is_reference": false, "is_vector": false, @@ -95598,7 +96130,7 @@ "brief": "Calculates the least common multiple of two numbers", "return": { "type": "int", - "description": "Least common multiple of the two numbers, or 0 if either of the numbers is not a valid integer above 0", + "description": "Least common multiple of the two numbers, or 0 if either of the numbers are 0", "is_pointer": false, "is_reference": false, "is_vector": false, diff --git a/scripts/json-files/beyond-splashkit-groups.json b/scripts/json-files/beyond-splashkit-groups.json index 4016a01fe..37538ccfe 100644 --- a/scripts/json-files/beyond-splashkit-groups.json +++ b/scripts/json-files/beyond-splashkit-groups.json @@ -1,7 +1,5 @@ [ - "Audio", - "Cryptography", - "Graphics", - "Maths", - "Utilities" + "cryptography", + "sdl2", + "utilities" ] \ No newline at end of file diff --git a/scripts/json-files/guides-groups.json b/scripts/json-files/guides-groups.json index 85cfd9aa0..7fe7bccde 100644 --- a/scripts/json-files/guides-groups.json +++ b/scripts/json-files/guides-groups.json @@ -1,15 +1,16 @@ [ - "Animations", - "Audio", - "Camera", - "Color", - "Graphics", - "Input", - "Interface", - "JSON", - "Networking", - "Physics", - "Raspberry-GPIO", - "Resource-Bundles", - "Utilities" + "animations", + "audio", + "beyond-splashkit", + "camera", + "color", + "graphics", + "input", + "interface", + "json", + "networking", + "physics", + "raspberry-gpio", + "resources", + "utilities" ] \ No newline at end of file diff --git a/scripts/json-files/guides.json b/scripts/json-files/guides.json index 7a308570c..b2e9f8292 100644 --- a/scripts/json-files/guides.json +++ b/scripts/json-files/guides.json @@ -18,7 +18,7 @@ "key_down", "assign_animation" ], - "url": "/guides/animations/0-using-animations/" + "url": "/guides/animations/using-animations/" } ], "audio": [ @@ -36,7 +36,7 @@ "fill_rectangle", "draw_line" ], - "url": "/guides/audio/0-getting-started-with-audio/" + "url": "/guides/audio/getting-started-with-audio/" } ], "camera": [ @@ -54,7 +54,7 @@ "fill_circle", "refresh_screen_with_target_fps" ], - "url": "/guides/camera/0-using-splashkit-camera/" + "url": "/guides/camera/using-splashkit-camera/" } ], "graphics": [ @@ -69,21 +69,26 @@ "refresh_screen", "delay" ], - "url": "/guides/graphics/0-drawing-using-procedures/" + "url": "/guides/graphics/drawing-using-procedures/" }, { "name": "Understanding Double Buffering", "functions": [], - "url": "/guides/graphics/1-double-buffering/" + "url": "/guides/getting-started/double-buffering/" } ], "input": [ { - "name": "Reading Text", + "name": "User Inputs in Graphical Applications", "functions": [ - "write", - "read_line", - "write_line", + "color_red", + "color_yellow", + "color_white", + "clear_screen", + "window_close_requested", + "mouse_down", + "mouse_up", + "mouse_movement", "open_window", "quit_requested", "load_font", @@ -100,24 +105,7 @@ "draw_text", "refresh_screen_with_target_fps" ], - "url": "/guides/input/0-reading-text/" - }, - { - "name": "Using Mouse Inputs", - "functions": [ - "color_red", - "color_yellow", - "color_white", - "process_events", - "mouse_clicked", - "clear_screen", - "refresh_window", - "window_close_requested", - "mouse_down", - "mouse_up", - "mouse_movement" - ], - "url": "/guides/input/1-mouse-button-inputs/" + "url": "/guides/input/user-inputs-in-graphical-applications/" } ], "interface": [ @@ -134,35 +122,23 @@ "draw_interface", "refresh_screen" ], - "url": "/guides/interface/00-interface/" + "url": "/guides/interface/getting-started-with-interfaces/" } ], "json": [ { - "name": "Introduction to JSON in SplashKit", + "name": "Using JSON in SplashKit", "functions": [ "json_from_file", "json_read_string", "write_line", "free_json", - "json_has_key" - ], - "url": "/guides/json/0-json_intro/" - }, - { - "name": "Reading JSON Data in SplashKit", - "functions": [ + "json_has_key", "json_read_array_of_string", "write_line", "write", "json_read_object", - "json_read_number_as_int" - ], - "url": "/guides/json/1-json_reading/" - }, - { - "name": "Writing JSON Data in SplashKit", - "functions": [ + "json_read_number_as_int", "create_json", "json_set_string", "json_set_bool", @@ -175,7 +151,7 @@ "json_read_object", "json_read_number_as_int" ], - "url": "/guides/json/2-json_writing/" + "url": "/guides/json/getting-started-with-json/" } ], "networking": [ @@ -189,7 +165,7 @@ "send_response", "send_html_file_response" ], - "url": "/guides/networking/0-getting-started-with-servers/" + "url": "/guides/networking/getting-started-with-servers/" }, { "name": "Routing With Servers", @@ -202,7 +178,7 @@ "send_html_file_response", "is_get_request_for" ], - "url": "/guides/networking/1-routing-with-servers/" + "url": "/guides/networking/routing-with-servers/" }, { "name": "How to make a RESTful API call using SplashKit", @@ -221,7 +197,7 @@ "json_read_number_as_int", "json_read_string" ], - "url": "/guides/networking/2-restful-api-call/" + "url": "/guides/networking/restful-api-call/" } ], "physics": [ @@ -394,7 +370,7 @@ { "name": "Loading Resources with Bundles", "functions": [], - "url": "/guides/resource-bundles/0-loading-resources-with-bundles/" + "url": "/guides/resources/loading-resources-with-bundles/" } ], "utilities": [ @@ -403,6 +379,7 @@ "functions": [ "convert_to_integer", "write", + "write_line", "write_line_int", "convert_to_double", "write_line_double", @@ -414,7 +391,7 @@ "to_lowercase", "trim" ], - "url": "/guides/utilities/0-useful-utilities/" + "url": "/guides/utilities/useful-utilities/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Animations/animations.json b/scripts/json-files/guides/animations/animations.json similarity index 92% rename from scripts/json-files/guides/Animations/animations.json rename to scripts/json-files/guides/animations/animations.json index e9a2fa215..d17f18bd1 100644 --- a/scripts/json-files/guides/Animations/animations.json +++ b/scripts/json-files/guides/animations/animations.json @@ -18,7 +18,7 @@ "key_down", "assign_animation" ], - "url": "/guides/animations/0-using-animations/" + "url": "/guides/animations/using-animations/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Audio/audio.json b/scripts/json-files/guides/audio/audio.json similarity index 89% rename from scripts/json-files/guides/Audio/audio.json rename to scripts/json-files/guides/audio/audio.json index 251b388b5..55aee036e 100644 --- a/scripts/json-files/guides/Audio/audio.json +++ b/scripts/json-files/guides/audio/audio.json @@ -14,7 +14,7 @@ "fill_rectangle", "draw_line" ], - "url": "/guides/audio/0-getting-started-with-audio/" + "url": "/guides/audio/getting-started-with-audio/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Camera/camera.json b/scripts/json-files/guides/camera/camera.json similarity index 89% rename from scripts/json-files/guides/Camera/camera.json rename to scripts/json-files/guides/camera/camera.json index 116f9ef76..7157ce758 100644 --- a/scripts/json-files/guides/Camera/camera.json +++ b/scripts/json-files/guides/camera/camera.json @@ -14,7 +14,7 @@ "fill_circle", "refresh_screen_with_target_fps" ], - "url": "/guides/camera/0-using-splashkit-camera/" + "url": "/guides/camera/using-splashkit-camera/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Graphics/graphics.json b/scripts/json-files/guides/graphics/graphics.json similarity index 78% rename from scripts/json-files/guides/Graphics/graphics.json rename to scripts/json-files/guides/graphics/graphics.json index d696213c8..bb33314e8 100644 --- a/scripts/json-files/guides/Graphics/graphics.json +++ b/scripts/json-files/guides/graphics/graphics.json @@ -11,12 +11,12 @@ "refresh_screen", "delay" ], - "url": "/guides/graphics/0-drawing-using-procedures/" + "url": "/guides/graphics/drawing-using-procedures/" }, { "name": "Understanding Double Buffering", "functions": [], - "url": "/guides/graphics/1-double-buffering/" + "url": "/guides/getting-started/double-buffering/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Input/input.json b/scripts/json-files/guides/input/input.json similarity index 64% rename from scripts/json-files/guides/Input/input.json rename to scripts/json-files/guides/input/input.json index 01671e59c..ba4236013 100644 --- a/scripts/json-files/guides/Input/input.json +++ b/scripts/json-files/guides/input/input.json @@ -1,11 +1,16 @@ { "guides": [ { - "name": "Reading Text", + "name": "User Inputs in Graphical Applications", "functions": [ - "write", - "read_line", - "write_line", + "color_red", + "color_yellow", + "color_white", + "clear_screen", + "window_close_requested", + "mouse_down", + "mouse_up", + "mouse_movement", "open_window", "quit_requested", "load_font", @@ -22,24 +27,7 @@ "draw_text", "refresh_screen_with_target_fps" ], - "url": "/guides/input/0-reading-text/" - }, - { - "name": "Using Mouse Inputs", - "functions": [ - "color_red", - "color_yellow", - "color_white", - "process_events", - "mouse_clicked", - "clear_screen", - "refresh_window", - "window_close_requested", - "mouse_down", - "mouse_up", - "mouse_movement" - ], - "url": "/guides/input/1-mouse-button-inputs/" + "url": "/guides/input/user-inputs-in-graphical-applications/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Interface/interface.json b/scripts/json-files/guides/interface/interface.json similarity index 86% rename from scripts/json-files/guides/Interface/interface.json rename to scripts/json-files/guides/interface/interface.json index 13960df37..705d2aa74 100644 --- a/scripts/json-files/guides/Interface/interface.json +++ b/scripts/json-files/guides/interface/interface.json @@ -13,7 +13,7 @@ "draw_interface", "refresh_screen" ], - "url": "/guides/interface/00-interface/" + "url": "/guides/interface/getting-started-with-interfaces/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/JSON/json.json b/scripts/json-files/guides/json/json.json similarity index 59% rename from scripts/json-files/guides/JSON/json.json rename to scripts/json-files/guides/json/json.json index 9563cee73..768aa2d9d 100644 --- a/scripts/json-files/guides/JSON/json.json +++ b/scripts/json-files/guides/json/json.json @@ -1,30 +1,18 @@ { "guides": [ { - "name": "Introduction to JSON in SplashKit", + "name": "Using JSON in SplashKit", "functions": [ "json_from_file", "json_read_string", "write_line", "free_json", - "json_has_key" - ], - "url": "/guides/json/0-json_intro/" - }, - { - "name": "Reading JSON Data in SplashKit", - "functions": [ + "json_has_key", "json_read_array_of_string", "write_line", "write", "json_read_object", - "json_read_number_as_int" - ], - "url": "/guides/json/1-json_reading/" - }, - { - "name": "Writing JSON Data in SplashKit", - "functions": [ + "json_read_number_as_int", "create_json", "json_set_string", "json_set_bool", @@ -37,7 +25,7 @@ "json_read_object", "json_read_number_as_int" ], - "url": "/guides/json/2-json_writing/" + "url": "/guides/json/getting-started-with-json/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Networking/networking.json b/scripts/json-files/guides/networking/networking.json similarity index 87% rename from scripts/json-files/guides/Networking/networking.json rename to scripts/json-files/guides/networking/networking.json index f04a6bf92..770e7efd8 100644 --- a/scripts/json-files/guides/Networking/networking.json +++ b/scripts/json-files/guides/networking/networking.json @@ -10,7 +10,7 @@ "send_response", "send_html_file_response" ], - "url": "/guides/networking/0-getting-started-with-servers/" + "url": "/guides/networking/getting-started-with-servers/" }, { "name": "Routing With Servers", @@ -23,7 +23,7 @@ "send_html_file_response", "is_get_request_for" ], - "url": "/guides/networking/1-routing-with-servers/" + "url": "/guides/networking/routing-with-servers/" }, { "name": "How to make a RESTful API call using SplashKit", @@ -42,7 +42,7 @@ "json_read_number_as_int", "json_read_string" ], - "url": "/guides/networking/2-restful-api-call/" + "url": "/guides/networking/restful-api-call/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Physics/physics.json b/scripts/json-files/guides/physics/physics.json similarity index 100% rename from scripts/json-files/guides/Physics/physics.json rename to scripts/json-files/guides/physics/physics.json diff --git a/scripts/json-files/guides/Raspberry-GPIO/raspberry-gpio.json b/scripts/json-files/guides/raspberry-gpio/raspberry-gpio.json similarity index 100% rename from scripts/json-files/guides/Raspberry-GPIO/raspberry-gpio.json rename to scripts/json-files/guides/raspberry-gpio/raspberry-gpio.json diff --git a/scripts/json-files/guides/Resource-Bundles/resource-bundles.json b/scripts/json-files/guides/resource-bundles/resource-bundles.json similarity index 61% rename from scripts/json-files/guides/Resource-Bundles/resource-bundles.json rename to scripts/json-files/guides/resource-bundles/resource-bundles.json index 1bd202307..ff9353da8 100644 --- a/scripts/json-files/guides/Resource-Bundles/resource-bundles.json +++ b/scripts/json-files/guides/resource-bundles/resource-bundles.json @@ -3,7 +3,7 @@ { "name": "Loading Resources with Bundles", "functions": [], - "url": "/guides/resource-bundles/0-loading-resources-with-bundles/" + "url": "/guides/resources/loading-resources-with-bundles/" } ] } \ No newline at end of file diff --git a/scripts/json-files/guides/Utilities/utilities.json b/scripts/json-files/guides/utilities/utilities.json similarity index 85% rename from scripts/json-files/guides/Utilities/utilities.json rename to scripts/json-files/guides/utilities/utilities.json index a630ef6f6..bf6fcce1c 100644 --- a/scripts/json-files/guides/Utilities/utilities.json +++ b/scripts/json-files/guides/utilities/utilities.json @@ -5,6 +5,7 @@ "functions": [ "convert_to_integer", "write", + "write_line", "write_line_int", "convert_to_double", "write_line_double", @@ -16,7 +17,7 @@ "to_lowercase", "trim" ], - "url": "/guides/utilities/0-useful-utilities/" + "url": "/guides/utilities/useful-utilities/" } ] } \ No newline at end of file diff --git a/src/components/PopularTutorials.astro b/src/components/PopularTutorials.astro new file mode 100644 index 000000000..26957d01d --- /dev/null +++ b/src/components/PopularTutorials.astro @@ -0,0 +1,342 @@ +--- +// Popular Tutorials Component +// Displays most popular SplashKit tutorials sorted by views +// Uses mock data API endpoint for Phase 1 implementation +--- + + + + + + diff --git a/src/content/docs/beyond-splashkit/index.mdx b/src/content/docs/beyond-splashkit/index.mdx deleted file mode 100644 index da0dd7cfe..000000000 --- a/src/content/docs/beyond-splashkit/index.mdx +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: Beyond SplashKit -sidebar: - label: "Overview" - order: 0 ---- - - -:::tip["Beyond" SplashKit SDK] - -SplashKit provides a versatile set of categories, encompassing graphics, audio, input, and more, offering developers a comprehensive toolkit for game and multimedia development. - -"Beyond" SplashKit provides tutorials and examples outside of the SplashKit SDK. - -::: - -import BeyondSKList from "../../../components/BeyondSplashKit.astro"; - - - diff --git a/src/content/docs/guides/0-using-splashkit.mdx b/src/content/docs/guides/0-using-splashkit.mdx deleted file mode 100644 index 8e2570733..000000000 --- a/src/content/docs/guides/0-using-splashkit.mdx +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: Using SplashKit -sidebar: - order: 1 ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -Here is a basic overview of how to compile and run SplashKit programs in C++, C# and python. - - - - -To compile C++ SplashKit code, you will use the following command (assuming the code file is named `program.cpp`): - -```shell -clang++ program.cpp -l SplashKit -o test_program -``` - -Or: - -```shell -g++ program.cpp -l SplashKit -o test_program -``` - -Then you can run the program with: - -```shell -./test_program -``` - -Or, if using MSYS2 (MINGW64): - -```shell -./test_program.exe -``` - -:::note[With 'skm'] - -You can also compile your C++ code using the following command: - -```shell -skm clang++ program.cpp -o test_program -``` - -Or: - -```shell -skm g++ program.cpp -o test_program -``` - -::: - - - - -To run C# SplashKit code with dotnet, you will need to first run the command below: - -```shell -dotnet add package SplashKit -``` - -This will add the SplashKit NuGet package, to link the SplashKit SDK to your project. - -Then you can run the program using: - -```shell -dotnet run -``` - -:::note[With 'skm'] - -You can also build and run your C# code using the following command: - -```shell -skm dotnet run -``` - -::: - - - - -To run SplashKit python code, you will use the following command (assuming the code file is named `program.py`): - -```shell -python3 program.py -``` - -:::note[With 'skm'] - -You can also run your Python code using the following command: - -```shell -skm python3 program.py -``` - -::: - - - - -## More Information - -More detailed guides on getting started with SplashKit coming soon... - -For now, you can look at these guides in the [programmers.guide](https://programmers.guide/) online textbook: - -| Language | Overview | Link | -| -------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -| C# | Setting up a basic SplashKit C# project. | [**Your First Program**](https://programmers.guide/book/part-0-getting-started/3-building-programs/1-tour/1-hello-world-cli/) | -| C# | Building a graphical (GUI) SplashKit program. | [**Build Graphical Hello World**](https://programmers.guide/book/part-0-getting-started/3-building-programs/1-tour/1-hello-world-cli/) | -| C++ | Setting up a basic SplashKit C++ program. | [**Hello from C/C++**](https://programmers.guide/book/part-0-getting-started/3-building-programs/1-tour/3-hello-cpp/) | -| C++ | More in-depth C++ guide. | [**Building a C/C++ Program**](https://programmers.guide/book/part-2-organised-code/1-starting-cpp/2-trailside/1-0-building-cpp/) | diff --git a/src/content/docs/guides/Color/0-colour-generator.mdx b/src/content/docs/guides/Color/0-colour-generator.mdx deleted file mode 100644 index c013122d0..000000000 --- a/src/content/docs/guides/Color/0-colour-generator.mdx +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: SplashKit Colours -description: Use this tool to generate the colours you need for your SplashKit projects! -category: Guides -author: Shaun Ratcliff -lastupdated: 11 Dec 24 -tableOfContents: true ---- - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -import ColorGenerator from "/src/components/ColorGenerator.astro"; -import ColorPalette from "/src/components/ColorPalette.astro"; - -## SplashKit Colours - -Colours are at the heart of creating engaging and visually appealing applications, and SplashKit makes working with them seamless. By leveraging industry-standard colour models, SplashKit enables you to work with colours in a way that feels natural and intuitive. - -### Colour RGB(A) - -The RGB(A) model defines colours based on their Red, Green, and Blue components, with an optional Alpha channel to control transparency. Each component ranges from 0 to 255, creating a vast palette of possible colours. Whether you're designing vivid visuals or subtle gradients, RGB(A) is a straightforward way to define and manipulate colours. - -### Colour HSB - -On the other hand, the HSB (Hue, Saturation, Brightness) model offers a more intuitive approach to colour creation. Hue determines the base colour, measured in degrees around a colour wheel (0° for red, 120° for green, 240° for blue, and so on). - -![Colour Wheel](./images/colour_wheel.png) - -Saturation adjusts the intensity of the colour, from a dull gray to a vibrant hue, while Brightness defines how light or dark the color appears. This model is particularly useful for applications where fine-tuning the emotional or thematic tone of visuals is key. - -The tools below will help you to experiment with both models to find your perfect colour. You can also explore the full range of SplashKit colours that have ready-to-use functions for C++, C#, or Python. - -## Colour Generator - -The Colour Generator tool is designed to help you visualise and generate precise colour configurations in both RGB(A) and HSB formats for your SplashKit projects. Whether you’re tweaking Red, Green, and Blue values or adjusting Hue, Saturation, and Brightness, this tool provides immediate visual feedback through a colour preview box. - - - -## Colour Palette - -SplashKit streamlines colour manipulation in graphical applications by providing you with an intuitive and efficient approach to working with colours. This interactive colour palette displays all the available SplashKit colours, allowing you to visually explore and select your desired shade. Once a colour is chosen, the corresponding SplashKit functions in C++, C#, and Python will be shown, making it simple to integrate precise colour choices into your project. - - diff --git a/src/content/docs/guides/Color/images/colour_wheel.png b/src/content/docs/guides/Color/images/colour_wheel.png deleted file mode 100644 index be899bd84..000000000 Binary files a/src/content/docs/guides/Color/images/colour_wheel.png and /dev/null differ diff --git a/src/content/docs/guides/Input/0-reading-text.mdx b/src/content/docs/guides/Input/0-reading-text.mdx deleted file mode 100644 index 8228a0b88..000000000 --- a/src/content/docs/guides/Input/0-reading-text.mdx +++ /dev/null @@ -1,441 +0,0 @@ ---- -title: Reading Text -description: See how to read text from the user, both from command line and graphical applications. -category: Tutorials -author: Andrew Cain and others -lastupdated: October 2024 ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -This article shows you how to get started reading text from the user. This includes reading text from the command line but also how to read text from within a graphical application. - -## Reading Text from the Command Line - -Reading text input from the user is straightforward for command line applications. In this context, [Read Line](/api/terminal/#read-line) allows you to read a line of text entered at the Terminal. This is a **blocking** function call, meaning it waits for the user to input the line before it returns. For command line applications, this is fine; you want it to wait for the input. - -The following code demonstrates the use of [Read Line](/api/terminal/#read-line) in order to read in and display the user's name. - - - - -```cpp -#include "splashkit.h" - -int main() -{ - string name; // declare a variable to store the name - string quest; // and another to store a quest - - write("What is your name: "); // prompt the user for input - name = read_line(); // read user input - - // read in another value - write("And what is your quest? "); - quest = read_line(); - - write_line(name + "'s quest is: " + quest); // output quest to the terminal - - return 0; -} -``` - - - - - - - -```csharp -using static SplashKitSDK.SplashKit; - -string name; // declare a variable to store the name -string quest; // and another to store a quest - -Write("What is your name: "); // prompt the user for input -name = ReadLine(); // read user input - -// Read in another value -Write("And what is your quest? "); -quest = ReadLine(); - -WriteLine(name + "'s quest is: " + quest); // output quest to the terminal -``` - - - - -```csharp -using SplashKitSDK; - -namespace ReadingText -{ - public class Program - { - public static void Main() - { - string name; // declare a variable to store the name - string quest; // and another to store a quest - - SplashKit.Write("What is your name: "); // prompt the user for input - name = SplashKit.ReadLine(); // read user input - - // Read in another value - SplashKit.Write("And what is your quest? "); - quest = SplashKit.ReadLine(); - - SplashKit.WriteLine(name + "'s quest is: " + quest); // output quest to the terminal - } - } -} -``` - - - - - - - -```python -from splashkit import * - -write("What is your name: ") # prompt the user for input -name = read_line() # read user input and store in a variable - -# Read in another value -write("And what is your quest? ") -quest = read_line() - -write_line(name + "'s quest is: " + quest) -``` - - - - -## Reading Text in Graphical Applications - -Reading input from users in graphical applications is more complex, as blocking operations will cause the entire graphical interface to freeze. With a graphical application, you need to keep redrawing, processing events, updating elements, and refreshing the screen. If you stop doing this to wait for user input, then any dynamic visuals will stop! - -Let's see how to read input from the user using some example code. We can then talk through the different parts to understand how they come together to give you a dynamic application with user input. - - - - -```cpp -#include "splashkit.h" - -int main() -{ - // Lets read into this string... - string name = "unknown"; - - // Open a window to show the user... - open_window("Reading Input.", 800, 600); - - // Load a font for text rendering - load_font("input", "arial.ttf"); - - // Define area where text should appear - rectangle rect = rectangle_from(230.0, 50.0, 200.0, 30.0); - - // Start reading text in this area - start_reading_text(rect); - - // Here is our game loop - do - { - // Listen for input... this will update the text read - process_events(); - - // Click anywhere on the screen to trigger the text input - if (mouse_clicked(LEFT_BUTTON)) - { - // Start reading text in the rectagle area - start_reading_text(rect); - } - - // Looks like we finished reading text... - if (not reading_text()) - { - // Was input cancelled? - if (text_entry_cancelled()) - { - name = "unknown"; - } - else - { - // Get the name from the text input - name = text_input(); - } - } - - // Draw the screen... - clear_screen(COLOR_WHITE); - - draw_rectangle(COLOR_BLACK, rect); - - // If we are reading text... then show what it is - if (reading_text()) - { - draw_collected_text(COLOR_BLACK, font_named("input"), 18, option_defaults()); - } - - // Draw text instructions - draw_text("Click anywhere to start reading text", COLOR_RED, font_named("input"), 18, 200, 100); - - // Draw what we have in the name - draw_text(name, COLOR_BLACK, font_named("input"), 18, 10, 10); - - // Show it.. - refresh_screen(60); - } while (!quit_requested()); - - close_all_windows(); - return 0; -} -``` - - - - - - - -```csharp -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Let's read into this string... -string name = "unknown"; - -// Open a window to show the user... -OpenWindow("Reading Input.", 800, 600); - -// Load a font for text rendering -LoadFont("input", "arial.ttf"); - -// Define the area where text should appear -Rectangle rect = RectangleFrom(230.0, 50.0, 200.0, 30.0); - -// Start reading text in this area -StartReadingText(rect); - -// Here is our game loop -do -{ - // Listen for input... this will update the text read - ProcessEvents(); - - // Click anywhere on the screen to trigger the text input - if (MouseClicked(MouseButton.LeftButton)) - { - // Start reading text in the rectagle area - StartReadingText(rect); - } - - // Looks like we finished reading text... - if (!ReadingText()) - { - // Was input canceled? - if (TextEntryCancelled()) - { - name = "unknown"; - } - else - { - // Get the name from the text input - name = TextInput(); - } - } - - // Draw the screen... - ClearScreen(ColorWhite()); - DrawRectangle(ColorBlack(), rect); - - // If we are reading text... then show what it is - if (ReadingText()) - { - DrawCollectedText(ColorBlack(), FontNamed("input"), 18, OptionDefaults()); - } - - // Draw text instructions - DrawText("Click anywhere to start reading text", Color.Red, SplashKit.FontNamed("input"), 18, 200, 100); - - // Draw what we have in the name - DrawText(name, ColorBlack(), FontNamed("input"), 18, 10, 10); - - // Show it... - RefreshScreen(60); -} while (!QuitRequested()); - -CloseAllWindows(); -``` - - - - -```csharp -using SplashKitSDK; - -namespace ReadingInput -{ - public class Program - { - public static void Main() - { - // Let's read into this string... - string name = "unknown"; - - // Open a window to show the user... - Window window = new Window("Reading Input.", 800, 600); - - // Load a font for text rendering - Font font = new Font("input", "arial.ttf"); - - // Define the area where text should appear - Rectangle rect = SplashKit.RectangleFrom(230.0, 50.0, 200.0, 30.0); - - // Start reading text in the rectagle area - SplashKit.StartReadingText(rect); - - // Here is our game loop - do - { - // Listen for input... this will update the text read - SplashKit.ProcessEvents(); - - // Click anywhere on the screen to trigger the text input - if (SplashKit.MouseClicked(MouseButton.LeftButton)) - { - // Start reading text in the rectagle area - SplashKit.StartReadingText(rect); - } - - // Looks like we finished reading text... - if (!SplashKit.ReadingText()) - { - // Was input canceled? - if (SplashKit.TextEntryCancelled()) - { - name = "unknown"; - } - else - { - // Get the name from the text input - name = SplashKit.TextInput(); - } - } - - // Draw the screen... - window.Clear(Color.White); - window.DrawRectangle(Color.Black, rect); - - // If we are reading text... then show what it is - if (SplashKit.ReadingText()) - { - SplashKit.DrawCollectedText(Color.Black, font, 18, SplashKit.OptionDefaults()); - } - - // Draw text instructions - window.DrawText("Click anywhere to start reading text", Color.Red, font, 18, 200, 100); - - // Draw what we have in the name - window.DrawText(name, Color.Black, font, 18, 10, 10); - - // Show it... - window.Refresh(60); - } while (!window.CloseRequested); - - SplashKit.CloseAllWindows(); - } - } -} -``` - - - - - - - -```python -from splashkit import * - -# Lets read into this string... -name = "unknown" - -# Open a window to show the user... -open_window("Reading Input.", 800, 600) - -# Load a font for text rendering -load_font("input", "arial.ttf") - -# Define area where text should appear -rect = rectangle_from(230.0, 50.0, 200.0, 30.0) - -# Start reading text in this area -# This could be in the loop, if we had a button or something to click to trigger this -start_reading_text(rect) - -# Here is our game loop - -while not quit_requested(): - - # Listen for input... thiss will update the text read - process_events() - - # Click anywhere on the screen to trigger the text input - if (mouse_clicked(MouseButton.left_button)): - - # Start reading text in the rectagle area - start_reading_text(rect) - - - # Looks like we finished reading text... - if not reading_text(): - # Was input cancelled - if text_entry_cancelled(): - name = "unknown" - else: - # Get the name from the text input - name = text_input() - - # Draw the screen... - clear_screen(color_white()) - - draw_rectangle_record(color_black(), rect) - - # If we are reading text... then show what it is - if reading_text(): - draw_collected_text(color_black(), font_named("input"), 18, option_defaults()) - - # Draw text instructions - draw_text("Click anywhere to start reading text", color_red(), font_named("input"), 18, 200, 100) - - # Draw what we have in the name - draw_text(name, color_black(), font_named("input"), 18, 10, 10) - - # Show it... - refresh_screen_with_target_fps(60) - -close_all_windows() -``` - - - - -In the above program we want to read in the user's name and store it in the `name` variable. To get started with this we need to open a window and load a font to draw the text and input. There is also the standard event loop that repeats the basic actions of checking user input and drawing the screen until the program is closed. - -The logic for reading input starts with the call to [Start Reading Text](/api/input/#start-reading-text). This tells SplashKit that you want it to collect text input by the user, and that you want it drawn into the passed-in [Rectangle](/api/types/#rectangle) (in this case `rect`). SplashKit is now listening for input from, and collecting this text for you when you call [Process Events](/api/input/#process-events). - -SplashKit will continue reading text from the user until they hit the Escape or Enter key. You can check if text is still being read by calling the [Reading Text](/api/input/#reading-text) function. In this example, we use this to update the name. You can also end text input yourself using the [End Reading Text](/api/input/#end-reading-text) function. - -When the SplashKit is no longer reading text, you can use [Text Entry Cancelled](/api/input/#text-entry-cancelled) to check if the user cancelled (by hitting Escape) the input. To read the actual value entered, you call [Text Input](/api/input/#text-input). This will return the value entered by the user. If they did cancel the input, then this will be an empty string. - -The key with graphical input will be to keep updating the data associated with the graphical elements. This will keep the screen updating as you collect the input from the user. For this, you need to [Start Reading Text](/api/input/#start-reading-text), then at some point collect the [Text Input](/api/input/#text-input) and [End Reading Text](/api/input/#end-reading-text). diff --git a/src/content/docs/guides/JSON/0-json_intro.mdx b/src/content/docs/guides/JSON/0-json_intro.mdx deleted file mode 100644 index f6ef2486f..000000000 --- a/src/content/docs/guides/JSON/0-json_intro.mdx +++ /dev/null @@ -1,304 +0,0 @@ ---- -title: Introduction to JSON in SplashKit -description: JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write, and for machines to parse and generate. -category: Guides -author: Jonathan Tynan and others -lastupdated: October 2024 -sidebar: - label: "Introduction to JSON" ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -### What is JSON? - -[JSON](/api/json/) is often used in various programming environments, including game development, for data storage and configuration. In SplashKit, JSON functionality allows developers to efficiently manage game settings, level data, and more. This section of the tutorial introduces JSON, its basic structure, and provides an overview of its application in SplashKit. - -### Basic Structure of a JSON File - -A basic JSON file might look like this: - -```json -{ - "gameTitle": "My New Game", - "screenSize": { - "width": 800, - "height": 600 - }, - "levels": ["level1", "level2", "level3"] -} -``` - -JSON objects are made up of values associated with keys. In this example, `gameTitle` is the key associated with the string `"My New Game"`, `screenSize` is the key for an object with two numeric values (width and height), and an array of strings is assigned as the value for the key `levels`. - -### Overview of JSON in SplashKit - -SplashKit simplifies the process of working with JSON files in your games. It provides functions for reading JSON files, allowing us to easily retrieve values and load configurations or game data. Additionally, it offers functions for writing JSON files, enabling us to save configurations and game data. - -### Getting Started with JSON in SplashKit - -To begin using JSON in SplashKit, we must have our files in the correct locations. Run the following command in your project directory to generate the resources folder. - -```shell -skm resources -``` - -This command creates sub-folders for each type of resource. One of these is named `json` and that is where we place our JSON files. To begin lets take the example JSON file above and place it into the `json` folder with the name `game_data.json`. To access the values in this file we can now do the following: - - - - -```cpp -#include "splashkit.h" -int main() -{ - json game_data = json_from_file("game_data.json"); - string game_title = json_read_string(game_data, "gameTitle"); - - write_line("Game Title: " + game_title); - - free_json(game_data); - - return 0; -} -``` - - - - - - - -```csharp -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -Json gameData = JsonFromFile("game_data.json"); -string gameTitle = JsonReadString(gameData, "gameTitle"); - -WriteLine("Game Title: " + gameTitle); - -FreeJson(gameData); -``` - - - - -```csharp -using SplashKitSDK; - -namespace GameDataManagement -{ - public class Program - { - public static void Main() - { - Json gameData = SplashKit.JsonFromFile("game_data.json"); - string gameTitle = SplashKit.JsonReadString(gameData, "gameTitle"); - - SplashKit.WriteLine("Game Title: " + gameTitle); - - SplashKit.FreeJson(gameData); - } - } -} -``` - - - - - - - -```python -from splashkit import * - -def main(): - game_data = json_from_file("game_data.json") - game_title = json_read_string(game_data, "gameTitle") - - if not game_title: - write_line("Error retrieving gameTitle.") - else: - write_line(f"Game Title: {game_title}") - - free_json(game_data) - -if __name__ == "__main__": - main() -``` - - - - -In this code example, we first use [Json From File](/api/json/#json-from-file) to load a JSON object containing details from the `game_data.json` file. -Next, we retrieve the value associated with the `gameTitle` key using [Json Read String](/api/json/#json-read-string)and output it to the console. Finally, we free the JSON object using [Free Json](/api/json/#free-json) before exiting the program. This deallocates any memory that was allocated to the JSON object, helping to prevent memory-related errors such as `Segmentation Fault`. We can build this program using the following command. - - - - -```shell -g++ program.cpp -l SplashKit -o json_program -``` - - - - -```shell -dotnet build -``` - - - - -And run it with: - - - - -```shell -./json_program -``` - - - - -```shell -dotnet run -``` - - - - -```shell -skm python3 program.py -``` - - - - -When we run this program, it should display the following output in the console: - -```plaintext -Game Title: My New Game -``` - -### Checking Keys - -But what if we didn't have a `gameTitle` key in our JSON? Well, error messages will be produced indicating that this key is `null`. To prevent this, we can use the [Json Has Key](/api/json/#json-has-key) function to check if the key is present and then do actions based on whether it has been found or not. We could then turn the previous example into the following code: - - - - -```cpp -#include "splashkit.h" -int main() -{ - json game_data = json_from_file("game_data.json"); - - if(json_has_key(game_data, "gameTitle")) - { - string game_title = json_read_string(game_data, "gameTitle"); - write("Game Title: "); - write_line(game_title); - } - else - { - write_line("Key \"gameTitle\" not found."); - } - - free_json(game_data); - - return 0; -} -``` - - - - - - - -```csharp -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -Json gameData = JsonFromFile("game_data.json"); - -if (JsonHasKey(gameData, "gameTitle")) -{ - string gameTitle = JsonReadString(gameData, "gameTitle"); - WriteLine("Game Title: " + gameTitle); -} -else -{ - WriteLine("Key \"gameTitle\" not found."); -} - -FreeJson(gameData); -``` - - - - -```csharp -using SplashKitSDK; - -namespace GameDataManagement -{ - public class Program - { - public static void Main() - { - Json gameData = SplashKit.JsonFromFile("game_data.json"); - - if (SplashKit.JsonHasKey(gameData, "gameTitle")) - { - string gameTitle = SplashKit.JsonReadString(gameData, "gameTitle"); - SplashKit.WriteLine("Game Title: " + gameTitle); - } - else - { - SplashKit.WriteLine("Key \"gameTitle\" not found."); - } - - SplashKit.FreeJson(gameData); - } - } -} -``` - - - - - - - -```python -from splashkit import * - -def main(): - game_data = json_from_file("game_data.json") - - if json_has_key(game_data, "gameTitle"): - game_title = json_read_string(game_data, "gameTitle") - write_line(f"Game Title: {game_title}") - else: - write_line('Key "gameTitle" not found.') - - free_json(game_data) - -if __name__ == "__main__": - main() -``` - - - - -We have successfully loaded our JSON file and retrieved the value associated with the `gameTitle` key. In the next tutorial, we'll delve deeper into retrieving other values stored within a JSON object. diff --git a/src/content/docs/guides/JSON/1-json_reading.mdx b/src/content/docs/guides/JSON/1-json_reading.mdx deleted file mode 100644 index b2ebc338b..000000000 --- a/src/content/docs/guides/JSON/1-json_reading.mdx +++ /dev/null @@ -1,443 +0,0 @@ ---- -title: Reading JSON Data in SplashKit -description: After understanding the basics of JSON in SplashKit, this part of the tutorial focuses on how to read and parse JSON data. Reading JSON data is essential for game development tasks such as loading game settings, level configurations, or player data. -category: Guides -author: Jonathan Tynan and others -lastupdated: December 2024 -sidebar: - label: "Reading JSON Data" ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -## Reading JSON Objects - -In the previous tutorial we loaded the following JSON file and read the game title from it. Lets extend this a little, and dive a further into extracting values from this structure. - -```json -{ - "gameTitle": "My New Game", - "fullScreenMode": false, - "numPlayers": 1, - "screenSize": { - "width": 800, - "height": 600 - }, - "levels": ["level1", "level2", "level3"] -} -``` - -### Accessing Values - -To access values in JSON objects like strings, numbers, or booleans, you can use functions like [Json Read String](/api/json/#json-read-string), [Json Read Number As Int](/api/json/#json-read-number-as-int), or [Json Read Bool](/api/json/#json-read-bool). We use these functions like the following code snippet. - - - - -```cpp -json game_data = json_from_file("game_data.json"); - -string title = json_read_string(game_data, "gameTitle"); -int numPlayers = json_read_number_as_int(game_data, "numPlayers"); -bool isFullScreen = json_read_bool(game_data, "fullScreenMode"); -``` - - - - - - - - -```csharp -Json gameData = JsonFromFile("game_data.json"); - -string title = JsonReadString(gameData, "gameTitle"); -int numPlayers = JsonReadNumberAsInt(gameData, "numPlayers"); -bool isFullScreen = JsonReadBool(gameData, "fullScreenMode"); -``` - - - - -```csharp -Json gameData = SplashKit.JsonFromFile("game_data.json"); - -string title = SplashKit.JsonReadString(gameData, "gameTitle"); -int numPlayers = SplashKit.JsonReadNumberAsInt(gameData, "numPlayers"); -bool isFullScreen = SplashKit.JsonReadBool(gameData, "fullScreenMode"); -``` - - - - - - - -```python -game_data = json_from_file("game_data.json") - -title = json_read_string(game_data, "gameTitle") -num_players = json_read_number_as_int(game_data, "numPlayers") -is_full_screen = json_read_bool(game_data, "fullScreenMode") -``` - - - - -### Working with JSON Arrays - -If the data is an array, like the value stored for the `levels` key, we can obtain the data through [Json Read Array](/api/json/#json-read-array-functions) and store it into a dynamic string array variable (such as `vector` in C++, or `List` in C#). Then we can loop through the entries in the array, and do some actions with the stored data. - -Below is an example of this: - - - - -```cpp -vector levels; - -json_read_array(game_data, "levels", levels); - -int num_levels = levels.size(); - -for(int i = 0; i < num_levels; i++) -{ - write("Got level: "); - write_line(levels[i]); -} -``` - - - - - - - - -```csharp -List levels = new List(); - -JsonReadArray(gameData, "levels", ref levels); - -int numLevels = levels.Count; - -for (int i = 0; i < numLevels; i++) -{ - WriteLine($"Got level: {levels[i]}"); -} -``` - - - - -```csharp -List levels = new List(); - -SplashKit.JsonReadArray(gameData, "levels", ref levels); - -int numLevels = levels.Count; - -for (int i = 0; i < numLevels; i++) -{ - SplashKit.WriteLine($"Got level: {levels[i]}"); -} -``` - - - - - - - -```python -levels = [] - -json_read_array_of_string(game_data, "levels", levels) - -num_levels = len(levels) - -for i in range(num_levels): - write_line(f"Got level: {levels[i]}") -``` - - - - -Running this prints the following to the terminal: - -```plaintext -Got level: level1 -Got level: level2 -Got level: level3 -``` - -### Extracting Nested JSON Objects - -SplashKit's JSON functionality allows you to extract various types of data, including basic types mentioned previously, but also even nested JSON objects. In our example file the value for the `screenSize` key is a JSON object. The following code demonstrates how to extract this object: - - - - -```cpp -json game_screen_size = json_read_object(game_data, "screenSize"); -int width = json_read_number_as_int(game_screen_size, "width"); -int height = json_read_number_as_int(game_screen_size, "height"); - -write_line("Screen Width: " + to_string(width)); -write_line("Screen Height: " + to_string(height)); -``` - - - - - - - - -```csharp -Json gameScreenSize = JsonReadObject(gamedata, "screenSize"); -int width = JsonReadNumberAsInt(gameScreenSize, "width"); -int height = JsonReadNumberAsInt(gameScreenSize, "height"); - -WriteLine($"Screen Width: {width}"); -WriteLine($"Screen Height: {height}"); -``` - - - - -```csharp -Json gameScreenSize = SplashKit.JsonReadObject(gamedata, "screenSize"); -int width = SplashKit.JsonReadNumberAsInt(gameScreenSize, "width"); -int height = SplashKit.JsonReadNumberAsInt(gameScreenSize, "height"); - -SplashKit.WriteLine($"Screen Width: {width}"); -SplashKit.WriteLine($"Screen Height: {height}"); -``` - - - - - - - -```python -game_screen_size = json_read_object(game_data, "screenSize") -width = json_read_number_as_int(game_screen_size, "width") -height = json_read_number_as_int(game_screen_size, "height") - -write_line(f"Screen Width: {width}") -write_line(f"Screen Height: {height}") -``` - - - - -Running this prints the following to the terminal: - -```plaintext -Screen Width: 800 -Screen Height: 600 -``` - -### Putting it all together - -By combining all these examples we can create the full program shown below. - - - - -```cpp -#include "splashkit.h" -using namespace std; - -int main() -{ - // Load the game data JSON file - json game_data = json_from_file("game_data.json"); - - // Read the game data from the JSON - string title = json_read_string(game_data, "gameTitle"); - int numPlayers = json_read_number_as_int(game_data, "numPlayers"); - bool isFullScreen = json_read_bool(game_data, "fullScreenMode"); - vector levels; - - // Write the game data to the terminal - write_line("Game Title: " + title); - write_line("Number of Players: " + to_string(numPlayers)); - write_line("Full Screen Mode: " + to_string(isFullScreen)); - - // Read the levels array from the JSON - json_read_array(game_data, "levels", levels); - - int num_levels = levels.size(); - - for (int i = 0; i < num_levels; i++) - { - write("Got level: "); - write_line(levels[i]); - } - - // Extract the nested JSON objects - json game_screen_size = json_read_object(game_data, "screenSize"); - int width = json_read_number_as_int(game_screen_size, "width"); - int height = json_read_number_as_int(game_screen_size, "height"); - - // Write the screen size to the terminal - write_line("Screen Width: " + to_string(width)); - write_line("Screen Height: " + to_string(height)); -} -``` - - - - - - - - -```csharp -using SplashKitSDK; -using static SplashKitSDK.SplashKit; - -// Load the game data JSON file -Json gameData = JsonFromFile("game_data.json"); - -// Read the game data from the JSON -string title = JsonReadString(gameData, "gameTitle"); -int numPlayers = JsonReadNumberAsInt(gameData, "numPlayers"); -bool isFullScreen = JsonReadBool(gameData, "fullScreenMode"); -List levels = new List(); - -// Write the game data to the terminal -WriteLine($"Game Title: {title}"); -WriteLine($"Number of Players: {numPlayers}"); -WriteLine($"Full Screen Mode: {isFullScreen}"); - -// Read the levels array from the JSON -JsonReadArray(gameData, "levels", ref levels); - -int numLevels = levels.Count; - -for (int i = 0; i < numLevels; i++) -{ - WriteLine($"Got level: {levels[i]}"); -} - -// Extract the nested JSON objects -Json gameScreenSize = JsonReadObject(gameData, "screenSize"); -int width = JsonReadNumberAsInt(gameScreenSize, "width"); -int height = JsonReadNumberAsInt(gameScreenSize, "height"); - -// Write the screen size to the terminal -WriteLine($"Screen Width: {width}"); -WriteLine($"Screen Height: {height}"); -``` - - - - -```csharp -using System; -using System.Collections.Generic; -using SplashKitSDK; - -class Program -{ - static void Main() - { - // Load the game data JSON file - Json gameData = SplashKit.JsonFromFile("game_data.json"); - - // Read the game data from the JSON - string title = SplashKit.JsonReadString(gameData, "gameTitle"); - int numPlayers = SplashKit.JsonReadNumberAsInt(gameData, "numPlayers"); - bool isFullScreen = SplashKit.JsonReadBool(gameData, "fullScreenMode"); - List levels = new List(); - - // Write the game data to the terminal - SplashKit.WriteLine($"Game Title: {title}"); - SplashKit.WriteLine($"Number of Players: {numPlayers}"); - SplashKit.WriteLine($"Full Screen Mode: {isFullScreen}"); - - // Read the levels array from the JSON - SplashKit.JsonReadArray(gameData, "levels", ref levels); - - int numLevels = levels.Count; - - for (int i = 0; i < numLevels; i++) - { - SplashKit.WriteLine($"Got level: {levels[i]}"); - } - - // Extract the nested JSON objects - Json gameScreenSize = SplashKit.JsonReadObject(gameData, "screenSize"); - int width = SplashKit.JsonReadNumberAsInt(gameScreenSize, "width"); - int height = SplashKit.JsonReadNumberAsInt(gameScreenSize, "height"); - - // Write the screen size to the terminal - SplashKit.WriteLine($"Screen Width: {width}"); - SplashKit.WriteLine($"Screen Height: {height}"); - } -} - -``` - - - - - - - -```python -from splashkit import * - -# Load the game data JSON file -game_data = json_from_file("game_data.json") - -# Read the game data from the JSON object -title = json_read_string(game_data, "gameTitle") -num_players = json_read_number_as_int(game_data, "numPlayers") -is_full_screen = json_read_bool(game_data, "fullScreenMode") -levels = [] - -# Write the game data to the terminal -write_line(f"Game Title: {title}") -write_line(f"Number of Players: {num_players}") -write_line(f"Full Screen Mode: {is_full_screen}") - -# Read the levels array from the JSON file -json_read_array_of_string(game_data, "levels", levels) - -num_levels = len(levels) - -for i in range(num_levels): - write_line(f"Got level: {levels[i]}") - -# Extract the nested JSON objects -game_screen_size = json_read_object(game_data, "screenSize") -width = json_read_number_as_int(game_screen_size, "width") -height = json_read_number_as_int(game_screen_size, "height") - -# Write the screen size to the terminal -write_line(f"Screen Width: {width}") -write_line(f"Screen Height: {height}") -``` - - - - -In this example, [Json Read Object](/api/json/#json-read-object) is used to extract the nested JSON object, and then the values are read from this nested object. These variables can then be used to define the window size for this game. - -### Conclusion - -Reading JSON data with SplashKit is a straightforward process that can greatly enhance the flexibility and functionality of your game. It enables dynamic loading of game content and configurations, making your game more adaptable and easier to manage. - -In the next part of this tutorial, we explore how to write and modify JSON data, allowing you to save game states, configurations, and player preferences. diff --git a/src/content/docs/guides/JSON/2-json_writing.mdx b/src/content/docs/guides/JSON/2-json_writing.mdx deleted file mode 100644 index 887000e43..000000000 --- a/src/content/docs/guides/JSON/2-json_writing.mdx +++ /dev/null @@ -1,640 +0,0 @@ ---- -title: Writing JSON Data in SplashKit -description: Having covered how to read JSON data in SplashKit, this part of the tutorial focuses on creating and writing data to JSON files. This functionality is crucial for features like saving game settings or player progress and information. -category: Guides -author: Jonathan Tynan and others -lastupdated: December 2024 -sidebar: - label: "Writing JSON Data" ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -### Creating JSON Objects and Arrays - -In SplashKit, you can programmatically create JSON objects and arrays, which then can be populated with data. Lets see how we can create the example JSON file from previous tutorials with this method. - - - - -```cpp -json new_game_data = create_json(); -json_set_string(new_game_data, "gameTitle", "My New Game"); -json_set_bool(new_game_data, "fullScreenMode", false); -json_set_number(new_game_data, "numPlayers", 1); -``` - - - - - - - -```csharp -Json newGameData = CreateJson(); -JsonSetString(newGameData, "gameTitle", "My New Game"); -JsonSetBool(newGameData, "fullScreenMode", false); -JsonSetNumber(newGameData, "numPlayers", 1); -``` - - - - -```csharp -Json newGameData = SplashKit.CreateJson(); -SplashKit.JsonSetString(newGameData, "gameTitle", "My New Game"); -SplashKit.JsonSetBool(newGameData, "fullScreenMode", false); -SplashKit.JsonSetNumber(newGameData, "numPlayers", 1); -``` - - - - - - - -```python -new_game_data = create_json() - -json_set_string(new_game_data, "gameTitle", "My New Game") -json_set_bool(new_game_data, "fullScreenMode", False) -json_set_number_integer(new_game_data, "numPlayers", 1) -``` - - - - -First we create the new JSON object using [Create Json](/api/json/#create-json), then we add basic data to **gameTitle**, **fullScreenMode**, and **numPlayers** using [Json Set String](/api/json/#json-set-string), [Json Set Bool](/api/json/#json-set-bool) and [Json Set Number](/api/json#json-set-number-functions). - - - - -```cpp -vector levels_array; - -levels_array.push_back("level1"); -levels_array.push_back("level2"); -levels_array.push_back("level3"); - -json_set_array(new_game_data, "levels", levels_array); -``` - - - - - - - -```csharp -List levelsArray = new List -{ - "level1", - "level2", - "level3" -}; - -JsonSetArray(newGameData, "levels", levelsArray); -``` - - - - -```csharp -List levelsArray = new List -{ - "level1", - "level2", - "level3" -}; - -SplashKit.JsonSetArray(newGameData, "levels", levelsArray); -``` - - - - - - - -```python -levels_array = ["level1", "level2", "level3"] -json_set_array_of_string(new_game_data, "levels", levels_array) -``` - - - - -Next we add the levels array to the JSON object. We create a vector to store the strings, and push back each string that we want. Finally we use [Json Set Array](/api/json/#json-set-array-functions) to store this data in JSON format. - - - - -```cpp -json screen_size_data = create_json(); - -json_set_number(screen_size_data, "width", 800); -json_set_number(screen_size_data, "height", 600); - -json_set_object(new_game_data, "screenSize", screen_size_data); -``` - - - - - - - -```csharp -Json screenSizeData = CreateJson(); - -JsonSetNumber(screenSizeData, "width", 800); -JsonSetNumber(screenSizeData, "height", 600); - -JsonSetObject(newGameData, "screenSize", screenSizeData); -``` - - - - -```csharp -Json screenSizeData = SplashKit.CreateJson(); - -SplashKit.JsonSetNumber(screenSizeData, "width", 800); -SplashKit.JsonSetNumber(screenSizeData, "height", 600); - -SplashKit.JsonSetObject(newGameData, "screenSize", screenSizeData); -``` - - - - - - - -```python -screen_size_data = create_json() - -json_set_number_integer(screen_size_data, "width", 800) -json_set_number_integer(screen_size_data, "height", 600) - -json_set_object(new_game_data, "screenSize", screen_size_data) -``` - - - - -Then we tackle the nested JSON object, the screen size object. We use [Create Json](/api/json/#create-json) to create a new object for this data, and then we add the width and the height to the object using [Json Set Number](/api/json/#json-set-number-functions). Now that we have this JSON object filled with the data we want, we add it to the `new_game_data` object with [Json Set Object](/api/json/#json-set-object). - -### Writing JSON Data to a File - -Now that we have the `new_game_data` object that stores the same values as the JSON file used previously. Now, we can save this using [Json To File](/api/json/#json-to-file) like in the code below. - -:::note -Make sure to run `skm resources` to create the `Resources/json/` folder before executing this code. -::: - - - - -```cpp -json_to_file(new_game_data, "new_game_data.json"); -``` - - - - - - - -```csharp -JsonToFile(newGameData, "new_game_data.json"); - -``` - - - - -```csharp -SplashKit.JsonToFile(newGameData, "new_game_data.json"); -``` - - - - - - - -```python -json_to_file(new_game_data, "new_game_data.json") -``` - - - - -By combining all these examples we can create the full program shown below. - - - - -```cpp -#include "splashkit.h" - -int main() -{ - json new_game_data = create_json(); - - json_set_string(new_game_data, "gameTitle", "My New Game"); - json_set_bool(new_game_data, "fullScreenMode", false); - json_set_number(new_game_data, "numPlayers", 1); - - json screen_size_data = create_json(); - - json_set_number(screen_size_data, "width", 800); - json_set_number(screen_size_data, "height", 600); - - json_set_object(new_game_data, "screenSize", screen_size_data); - - vector levels_array; - - levels_array.push_back("level1"); - levels_array.push_back("level2"); - levels_array.push_back("level3"); - - json_set_array(new_game_data, "levels", levels_array); - - json_to_file(new_game_data, "new_game_data.json"); - - free_all_json(); -} -``` - - - - - - - -```csharp -using SplashKitSDK; -using static SplashKitSDK.SplashKit; -using System.Collections.Generic; - -Json newGameData = CreateJson(); - -JsonSetString(newGameData, "gameTitle", "My New Game"); -JsonSetBool(newGameData, "fullScreenMode", false); -JsonSetNumber(newGameData, "numPlayers", 1); - -Json screenSizeData = CreateJson(); -JsonSetNumber(screenSizeData, "width", 800); -JsonSetNumber(screenSizeData, "height", 600); - -JsonSetObject(newGameData, "screenSize", screenSizeData); - -List levelsArray = new List -{ - "level1", - "level2", - "level3" -}; - -JsonSetArray(newGameData, "levels", levelsArray); - -JsonToFile(newGameData, "new_game_data.json"); -FreeJson(newGameData); - -FreeJson(screenSizeData); -``` - - - - -```csharp -using SplashKitSDK; -using System.Collections.Generic; - -namespace WritingJsonData -{ - public class Program - { - public static void Main() - { - Json newGameData = SplashKit.CreateJson(); - - SplashKit.JsonSetString(newGameData, "gameTitle", "My New Game"); - SplashKit.JsonSetBool(newGameData, "fullScreenMode", false); - SplashKit.JsonSetNumber(newGameData, "numPlayers", 1); - - Json screenSizeData = SplashKit.CreateJson(); - SplashKit.JsonSetNumber(screenSizeData, "width", 800); - SplashKit.JsonSetNumber(screenSizeData, "height", 600); - - SplashKit.JsonSetObject(newGameData, "screenSize", screenSizeData); - - List levelsArray = new List - { - "level1", - "level2", - "level3" - }; - - SplashKit.JsonSetArray(newGameData, "levels", levelsArray); - - SplashKit.JsonToFile(newGameData, "new_game_data.json"); - SplashKit.FreeJson(newGameData); - - SplashKit.FreeJson(screenSizeData); - } - } -} -``` - - - - - - - -```python -from splashkit import * - -new_game_data = create_json() - -json_set_string(new_game_data, "gameTitle", "My New Game") -json_set_bool(new_game_data, "fullScreenMode", False) -json_set_number_integer(new_game_data, "numPlayers", 1) - -screen_size_data = create_json() -json_set_number_integer(screen_size_data, "width", 800) -json_set_number_integer(screen_size_data, "height", 600) - -json_set_object(new_game_data, "screenSize", screen_size_data) - -levels_array = ["level1", "level2", "level3"] - -json_set_array_of_string(new_game_data, "levels", levels_array) -json_to_file(new_game_data, "new_game_data.json") - -free_all_json() -``` - - - - -Running this program results in a file named `new_game_data.json` being written to the `Resources/json/` folder. Open this up and you'll see something very similar or identical to the example JSON file we've been using previously. It should look something like this: - -```json -{ - "numPlayers": 1, - "fullScreenMode": false, - "gameTitle": "My New Game", - "levels": [ - "level1", - "level2", - "level3" - ], - "screenSize": { - "height": 600, - "width": 800 - } -} -``` - -Some of the keys can be in different positions, but this does not affect how we use it as we look for the key when retrieving values, not a particular data position in the JSON file. This new file is effectively the same JSON that we've used in previous JSON tutorials. - -### Modifying Existing JSON Data - -You can also load an existing JSON file, modify its contents, and save the changes back to the file. To demonstrate this, lets add the details of a player character to our game data. - - - - -```cpp -json player_data = create_json(); -json_set_string(player_data, "name", "Hero"); - -json stats_data = create_json(); -json_set_number(stats_data, "health", 100); -json_set_number(stats_data, "mana", 50); -json_set_number(stats_data, "strength", 75); - -json_set_object(player_data, "stats", stats_data); -``` - - - - - - - -```csharp -Json playerData = CreateJson(); -JsonSetString(playerData, "name", "Hero"); - -Json statsData = CreateJson(); -JsonSetNumber(statsData, "health", 100); -JsonSetNumber(statsData, "mana", 50); -JsonSetNumber(statsData, "strength", 75); - -JsonSetObject(playerData, "stats", statsData); -``` - - - - -```csharp -Json playerData = SplashKit.CreateJson(); -SplashKit.JsonSetString(playerData, "name", "Hero"); - -Json statsData = SplashKit.CreateJson(); -SplashKit.JsonSetNumber(statsData, "health", 100); -SplashKit.JsonSetNumber(statsData, "mana", 50); -SplashKit.JsonSetNumber(statsData, "strength", 75); - -SplashKit.JsonSetObject(playerData, "stats", statsData); -``` - - - - - - - -```python -player_data = create_json() -json_set_string(player_data, "name", "Hero") - -stats_data = create_json() -json_set_number_integer(stats_data, "health", 100) -json_set_number_integer(stats_data, "mana", 50) -json_set_number_integer(stats_data, "strength", 75) - -json_set_object(player_data, "stats", stats_data) -``` - - - - -First we create the player JSON object to store the data for an entire character, then we create an individual object to hold the stats for the character. After this we add the stats object and nest it in the `player_data` object we created earlier. - - - - -```cpp -json existing_data = json_from_file("new_game_data.json") -json_set_object(existing_data, "character", player_data); - -json_to_file(existing_data, "modified_game_data.json"); -``` - - - - - - - -```csharp -Json existingData = JsonFromFile("new_game_data.json"); -JsonSetObject(existingData, "character", playerData); - -JsonToFile(existingData, "modified_game_data.json"); -``` - - - - -```csharp -Json existingData = SplashKit.JsonFromFile("new_game_data.json"); -SplashKit.JsonSetObject(existingData, "character", playerData); - -SplashKit.JsonToFile(existingData, "modified_game_data.json"); -``` - - - - - - - -```python -existing_data = json_from_file("new_game_data.json") -json_set_object(existing_data, "character", player_data) - -json_to_file(existing_data, "modified_game_data.json") -``` - - - - -Next we load the game data we saved previously, add our `player_data` object to the existing data and save it. If we add this code to our previous program and run it a file is created in the `Resources/json/` folder named `modified_game_data.json`. Open it, and you should see something like the following: - -```json -{ - "character": { - "name": "Hero", - "stats": { - "health": 100, - "mana": 50, - "strength": 75 - } - }, - "fullScreenMode": false, - "numPlayers": 1, - "gameTitle": "My New Game", - "levels": [ - "levels1", - "levels2", - "levels3" - ], - "screenSize": { - "height": 600, - "width": 800 - } -} -``` - -Now we have a character object stored with this JSON file. We also now have multiple levels of nesting. When this is the case and we want to access the innermost key we must get these JSON objects. So, to access the health stat we can use the following code: - - - - -```cpp -// Load our JSON -json modified_game_data = json_from_file("modified_game_data.json"); -// Retrieve Character JSON object from the file. -json character = json_read_object(modified_game_data, "character"); -// Retrieve the Stats JSON object from the Character JSON -json stats = json_read_object(character, "stats"); -// Retrieve the value of health from the stats JSON object -int hp = json_read_number_as_int(stats, "health"); -``` - - - - - - - -```csharp -// Load our JSON -Json modifiedGameData = JsonFromFile("modified_game_data.json"); - -// Retrieve Character JSON object from the file. -Json modifiedGameData = JsonFromFile("modified_game_data.json"); - -// Retrieve the Stats JSON object from the Character JSON -Json stats = JsonReadObject(character, "stats"); - -// Retrieve the value of health from the stats JSON object -int hp = JsonReadNumberAsInt(stats, "health"); -``` - - - - -```csharp -// Load our JSON -Json modifiedGameData = SplashKit.JsonFromFile("modified_game_data.json"); - -// Retrieve Character JSON object from the file. -Json character = SplashKit.JsonReadObject(modifiedGameData, "character"); - -// Retrieve the Stats JSON object from the Character JSON -Json stats = SplashKit.JsonReadObject(character, "stats"); - -// Retrieve the value of health from the stats JSON object -int hp = SplashKit.JsonReadNumberAsInt(stats, "health"); -``` - - - - - - - -```python -# Load our JSON -modified_game_data = json_from_file("modified_game_data.json") - -# Retrieve Character JSON object from the file. -character = json_read_object(modified_game_data, "character") - -# Retrieve the Stats JSON object from the Character JSON -stats = json_read_object(character, "stats") - -# Retrieve the value of health from the stats JSON object -hp = json_read_number_as_int(stats, "health") -``` - - - - -### Conclusion - -By following this tutorial, you're now equipped with the foundational skills necessary to create, read and write JSON data objects with SplashKit. These examples have been focused around game development, but the JSON skills you've learnt extends beyond this as JSON is a versatile tool for any software development project. diff --git a/src/content/docs/guides/Raspberry-GPIO/1-read-button-press.mdx b/src/content/docs/guides/Raspberry-GPIO/1-read-button-press.mdx deleted file mode 100644 index 27bdae197..000000000 --- a/src/content/docs/guides/Raspberry-GPIO/1-read-button-press.mdx +++ /dev/null @@ -1,507 +0,0 @@ ---- -title: Reading Button Presses -description: - Reading GPIO inputs is a crucial component of creating responsive projects. In this guide we learn - to read GPIO inputs by using a simple button to turn an LED on and off. -category: Guides -author: Jonathan Tynan -lastupdated: December 2024 ---- - -import { Tabs, TabItem , Steps} from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -:::caution[Before you begin.] -When working with Raspberry Pi GPIO pins, it's crucial to handle the setup and cleanup processes carefully. - -- Always ensure that the GPIO pins are properly initialised before use and cleaned up afterwards to prevent any damage to your Raspberry Pi -- Be mindful of static electricity which can pose a serious risk to the sensitive electronic components on the board -- Before touching the Raspberry Pi or any connected components, ground yourself to eliminate any static charge that may have accumulated. - -These precautions help to protect your device from potential harm caused by electrostatic discharges. -::: - -In this guide, we explore how to use the GPIO pins on a Raspberry Pi to read button presses. This ability is crucial for projects involving user input, like interactive installations or basic controls for robotics. We look at the basics of setting up a circuit with a button, how to use the SplashKit library to detect the button press and briefly introduce more advanced topics like the concept of floating pins and debouncing. - -## Components - -### Breadboard - -Breadboards are invaluable for testing and building circuits without the need for soldering. Arranged in rows and columns of holes, each row internally connected. See [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led/#components) for more details. - -### Push Button - -A push button allows electricity to flow between its two contacts by physically moving strips of metal together when pressed. This connects the circuit and provides power to our input pin. This pushbutton has four pins and each diagonal pin is paired with each other. It's a simple switch mechanism which we can detect and use. - -### Jumper Wires - -Jumper wires connect our components on the breadboard to the Raspberry Pi and each other. We use M/F jumper wires for this setup. See [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led/#components) for more details. - -## The Circuit - -Below is the circuit diagram for this project. We connect the power and ground to the appropriate rails on the breadboard and connect our components ground or power connections to these rails. We can have the LED directly connected to Pin 11 on the Raspberry Pi, and the button to Pin 29. - -![Circuit Diagram for reading a button press](./images/circuits/buttonpush.png) - -The physical circuit is show in the below image, where we can see the physical implementation of the provided circuit diagram. Note: The power and ground rail connections are swapped in the below image due to the orientation of the breadboard, ensure your connections are correct. - -![Photograph of circuit for reading a button press](./images/circuits/push_button_circuit.png) - -## The Code - -:::caution[Before running the code.] -This code requires the `pigpio` daemon, so make sure it is running! For more information see: [Starting the Daemon](/guides/raspberry-gpio/0-blink-led/#starting-the-daemon) -::: - - - - - ```cpp - #include "splashkit.h" - - int main() - { - raspi_init(); - pins button_pin = PIN_29; - pins led_pin = PIN_11; - pin_values led_state = GPIO_LOW; - - raspi_set_mode(button_pin, GPIO_INPUT); - raspi_set_mode(led_pin, GPIO_OUTPUT); - - raspi_set_pull_up_down(button_pin, PUD_DOWN); - - open_window("dummy_window", 1, 1); - while(!any_key_pressed()) - { - process_events(); - if(raspi_read(button_pin) == GPIO_HIGH) - { - led_state = raspi_read(led_pin); - if(led_state == GPIO_LOW) - { - raspi_write(led_pin, GPIO_HIGH); - } - else - { - raspi_write(led_pin, GPIO_LOW); - } - } - } - - close_all_windows(); - raspi_cleanup(); - return 0; - } - ``` - - - - - - - - ```csharp - using SplashKitSDK; - using static SplashKitSDK.SplashKit; - - RaspiInit(); - Pins button_pin = (Pins)29; - Pins led_pin = (Pins)11; - PinValues led_state = (PinValues) 0; - - RaspiSetMode(button_pin, (PinModes) 0); - RaspiSetMode(led_pin, (PinModes) 1); - - RaspiSetPullUpDown(button_pin, (PullUpDown) 1); - - OpenWindow("dummy_window", 1, 1); - while(!AnyKeyPressed()) - { - ProcessEvents(); - if(RaspiRead(button_pin) == (PinValues) 1) - { - led_state = RaspiRead(led_pin); - if(led_state == (PinValues) 0) - { - RaspiWrite(led_pin, (PinValues) 1); - } - else - { - RaspiWrite(led_pin, (PinValues) 0); - } - } - } - - CloseAllWindows(); - RaspiCleanup(); -``` - - - - -```csharp -using SplashKitSDK; - -namespace RaspberryPiButtonLED -{ - public class Program - { - public static void Main() - { - SplashKit.RaspiInit(); - Pins buttonPin = (Pins)29; - Pins ledPin = (Pins)11; - PinValues ledState = (PinValues)0; - - SplashKit.RaspiSetMode(buttonPin, (PinModes)0); - SplashKit.RaspiSetMode(ledPin, (PinModes)1); - - SplashKit.RaspiSetPullUpDown(buttonPin, (PullUpDown)1); - - SplashKit.OpenWindow("dummy_window", 1, 1); - while (!SplashKit.AnyKeyPressed()) - { - SplashKit.ProcessEvents(); - - if (SplashKit.RaspiRead(buttonPin) == (PinValues)1) - { - ledState = SplashKit.RaspiRead(ledPin); - if (ledState == (PinValues)0) - { - SplashKit.RaspiWrite(ledPin, (PinValues)1); - } - else - { - SplashKit.RaspiWrite(ledPin, (PinValues)0); - } - } - } - - SplashKit.CloseAllWindows(); - SplashKit.RaspiCleanup(); - } - } -} -``` - - - - - - -### Understanding the code - -Lets break down this code and analyse it in sections. - - -1. **Part 1** - - - - - ```cpp - raspi_init(); - pins button_pin = PIN_29; - pins led_pin = PIN_11; - pin_values led_state = GPIO_LOW; - ``` - - - - - - - - - ```csharp - RaspiInit(); - Pins button_pin = (Pins)29; - Pins led_pin = (Pins)11; - PinValues led_state = (PinValues) 0; - ``` - - - - - ```csharp - SplashKit.RaspiInit(); - Pins buttonPin = (Pins)29; - Pins ledPin = (Pins)11; - PinValues ledState = (PinValues)0; - ``` - - - - - - - We start this code by initialising our hardware through [Raspi Init](/api/raspberry/#raspi-init), we then define the [Pins](/api/types/#gpio-pin) that we're are using for the button (Pin 29), and the LED (Pin 11). We also initialise a variable, `led_state`, to hold the state of the LED at any point in time. We use `led_state` later to determine whether to switch the LED on, or off. - - --- - -2. **Part 2** - - - - - ```cpp - raspi_set_mode(button_pin, GPIO_INPUT); - raspi_set_mode(led_pin, GPIO_OUTPUT); - - raspi_set_pull_up_down(button_pin, PUD_DOWN); - ``` - - - - - - - - - ```csharp - RaspiSetMode(button_pin, (PinModes) 0); - RaspiSetMode(led_pin, (PinModes) 1); - - RaspiSetPullUpDown(button_pin, (PullUpDown) 1); - ``` - - - - - ```csharp - SplashKit.RaspiSetMode(buttonPin, (PinModes)0); - SplashKit.RaspiSetMode(ledPin, (PinModes)1); - - SplashKit.RaspiSetPullUpDown(buttonPin, (PullUpDown)1); - ``` - - - - - - - We begin by setting the mode for each pin using [Raspi Set Mode](/api/raspberry/#raspi-set-mode). The button pin is set to [`GPIO_INPUT`](/api/types/#gpio-pin-mode) and the LED pin is set to [`GPIO_OUTPUT`](/api/types/#gpio-pin-mode). We do this as in this program we are detecting the input of the button and are writing the output of the LED. Then we use [Raspi Set Pull Up Down](/api/raspberry/#raspi-set-pull-up-down) on the button pin with the argument [`PUD_DOWN`](/api/types/#pull-up-down). This sets the internal pull-down resistor to prevent the pin from being a ["floating pin."](#floating-pins) - - --- - -3. **Part 3** - - - - - ```cpp - open_window("dummy_window", 1, 1); - while(!any_key_pressed()) - { - process_events(); - ... - } - ``` - - - - - - - - - ```csharp - OpenWindow("dummy_window", 1, 1); - while(!AnyKeyPressed()) - { - ProcessEvents(); - ... - } - ``` - - - - - ```csharp - SplashKit.OpenWindow("dummy_window", 1, 1); - while (!SplashKit.AnyKeyPressed()) - { - SplashKit.ProcessEvents(); - ... - } - ``` - - - - - - - Just like in the [first tutorial](/guides/raspberry-gpio/0-blink-led), we create a timer that limits how long our program runs for. We do this so we know that our pins are cleaned properly upon exiting the program. - - --- - -4. **Part 4** - - - - - ```cpp - if(raspi_read(button_pin) == GPIO_HIGH) - { - led_state = raspi_read(led_pin); - if(led_state == GPIO_LOW) - { - raspi_write(led_pin, GPIO_HIGH); - } - else - { - raspi_write(led_pin, GPIO_LOW); - } - } - ``` - - - - - - - - - ```csharp - if(RaspiRead(button_pin) == (PinValues) 1) - { - led_state = RaspiRead(led_pin); - if(led_state == (PinValues) 0) - { - RaspiWrite(led_pin, (PinValues) 1); - } - else - { - RaspiWrite(led_pin, (PinValues) 0); - } - } - ``` - - - - - ```csharp - if (SplashKit.RaspiRead(buttonPin) == (PinValues)1) - { - ledState = SplashKit.RaspiRead(ledPin); - if (ledState == (PinValues)0) - { - SplashKit.RaspiWrite(ledPin, (PinValues)1); - } - else - { - SplashKit.RaspiWrite(ledPin, (PinValues)0); - } - } - ``` - - - - - - - Above is the main section of this code. On each loop we read the state of the button pin using [Raspi Read](/api/raspberry/#raspi-read) and if the result is `GPIO_HIGH`, then this indicates that the button has been pressed. We then read the state of the led, which can either be `GPIO_LOW` indicated the LED is not on, or `GPIO_HIGH` indicating that the LED is on. Once we have this state we can use [Raspi Write](/api/raspberry/#raspi-write) to change the pin to the opposite of what has been read. - - --- - -5. **Part 5** - - - - - ```cpp - close_all_windows(); - raspi_cleanup(); - return 0; - ``` - - - - - - - - - ```csharp - CloseAllWindows(); - RaspiCleanup(); - ``` - - - - - ```csharp - SplashKit.CloseAllWindows(); - SplashKit.RaspiCleanup(); - ``` - - - - - - - Just like in the [first tutorial](/guides/raspberry-gpio/0-blink-led) and most projects involving GPIO pins, we must ensure that the hardware and resources we've used are cleaned properly, and we do this by stopping and freeing our timers and calling [Raspi Cleanup](/api/raspberry/#raspi-cleanup). - - --- - - - -### Build and run the code - -We can build this program with the following command: - - - - - ```shell - g++ button_press.cpp -l SplashKit -o button_press - ``` - - - - - ```shell - dotnet build - ``` - - - - -We can then run the program with the following command: - - - - - ```shell - ./button_press - ``` - - - - - ```shell - dotnet run - ``` - - - - -![GIF of the button press circuit in action.](/gifs/guides/gpio-tutorial-gifs/push_button.gif) - -## Further Information - -### Floating Pins - -A 'floating' pin is one that is not actively driven high (connected to some kind of power) or driven low (connected to ground). When this is the case the pin is said to be 'floating' as the state of the pin can change due to electrical noise or interference. If we were to read the pin in this state, then the value returned would be randomly either [`GPIO_HIGH`](/api/types/#gpio-pin-value) or [`GPIO_LOW`](/api/types/#gpio-pin-value) - -In this tutorial we've used an internal pull-down resistor to prevent this. A pull-down resistor connects the pin to ground which effectively neutralises the electrical interference. Doing this ensures the pin only reads[`GPIO_LOW`](/api/types/#gpio-pin-value) until the button is actually pressed and the pin is powered. - -### Debouncing - -The button that is used in this tutorial works by physically moving a strip of metal against another strip of metal to complete a circuit. When you press or release the button, these electrical contacts can physically bounce and create multiple on-off signals. This phenomenon is known as 'debouncing' and can be remedied through hardware and software solutions. One basic way to address this in software is create a non-blocking delay when reading the input (in this case the button). To do this we record the time when we last read the input and take it away from the current time in the loop. We then only read the button when this result is greater than some interval we've set. diff --git a/src/content/docs/guides/Raspberry-GPIO/2-pwm-control-led.mdx b/src/content/docs/guides/Raspberry-GPIO/2-pwm-control-led.mdx deleted file mode 100644 index c1c86c118..000000000 --- a/src/content/docs/guides/Raspberry-GPIO/2-pwm-control-led.mdx +++ /dev/null @@ -1,363 +0,0 @@ ---- -title: Using PWM to control LED brightness -description: Pulse Width Modulation is a technique in which we emulate analog signals in digital pins. This tutorial we explore how to use PWM parameters to modify the operation of an LED. - -category: Guides -author: Jonathan Tynan -lastupdated: Apr 27 2024 ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -Pulse Width Modulation (PWM) is a technique for emulating analog signals when using a digital signal source - like the pins we've been using. It does this by rapidly turning the digital pins on and off, effectively controlling the amount of power sent to a device. This method is widely used for controlling lights, motors and other devices. When using PWM we have several parameters we can control and modify: the PWM duty cycle, the PWM frequency and the PWM range. - -### PWM Frequency - -PWM operates through cycles, which are set by the frequency. The frequency of PWM indicates how many times per second the PWM signal completes one on-and-off cycle. A higher frequency means the individual cycles are completed more rapidly, which can help in smoothing the output in devices like LED's and motors. It is measured in Hertz (Hz) and as it increases, this rapid switching becomes less and less perceptible to human senses. At low frequencies this switching is noticeable and this is seen later in this tutorial. - -### PWM Duty Cycle - -In each of these cycles, the pin is powered high for a some part of the cycle and unpowered for the other part. We define this through the duty cycle, and this allows for fine control over the amount of power delivered to a device. In this tutorial it is shown that increasing the duty cycle of a PWM signal sent to an LED makes it appear brighter as the LED is on for more of the cycle. This value is often expressed as a percentage, for example a 50% duty cycle means that the signal is on for half of the cycle, and off for the other half. - -### PWM Range - -The range of the PWM refers to the resolution we can achieve when adjusting the duty cycle. For example, a range of 255 means that the duty cycle can be adjusted in 256 increments so that the pin could be always off (0%) or always on (100%). A larger range allows for more precise control of the output device and we explore this further in the next tutorial. - -## Components - -### Breadboard - -Breadboards are reusable devices used to build and test circuits. They are made up of a number of -holes that are connected by hidden metal strips. Along the top and bottoms are the ground and power -rails, and in the middle there are two sections separated by a channel. Each hole in a section is -connected to the adjacent vertical holes. More information can be found at -[How to Use a Breadboard](https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/all). - -### LED - -An LED (Light Emitting Diode) is a device that emits light when an electric current passes through -it. They feature two legs, a longer positive leg (the [anode](https://en.wikipedia.org/wiki/Anode)) -and a shorter negative leg (the [cathode](https://en.wikipedia.org/wiki/Cathode)). The longer leg is -often kinked so that both legs protrude the same distance from the LED. To use it we connect the positive -lead to the GPIO pin and the negative lead to a ground pin. More information can be found at -[Light-Emitting Diodes (LEDs)](https://learn.sparkfun.com/tutorials/light-emitting-diodes-leds/all) - -### 220 Ω Resistor - -The power that the Raspberry Pi can provide is actually too much for these LEDs. To prevent the LED -from burning out, we must add a resistor to the circuit. The resistor limits the current that -flows through the LED, preventing it from burning out. The exact value of the resistor is not -critical, but too high a value does not allow enough illumination of the LED. A resistor in the -range of 220 Ω to 1 kΩ should work well. More information on resistors can be found at -[Sparkfun - Resistors](https://learn.sparkfun.com/tutorials/resistors/all) - -:::tip[Resistor Colour Code] -The colours on a resistor indicate the resistance value. Each coloured band corresponds to specific -numbers and multipliers which can be used to calculate the resistance value. More information -can be found at [Electronic Colour Code](https://en.wikipedia.org/wiki/Electronic_color_code) -::: - -### Jumper Wires - -Jumper Wires, or DuPont wires, are used to make a temporary connection different components. They -can be M/M, M/F, or F/F. We are using M/F jumper wires in this guide. - -## The Circuit - -Below we can see the circuit diagram for this project. Just like the blink-LED tutorial, we have the cathode of the LED connected to -GPIO Pin 11, while the anode is connected to ground pin 6 through a resistor. - -![Circuit Diagram for Blinking an LED](./images/circuits/blinkled.png) - -And the physical circuit looks like the following image, in which we've connected an M/F jumper wire -from Pin 11 to the cathode of the LED. The anode of the LED is connected to the resistor, which is -then connected to the ground pin through another M/F jumper wire. - -![Photograph of a circuit to blink an LED](./images/circuits/blink_led_circuit.jpg) - -## The Code - -:::caution[Before running the code.] -This code requires the `pigpio` daemon, so make sure it is running! For more information see: [Starting the Daemon](/guides/raspberry-gpio/0-blink-led/#starting-the-daemon) -::: - -## Changing Frequency - -Below is an example program to iterate over the entire range of frequencies available. - - - - - ```cpp - #include "splashkit.h" - - int main() - { - const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, - 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; - const int pwm_range = 255; - raspi_init(); - pin led_pin = PIN_11; - raspi_set_mode(led_pin, GPIO_OUTPUT); - raspi_set_pwm_range(led_pin, pwm_range); - raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); - for(int i = 0; i < 18; i++) - { - write("At Frequency: "); - write_line(freq[i]); - raspi_set_pwm_frequency(led_pin, freq[i]); - delay(1000); - } - raspi_cleanup(); - return 0; - } - ``` - - - - -### Understanding the code - -Lets break down this code and look at it in sections. - -1. - - - - ```cpp - const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, - 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; - const int pwm_range = 255; - raspi_init(); - pin led_pin = PIN_11; - raspi_set_mode(led_pin, GPIO_OUTPUT); - ``` - - - - - When using `pigpiod`, we can actually set the sample rate for the daemon, which is a value determining how many times it can read a pin in a second. Each sample rate has a set of available frequencies, with the values defined in freqs array being the available frequencies for the default sample rate (more information can be found at [Pigpio library -`set_PWM_frequency`](https://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_frequency)). - - So, we define these values in an array and as a constant as these we don't want them changing during the running of the program. We then define a standard range for our PWM, also as a constant, and then we do the usual initialisation of the Raspberry Pi Pins. - -2. - - - - ```cpp - raspi_set_pwm_range(led_pin, pwm_range); - raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); - ``` - - - - - In this section we set the PWM range and duty cycles that we are using. We are setting the duty cycle to be half the PWM range, or in other words we're setting it to 50%. We are not changing these values so we can specifically see the effects of changing frequency. - -3. - - - - ```cpp - for(int i = 0; i < 18; i++) - { - write("At Frequency: "); - write_line(freq[i]); - raspi_set_pwm_frequency(led_pin, freq[i]); - delay(1000); - } - ``` - - - - - This part is the main component of the code. We iterate over the previously defined frequencies and write where we're at to the terminal. We then set the PWM to the particular frequency and wait for one second. This delay allows us to see the changes in the LED as the frequency increases. At the beginning there is a noticeable flicker, before the flickering stabilises to full illumination as the frequency increases. - -4. - - - - ```cpp - raspi_cleanup(); - return 0; - ``` - - - - - Finally we clean up and exit the program. - -We can build this program with the following command: - - - - - ```shell - g++ pwm_frequency.cpp -l SplashKit -o pwm_frequency - ``` - - - - - -We can then run the program with the following command: - - - - - ```shell - ./pwm_frequency - ``` - - - - -Running this, you may be able to see a noticeable flicker when the frequency is at a low value but it quickly stabilises as it increases. This happens due to the way our eyes perceive light, specifically the [Persistence of Vision](https://en.wikipedia.org/wiki/Persistence_of_vision). If the frequency is faster than the time that images remain in our vision, then we do not notice the times when the LED is unlit. - -#### Changing Duty Cycle - -Below is an example program, very similar to the previous program, that demonstrates what the effect of modifying the duty cycle does to the LED. - - - - - ```cpp - #include "splashkit.h" - - int main() - { - const int pwm_range = 255; - raspi_init(); - pin led_pin = PIN_11; - raspi_set_mode(led_pin, GPIO_OUTPUT); - - raspi_set_pwm_frequency(led_pin, 1000); - raspi_set_pwm_range(led_pin, pwm_range); - - - for(int i = 0; i <= pwm_range; i += 10) - { - write("At Duty Cycle: "); - write_line(i); - raspi_set_pwm_dutycycle(led_pin, i); - delay(1000); - } - - raspi_cleanup(); - return 0; - } - ``` - - - - -Lets break down this code and look at the sections that are different. - -1. - - - - ```cpp - const int pwm_range = 255; - ``` - - - - - Like before we set our PWM range to a constant value. We are using 255 as a general default, but it is important to know that the real range of PWM is dependant on the frequency that we set. More information can be found at [Pigpio library - `set_pwm_range`](https://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_range). - -2. - - - - ```cpp - raspi_set_pwm_frequency(led_pin, 1000); - raspi_set_pwm_range(led_pin, pwm_range); - ``` - - - - - First we set our frequency, we're are using 1000Hz (which cycles at 1000 times per second). We then set our predefined PWM range, and if we refer back to the Pigpiod library we can see that a frequency of 1000 is the 14th available frequency at the default sample rate. This means that at this frequency we really have a range of 2500 and so our PWM range of 255 is valid. - -3. - - - - ```cpp - for(int i = 0; i <= pwm_range; i += 10) - { - write("At Duty Cycle: "); - write_line(i); - raspi_set_pwm_dutycycle(led_pin, i); - delay(1000); - } - for(int i = pwm_range; i >= 0; i -= 10) - { - write("At Duty Cycle: "); - write_line(i); - raspi_set_pwm_dutycycle(led_pin, i); - delay(1000); - } - ``` - - - - - In this section we have the main function of this program. We iterate over the range that we've set in increments of 10, and at each step we print out the duty cycle we're currently on. We then set the duty cycle to this value and wait for a second so we can see the changes. We then reverse the loop and iterate back down to zero. - -4. - - - - ```cpp - raspi_cleanup(); - return 0; - ``` - - - - - Like usual, we clean up and exit the program. - -### Build and run the code - -We can build this program with the following command: - - - - - ```shell - g++ pwm_dutycycle.cpp -l SplashKit -o pwm_dutycycle - ``` - - - - -We can then run the program with the following command: - - - - - ```shell - ./pwm_dutycycle - ``` - - - - -Changing the duty cycle results in a noticeable change in the brightness of the LED. This occurs due to there being literally more or less power flowing through the device, resulting in the increase or decrease in brightness. This can be seen in the GIF below. - -!["GIF of LED duty cycle changes."](/gifs/guides/gpio-tutorial-gifs/pwm_led.gif) - -### Further Information - -#### Changing PWM Range - -As previously mentioned, when we increase the PWM range we increase the number of steps between the pin being always off and always on. We could change the range in the previous program and observe finer and more subtle adjustments occurring to the LED as the duty cycle increases. But this may be difficult to see when using a regular LED. A more effective demonstration of the capabilities of PWM would be through the use of an RGB LED, which can interpret analog-like signals achieved through PWM to mix red, green, and blue light in varying intensities. This allows for the creation of a wider spectrum of colours by adjusting the PWM range for each of the LED's colour components. diff --git a/src/content/docs/guides/Raspberry-GPIO/3-pwm-button-control.mdx b/src/content/docs/guides/Raspberry-GPIO/3-pwm-button-control.mdx deleted file mode 100644 index 1bc31172d..000000000 --- a/src/content/docs/guides/Raspberry-GPIO/3-pwm-button-control.mdx +++ /dev/null @@ -1,242 +0,0 @@ ---- -title: Modify PWM through button presses -description: Learn to control LED brightness using Pulse Width Modulation (PWM) by button presses on a Raspberry Pi - -category: Guides -author: Jonathan Tynan -lastupdated: Apr 27 2024 ---- - -import { Tabs, TabItem } from "@astrojs/starlight/components"; - -**{frontmatter.description}** -Written by: {frontmatter.author} -_Last updated: {frontmatter.lastupdated}_ - ---- - -In this tutorial, we bring all the previous lessons together. We are reading button presses and will use these readings to modify the brightness of an LED by changing the PWM duty cycle. This tutorial brings together digital pin reading, writing and PWM modification. This is a simple demonstration of how to integrate various physical components and get them working with each other. - -### Components - -See [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led/#components) for more details on these components. - -- Breadboard -- LED -- 220 Ω Resistor -- Jumper Wires - -See [Read Button Press Tutorial](/guides/raspberry-gpio/1-read-button-press/#components) for more details on these components: - -- 2 Push Buttons - -### The Circuit - -Below we can see the circuit diagram for this project. First we have the Raspberry Pi ground connected to the ground rail of the breadboard and a 3.3V pin connected to the power rail of the bread board. We then have an LED which is connected to the ground rail and to Pin 11 through a 220 Ω resistor. Next we have 2 buttons, where both are connected to the powered rail on the breadboard and the otherside of the buttons are connected to pins 13 and 29. - -![Circuit Diagram for using button presses to modify PWM.](./images/circuits/pwm_buttons.png) - -![Photograph of a circuit for using button presses to modify PWM.](./images/circuits/pwm_buttons_circuit.png) - -### The Code - -:::caution[Before running the code.] -This code requires the `pigpio` daemon, so make sure it is running! For more information see: [Starting the Daemon](/guides/raspberry-gpio/0-blink-led/#starting-the-daemon) -::: - -Below is an example program that will detect button presses to increase or decrease the brightness of an LED. - - - - ``` cpp - #include "splashkit.h" - - int main() - { - int brightness = 128; - const int max_brightness = 255; - unsigned long last_read_time = 0; - const unsigned long read_interval = 400; - - raspi_init(); - pins led_pin = PIN_11; - pins increase_btn_pin = PIN_13; - pins decrease_btn_pin = PIN_29; - - raspi_set_mode(led_pin, GPIO_OUTPUT); - raspi_set_pwm_dutycycle(led_pin, brightness); - - raspi_set_mode(increase_btn_pin, GPIO_INPUT); - raspi_set_mode(decrease_btn_pin, GPIO_INPUT); - - raspi_set_pull_up_down(increase_button_pin, PUD_DOWN); - raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); - - timer run_timer = create_timer("run_timer"); - start_timer(run_timer); - unsigned long current_time = 0; - - open_window("dummy_window", 1, 1); - while(!any_key_pressed()) - { - process_events(); - current_time = timer_ticks(run_timer); - if(current_time - last_read_time > read_interval) - { - if(raspi_read(increase_btn_pin) == GPIO_HIGH) - { - brightness += 25; - if(brightness > max_brightness) { brightness = max_brightness; } - raspi_set_pwm_dutycycle(led_pin, brightness); - last_read_time = current_time; - } - if(raspi_read(decrease_btn_pin) == GPIO_HIGH) - { - brightness -= 25; - if(brightness < 0) { brightness = 0; } - raspi_set_pwm_dutycycle(led_pin, brightness); - last_read_time = current_time; - } - } - } - - close_all_windows(); - stop_timer(run_timer); - free_all_timers(); - raspi_cleanup(); - return 0; - } - ``` - - - - -Okay, now lets break down this code and look at its sections. - -1. - - - - ``` cpp - int brightness = 128; - const int max_brightness = 255; - unsigned long last_read_time = 0; - const unsigned long read_interval = 400; - ``` - - - - - Above is where we are setting up the variables that we're going to need. `brightness` which we are giving an inital value of 128 which is 50% of our maximum, 255. We are also setting `last_read_time` to 0 and `read_interval` to 400. We are using this to implement a simple debounce technique, in which we wait a certain amount of time (the interval) in a non-blocking manner. -2. - - - - ``` cpp - raspi_init(); - pins led_pin = PIN_11; - pins increase_btn_pin = PIN_13; - pins decrease_btn_pin = PIN_29; - ``` - - - - - Now we do our GPIO setup, where we call `raspi_init` and define the pins we are using. -3. - - - - ``` cpp - raspi_set_mode(led_pin, GPIO_OUTPUT); - raspi_set_pwm_dutycycle(led_pin, brightness); - - raspi_set_mode(increase_btn_pin, GPIO_INPUT); - raspi_set_mode(decrease_btn_pin, GPIO_INPUT); - - raspi_set_pull_up_down(increase_button_pin, PUD_DOWN); - raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); - ``` - - - - - Next, we setup our individual pins. We're going to write to the `led_pin` so we're setting that to output, and then we're setting its dutycycle to our initial brightness setting. Then we set our buttons to be inputs and set the pull-down resistors on them so that they are no longer floating and we can be sure they read `LOW` when not pressed. - -4. - - - - ``` cpp - timer run_timer = create_timer("run_timer"); - start_timer(run_timer); - unsigned long current_time = 0; - - open_window("dummy_window", 1, 1); - while(!any_key_pressed()) - { - process_events(); - ... - } - ``` - - - - - So we can debounce our buttons we'll create timers and a variable to hold the current time. Like in previous tutorials, we define how our program is going to end to ensure cleanup. In this case we are opening up our dummy window and watching for any key presses. - -5. - - - - ``` cpp - current_time = timer_ticks(run_timer); - if(current_time - last_read_time > read_interval) - { - if(raspi_read(increase_btn_pin) == GPIO_HIGH) - { - brightness += 25; - if(brightness > max_brightness) { brightness = max_brightness; } - raspi_set_pwm_dutycycle(led_pin, brightness); - last_read_time = current_time; - } - if(raspi_read(decrease_btn_pin) == GPIO_HIGH) - { - brightness -= 25; - if(brightness < 0) { brightness = 0; } - raspi_set_pwm_dutycycle(led_pin, brightness); - last_read_time = current_time; - } - } - ``` - - - - - Above we have the main part of the code, the inside of the while loop. At the start of every loop we are getting the current time from `timer_ticks`. We are then checking if more time has elapsed since the last button read than the interval that we set earlier. - - If this is the case, then it's time to check the buttons. We then read both buttons and if they're high then we'll either increase or decrease the brightness appropriately, set the duty cycle to this new brightness and record the last read time as the current time. -6. - - - - ``` cpp - close_all_windows(); - stop_timer(run_timer); - free_all_timers(); - raspi_cleanup(); - return 0; - ``` - - - - - As usual once our program has run we cleanup all our resources and safely exit the program. - -If we run this we should see an output like the following GIF. - -![A GIF of the LED increasing then decreasing in brightness.](/gifs/guides/gpio-tutorial-gifs/pwm_button.gif) - -### Modifying PWM Range - -As described in the previous tutorial, we can change the range of possible PWM values and have finer control over the brightness of the LED. In this tutorial, we use the typical PWM range of 0-255, but we could expand this to a higher resolution, like 1023, for more precise control of the exact brightness levels. Experiment with adjustments to the PWM range, modifying the parameters in your code, and observe how these changes affect the LED's response to button presses. Each step increase in the PWM range will allow for more nuanced adjustments and provide smoother transitions between light levels. Conversely, a decrease in the PWM range will limit these transitions, and make each button press cause a more noticeable change in brightness. diff --git a/src/content/docs/guides/Animations/images/All-About-Animation-Vectors.png b/src/content/docs/guides/animations/images/All-About-Animation-Vectors.png similarity index 100% rename from src/content/docs/guides/Animations/images/All-About-Animation-Vectors.png rename to src/content/docs/guides/animations/images/All-About-Animation-Vectors.png diff --git a/src/content/docs/guides/Animations/images/All-About-Animation-With-Sound.png b/src/content/docs/guides/animations/images/All-About-Animation-With-Sound.png similarity index 100% rename from src/content/docs/guides/Animations/images/All-About-Animation-With-Sound.png rename to src/content/docs/guides/animations/images/All-About-Animation-With-Sound.png diff --git a/src/content/docs/guides/Animations/images/Animation-Frame.png b/src/content/docs/guides/animations/images/Animation-Frame.png similarity index 100% rename from src/content/docs/guides/Animations/images/Animation-Frame.png rename to src/content/docs/guides/animations/images/Animation-Frame.png diff --git a/src/content/docs/guides/Animations/images/Animation-basics.png b/src/content/docs/guides/animations/images/Animation-basics.png similarity index 100% rename from src/content/docs/guides/Animations/images/Animation-basics.png rename to src/content/docs/guides/animations/images/Animation-basics.png diff --git a/src/content/docs/guides/Animations/images/frog.png b/src/content/docs/guides/animations/images/frog.png similarity index 100% rename from src/content/docs/guides/Animations/images/frog.png rename to src/content/docs/guides/animations/images/frog.png diff --git a/src/content/docs/guides/Animations/0-using-animations.mdx b/src/content/docs/guides/animations/using-animations.mdx similarity index 99% rename from src/content/docs/guides/Animations/0-using-animations.mdx rename to src/content/docs/guides/animations/using-animations.mdx index ccdaa8f69..92a67fcce 100644 --- a/src/content/docs/guides/Animations/0-using-animations.mdx +++ b/src/content/docs/guides/animations/using-animations.mdx @@ -1,7 +1,6 @@ --- title: Using Animations in SplashKit description: Animations allow you to switch between different images to make a more visually dynamic entity on the screen. SplashKit allows you to create animations and use these together with sprite sheets to create these animations. -category: Guides author: Various Authors lastupdated: October 2024 --- diff --git a/src/content/docs/guides/Audio/0-getting-started-with-audio.mdx b/src/content/docs/guides/audio/getting-started-with-audio.mdx similarity index 99% rename from src/content/docs/guides/Audio/0-getting-started-with-audio.mdx rename to src/content/docs/guides/audio/getting-started-with-audio.mdx index 729bd985a..608e32f57 100644 --- a/src/content/docs/guides/Audio/0-getting-started-with-audio.mdx +++ b/src/content/docs/guides/audio/getting-started-with-audio.mdx @@ -3,7 +3,6 @@ title: Get Started with SplashKit Audio description: Adding sound effects and music can really help bring an application to life. In this article see how to get started with Audio in SplashKit. author: Various Authors lastupdated: October 2024 -category: Guides --- import { Tabs, TabItem } from "@astrojs/starlight/components"; diff --git a/src/content/docs/guides/Audio/images/about_audio_1.png b/src/content/docs/guides/audio/images/about_audio_1.png similarity index 100% rename from src/content/docs/guides/Audio/images/about_audio_1.png rename to src/content/docs/guides/audio/images/about_audio_1.png diff --git a/src/content/docs/guides/Audio/images/about_audio_2.png b/src/content/docs/guides/audio/images/about_audio_2.png similarity index 100% rename from src/content/docs/guides/Audio/images/about_audio_2.png rename to src/content/docs/guides/audio/images/about_audio_2.png diff --git a/src/content/docs/guides/Audio/images/about_audio_3.png b/src/content/docs/guides/audio/images/about_audio_3.png similarity index 100% rename from src/content/docs/guides/Audio/images/about_audio_3.png rename to src/content/docs/guides/audio/images/about_audio_3.png diff --git a/src/content/docs/beyond-splashkit/Cryptography/0-encoding-and-decoding.mdx b/src/content/docs/guides/beyond-splashkit/cryptography/encoding-and-decoding.mdx similarity index 99% rename from src/content/docs/beyond-splashkit/Cryptography/0-encoding-and-decoding.mdx rename to src/content/docs/guides/beyond-splashkit/cryptography/encoding-and-decoding.mdx index 58adc719b..81fcc0e92 100644 --- a/src/content/docs/beyond-splashkit/Cryptography/0-encoding-and-decoding.mdx +++ b/src/content/docs/guides/beyond-splashkit/cryptography/encoding-and-decoding.mdx @@ -1,9 +1,10 @@ --- title: Encoding and Decoding description: Explore the essentials of encoding and decoding data using Base64, Caesar Cipher, and URL transformations for secure and efficient data representation. -category: Guides author: Brianna Laird lastupdated: December 2024 +sidebar: + order: 1 --- import { Tabs, TabItem } from "@astrojs/starlight/components"; diff --git a/src/content/docs/beyond-splashkit/Cryptography/2-morse-code.mdx b/src/content/docs/guides/beyond-splashkit/cryptography/morse-code.mdx similarity index 99% rename from src/content/docs/beyond-splashkit/Cryptography/2-morse-code.mdx rename to src/content/docs/guides/beyond-splashkit/cryptography/morse-code.mdx index d04a1cab7..4cdb91db9 100644 --- a/src/content/docs/beyond-splashkit/Cryptography/2-morse-code.mdx +++ b/src/content/docs/guides/beyond-splashkit/cryptography/morse-code.mdx @@ -1,9 +1,10 @@ --- title: Morse Code Tutorial description: Explore morse code, and how you can use a program to convert text to morse code and back. -category: Guides author: Brianna Laird lastupdated: December 2024 +sidebar: + order: 3 --- import { Tabs, TabItem, Steps } from "@astrojs/starlight/components"; diff --git a/src/content/docs/beyond-splashkit/Cryptography/1-steganography.mdx b/src/content/docs/guides/beyond-splashkit/cryptography/steganography.mdx similarity index 99% rename from src/content/docs/beyond-splashkit/Cryptography/1-steganography.mdx rename to src/content/docs/guides/beyond-splashkit/cryptography/steganography.mdx index 0b24831ce..11a14afa6 100644 --- a/src/content/docs/beyond-splashkit/Cryptography/1-steganography.mdx +++ b/src/content/docs/guides/beyond-splashkit/cryptography/steganography.mdx @@ -1,9 +1,10 @@ --- title: Steganography description: Explore using steganography to hide messages in images and bitmaps. -category: Guides author: Brianna Laird lastupdated: December 2024 +sidebar: + order: 2 --- import { Tabs, TabItem, Steps } from "@astrojs/starlight/components"; diff --git a/src/content/docs/guides/beyond-splashkit/index.mdx b/src/content/docs/guides/beyond-splashkit/index.mdx new file mode 100644 index 000000000..084b65ffb --- /dev/null +++ b/src/content/docs/guides/beyond-splashkit/index.mdx @@ -0,0 +1,59 @@ +--- +title: Beyond SplashKit +sidebar: + label: "Overview" + order: 0 +--- + +import { LinkCard } from "@astrojs/starlight/components"; + +:::tip[Beyond SplashKit] +This part of our documentation site provides useful tutorials and examples outside of the SplashKit SDK to help beginner developers extend their skills. +::: + +### Using SDL2 + +*Compare SplashKit code snippets with the equivalent code in SDL2 (one of SplashKit's dependencies):* + + + + +## Cryptography + +*Explore encoding and decoding techniques, as well as other interesting cryptography topics:* + + + + + +### Utilities + +*Learn more about how to code basic mathematical operations, conversion operations, and input validation:* + + + + diff --git a/src/content/docs/beyond-splashkit/Graphics/0-getting-started-with-graphics.mdx b/src/content/docs/guides/beyond-splashkit/sdl2/getting-started-with-graphics.mdx similarity index 78% rename from src/content/docs/beyond-splashkit/Graphics/0-getting-started-with-graphics.mdx rename to src/content/docs/guides/beyond-splashkit/sdl2/getting-started-with-graphics.mdx index 72b9e3667..1ee5076a1 100644 --- a/src/content/docs/beyond-splashkit/Graphics/0-getting-started-with-graphics.mdx +++ b/src/content/docs/guides/beyond-splashkit/sdl2/getting-started-with-graphics.mdx @@ -3,24 +3,26 @@ title: Getting Started with SDL2 Graphics description: This brief guide provides code to show simple graphics functionality without SplashKit such as how to open a window, keep a window open, draw a rectangle and display a bitmap. These are then combined to create a simple "eye dropper" program to compare with and without SplashKit. author: Simon Rhook and Olivia McKeon lastupdated: December 2024 +sidebar: + order: 1 --- import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; -import openWindowCode_withSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-with-splashkit.cpp?raw'; -import openWindowCode_noSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-no-splashkit.cpp?raw'; +import openWindowCode_withSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-with-splashkit.cpp?raw'; +import openWindowCode_noSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/open_window-no-splashkit.cpp?raw'; -import quitRequestedCode_withSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-with-splashkit.cpp?raw'; -import quitRequestedCode_noSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-no-splashkit.cpp?raw'; +import quitRequestedCode_withSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-with-splashkit.cpp?raw'; +import quitRequestedCode_noSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/quit_requested-no-splashkit.cpp?raw'; -import drawRectangleCode_withSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-with-splashkit.cpp?raw'; -import drawRectangleCode_noSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-no-splashkit.cpp?raw'; +import drawRectangleCode_withSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-with-splashkit.cpp?raw'; +import drawRectangleCode_noSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_rectangle-no-splashkit.cpp?raw'; -import drawBitmapCode_withSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-with-splashkit.cpp?raw'; -import drawBitmapCode_noSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-no-splashkit.cpp?raw'; +import drawBitmapCode_withSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-with-splashkit.cpp?raw'; +import drawBitmapCode_noSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/draw_bitmap-no-splashkit.cpp?raw'; -import eyedropperCode_withSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-with-splashkit.cpp?raw'; -import eyedropperCode_noSK from '/public/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-no-splashkit.cpp?raw'; +import eyedropperCode_withSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-with-splashkit.cpp?raw'; +import eyedropperCode_noSK from '/public/guides/beyond-splashkit/code-files/graphics/0-getting-started-with-graphics/eyedropper-no-splashkit.cpp?raw'; **{frontmatter.description}** Written by: {frontmatter.author} @@ -201,7 +203,7 @@ The following code shows how to display a bitmap image on the screen (Window), w :::note[Resources] -To test the code below, you can download these [**Resources**](/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip). +To test the code below, you can download these [**Resources**](/guides/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip). ::: @@ -228,7 +230,7 @@ This program combines the above into a small program that will change the screen :::note[Resources] -To test the code below, you can download these [**Resources**](/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip). +To test the code below, you can download these [**Resources**](/guides/beyond-splashkit/resources/BeyondSplashKit_Graphics_Resources.zip). ::: diff --git a/src/content/docs/beyond-splashkit/Audio/0-sound-effects.mdx b/src/content/docs/guides/beyond-splashkit/sdl2/sound-effects.mdx similarity index 92% rename from src/content/docs/beyond-splashkit/Audio/0-sound-effects.mdx rename to src/content/docs/guides/beyond-splashkit/sdl2/sound-effects.mdx index 3a25f3f20..3f483e86a 100644 --- a/src/content/docs/beyond-splashkit/Audio/0-sound-effects.mdx +++ b/src/content/docs/guides/beyond-splashkit/sdl2/sound-effects.mdx @@ -3,12 +3,14 @@ title: Playing Sound Effects and Music Without SplashKit description: This brief guide provides code to compare how to load and play music and sound effects with and without SplashKit (using SDL). author: Simon Rhook and Olivia McKeon lastupdated: December 2024 +sidebar: + order: 2 --- import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; -import soundEffectsCode_withSK from '/public/beyond-splashkit/code-files/audio/0-sound-effects/with-splashkit.cpp?raw'; -import soundEffectsCode_noSK from '/public/beyond-splashkit/code-files/audio/0-sound-effects/no-splashkit.cpp?raw'; +import soundEffectsCode_withSK from '/public/guides/beyond-splashkit/code-files/audio/0-sound-effects/with-splashkit.cpp?raw'; +import soundEffectsCode_noSK from '/public/guides/beyond-splashkit/code-files/audio/0-sound-effects/no-splashkit.cpp?raw'; **{frontmatter.description}** Written by: {frontmatter.author} @@ -134,7 +136,7 @@ The following code compares loading and playing music and sound effects with and :::note[Resources] -To test the code below, you can download these [**Resources**](/beyond-splashkit/resources/BeyondSplashKit_SoundEffects_Resources.zip). +To test the code below, you can download these [**Resources**](/guides/beyond-splashkit/resources/BeyondSplashKit_SoundEffects_Resources.zip). ::: diff --git a/src/content/docs/beyond-splashkit/Maths/1-converting-values.mdx b/src/content/docs/guides/beyond-splashkit/utilities/converting-values.mdx similarity index 99% rename from src/content/docs/beyond-splashkit/Maths/1-converting-values.mdx rename to src/content/docs/guides/beyond-splashkit/utilities/converting-values.mdx index a600e9fe4..680b90e92 100644 --- a/src/content/docs/beyond-splashkit/Maths/1-converting-values.mdx +++ b/src/content/docs/guides/beyond-splashkit/utilities/converting-values.mdx @@ -1,9 +1,10 @@ --- title: Conversion Operations description: Learn how to perform basic mathematical conversion operations for different values such as binary to decimal, or hex to octal. -category: Guides author: Brianna Laird lastupdated: December 2024 +sidebar: + order: 2 --- import { Tabs, TabItem } from "@astrojs/starlight/components"; diff --git a/src/content/docs/beyond-splashkit/Utilities/0-integer-input-validation.mdx b/src/content/docs/guides/beyond-splashkit/utilities/integer-input-validation.mdx similarity index 82% rename from src/content/docs/beyond-splashkit/Utilities/0-integer-input-validation.mdx rename to src/content/docs/guides/beyond-splashkit/utilities/integer-input-validation.mdx index c922eba4f..bb05ac999 100644 --- a/src/content/docs/beyond-splashkit/Utilities/0-integer-input-validation.mdx +++ b/src/content/docs/guides/beyond-splashkit/utilities/integer-input-validation.mdx @@ -3,12 +3,15 @@ title: Basic Integer Input Validation Without SplashKit description: This brief guide provides code to compare how to implement basic input validation for integers with and without SplashKit. author: Simon Rhook and Olivia McKeon lastupdated: December 2024 +sidebar: + order: 3 + label: Input Validation --- import { Code, Tabs, TabItem } from "@astrojs/starlight/components"; -import intInputValidationCode_withSK from '/public/beyond-splashkit/code-files/utilities/0-integer-input-validation/with-splashkit.cpp?raw'; -import intInputValidationCode_noSK from '/public/beyond-splashkit/code-files/utilities/0-integer-input-validation/no-splashkit.cpp?raw'; +import intInputValidationCode_withSK from '/public/guides/beyond-splashkit/code-files/utilities/0-integer-input-validation/with-splashkit.cpp?raw'; +import intInputValidationCode_noSK from '/public/guides/beyond-splashkit/code-files/utilities/0-integer-input-validation/no-splashkit.cpp?raw'; **{frontmatter.description}** Written by: {frontmatter.author} diff --git a/src/content/docs/beyond-splashkit/Maths/0-math-basics.mdx b/src/content/docs/guides/beyond-splashkit/utilities/math-basics.mdx similarity index 99% rename from src/content/docs/beyond-splashkit/Maths/0-math-basics.mdx rename to src/content/docs/guides/beyond-splashkit/utilities/math-basics.mdx index 907ee35ed..5f07309bf 100644 --- a/src/content/docs/beyond-splashkit/Maths/0-math-basics.mdx +++ b/src/content/docs/guides/beyond-splashkit/utilities/math-basics.mdx @@ -1,9 +1,10 @@ --- title: Basic Maths Operations description: Learn how to perform basic mathematical operations in programming, including square roots, prime numbers, factors, greatest common divisors, least common multiples, and modular arithmetic. -category: Guides author: Brianna Laird lastupdated: December 2024 +sidebar: + order: 1 --- import { Tabs, TabItem } from "@astrojs/starlight/components"; diff --git a/src/content/docs/guides/Camera/images/camera.png b/src/content/docs/guides/camera/images/camera.png similarity index 100% rename from src/content/docs/guides/Camera/images/camera.png rename to src/content/docs/guides/camera/images/camera.png diff --git a/src/content/docs/guides/Camera/0-using-splashkit-camera.mdx b/src/content/docs/guides/camera/using-splashkit-camera.mdx similarity index 99% rename from src/content/docs/guides/Camera/0-using-splashkit-camera.mdx rename to src/content/docs/guides/camera/using-splashkit-camera.mdx index 47ddcfd16..d7af51d76 100644 --- a/src/content/docs/guides/Camera/0-using-splashkit-camera.mdx +++ b/src/content/docs/guides/camera/using-splashkit-camera.mdx @@ -3,7 +3,6 @@ title: SplashKit Camera description: See how the camera works, and how to draw to the different coordinate systems in your program. author: Andrew Cain and others lastupdated: October 2024 -category: Guides --- import { Tabs, TabItem } from "@astrojs/starlight/components"; diff --git a/src/content/docs/guides/color/images/colour_wheel.png b/src/content/docs/guides/color/images/colour_wheel.png new file mode 100644 index 000000000..79f094f90 Binary files /dev/null and b/src/content/docs/guides/color/images/colour_wheel.png differ diff --git a/src/content/docs/guides/color/splashkit-colors.mdx b/src/content/docs/guides/color/splashkit-colors.mdx new file mode 100644 index 000000000..2b85387c0 --- /dev/null +++ b/src/content/docs/guides/color/splashkit-colors.mdx @@ -0,0 +1,49 @@ +--- +title: SplashKit Colors +description: Use this tool to generate the colors you need for your SplashKit projects! +author: Shaun Ratcliff +lastupdated: 11 Dec 24 +--- + +**{frontmatter.description}** +Written by: {frontmatter.author} +_Last updated: {frontmatter.lastupdated}_ + +--- + +import ColorGenerator from "/src/components/ColorGenerator.astro"; +import ColorPalette from "/src/components/ColorPalette.astro"; + +:::tip +_You can also checkout the [Color](/api/color/) API Documentation page for more details._ +::: + +## SplashKit Colors + +Colors are at the heart of creating engaging and visually appealing applications, and SplashKit makes working with them seamless. By leveraging industry-standard color models, SplashKit enables you to work with colors in a way that feels natural and intuitive. + +### Color RGB(A) + +The RGB(A) model defines colors based on their Red, Green, and Blue components, with an optional Alpha channel to control transparency. Each component ranges from 0 to 255, creating a vast palette of possible colors. Whether you're designing vivid visuals or subtle gradients, RGB(A) is a straightforward way to define and manipulate colors. + +### Color HSB + +On the other hand, the HSB (Hue, Saturation, Brightness) model offers a more intuitive approach to color creation. Hue determines the base color, measured in degrees around a color wheel (0° for red, 120° for green, 240° for blue, and so on). + +![Colour Wheel](./images/colour_wheel.png) + +Saturation adjusts the intensity of the color, from a dull gray to a vibrant hue, while Brightness defines how light or dark the color appears. This model is particularly useful for applications where fine-tuning the emotional or thematic tone of visuals is key. + +The tools below will help you to experiment with both models to find your perfect color. You can also explore the full range of SplashKit colors that have ready-to-use functions for C++, C#, or Python. + +## Color Palette + +SplashKit streamlines color manipulation in graphical applications by providing you with an intuitive and efficient approach to working with colors. This interactive color palette displays all the available SplashKit colors, allowing you to visually explore and select your desired shade. Once a color is chosen, the corresponding SplashKit functions in C++, C#, and Python will be shown, making it simple to integrate precise color choices into your project. + + + +## Color Generator + +The Color Generator tool is designed to help you visualise and generate precise color configurations in both RGB(A) and HSB formats for your SplashKit projects. Whether you’re tweaking Red, Green, and Blue values or adjusting Hue, Saturation, and Brightness, this tool provides immediate visual feedback through a color preview box. + + diff --git a/src/content/docs/guides/Graphics/1-double-buffering.mdx b/src/content/docs/guides/graphics/double-buffering.mdx similarity index 99% rename from src/content/docs/guides/Graphics/1-double-buffering.mdx rename to src/content/docs/guides/graphics/double-buffering.mdx index d774f8c5f..bbf952750 100644 --- a/src/content/docs/guides/Graphics/1-double-buffering.mdx +++ b/src/content/docs/guides/graphics/double-buffering.mdx @@ -1,7 +1,6 @@ --- title: Understanding Double Buffering description: SplashKit uses double buffering to make animations smooth, but this introduces a few steps to get images appearing on the screen as you expect. In this article we discuss the basics of double buffering using Refresh Screen and the painter model. -category: Guides author: Various Authors lastupdated: December 2024 --- diff --git a/src/content/docs/guides/Graphics/0-drawing-using-procedures.mdx b/src/content/docs/guides/graphics/drawing-using-procedures.mdx similarity index 99% rename from src/content/docs/guides/Graphics/0-drawing-using-procedures.mdx rename to src/content/docs/guides/graphics/drawing-using-procedures.mdx index b0e357ec2..3f3461364 100644 --- a/src/content/docs/guides/Graphics/0-drawing-using-procedures.mdx +++ b/src/content/docs/guides/graphics/drawing-using-procedures.mdx @@ -1,7 +1,6 @@ --- title: Drawing using Procedures description: This article provides a quick overview of getting started with SplashKit. It includes how to create a window and do some basic drawing in order to create a small animation. This is a great place to start with SplashKit. -category: Tutorials author: Andrew Cain and others lastupdated: January 2025 --- diff --git a/src/content/docs/guides/Graphics/images/double_buffer/draw_shapes.png b/src/content/docs/guides/graphics/images/double_buffer/draw_shapes.png similarity index 100% rename from src/content/docs/guides/Graphics/images/double_buffer/draw_shapes.png rename to src/content/docs/guides/graphics/images/double_buffer/draw_shapes.png diff --git a/src/content/docs/guides/Graphics/images/double_buffer/painter-new.jpg b/src/content/docs/guides/graphics/images/double_buffer/painter-new.jpg similarity index 100% rename from src/content/docs/guides/Graphics/images/double_buffer/painter-new.jpg rename to src/content/docs/guides/graphics/images/double_buffer/painter-new.jpg diff --git a/src/content/docs/guides/Graphics/images/drawing/AutoComplete.png b/src/content/docs/guides/graphics/images/drawing/AutoComplete.png similarity index 100% rename from src/content/docs/guides/Graphics/images/drawing/AutoComplete.png rename to src/content/docs/guides/graphics/images/drawing/AutoComplete.png diff --git a/src/content/docs/guides/Graphics/images/drawing/DrawFill.png b/src/content/docs/guides/graphics/images/drawing/DrawFill.png similarity index 100% rename from src/content/docs/guides/Graphics/images/drawing/DrawFill.png rename to src/content/docs/guides/graphics/images/drawing/DrawFill.png diff --git a/src/content/docs/guides/Graphics/images/drawing/NewWindow.png b/src/content/docs/guides/graphics/images/drawing/NewWindow.png similarity index 100% rename from src/content/docs/guides/Graphics/images/drawing/NewWindow.png rename to src/content/docs/guides/graphics/images/drawing/NewWindow.png diff --git a/src/content/docs/guides/Graphics/images/drawing/RefreshScreen.png b/src/content/docs/guides/graphics/images/drawing/RefreshScreen.png similarity index 100% rename from src/content/docs/guides/Graphics/images/drawing/RefreshScreen.png rename to src/content/docs/guides/graphics/images/drawing/RefreshScreen.png diff --git a/src/content/docs/guides/index.mdx b/src/content/docs/guides/index.mdx index 493ad6987..c01f14047 100644 --- a/src/content/docs/guides/index.mdx +++ b/src/content/docs/guides/index.mdx @@ -5,14 +5,274 @@ sidebar: order: 0 --- +import { CardGrid, LinkCard, Tabs, TabItem } from "@astrojs/starlight/components"; :::tip[SplashKit SDK] - SplashKit provides a versatile set of categories, encompassing graphics, audio, input, and more, offering developers a comprehensive toolkit for game and multimedia development. +::: + +### Getting Started + +*Get started coding with different areas of SplashKit:* + + + + + + + + + + + + + + + +### Raspberry Pi GPIO + +*Discover how to use SplashKit on a Raspberry Pi to work with LEDs and buttons:* + + + + + + + + +### Physics + +*Learn more about using vectors and related functionality in SplashKit:* + + + + + + + + + + + + + +### Interface + +*See how you can create user interface panels with different layouts and styling:* + + + + + + + +### Networking + +*Find out more about using SplashKit's web server functionality:* + + + + + + + +## Using SplashKit + +### Compile and Run SplashKit Code + +Here is a basic overview of how to compile and run SplashKit programs in C++, C# and python. + + + + +To compile C++ SplashKit code, you will use the following command (assuming the code file is named `program.cpp`): + +```shell +clang++ program.cpp -l SplashKit -o test_program +``` + +Or: + +```shell +g++ program.cpp -l SplashKit -o test_program +``` + +Then you can run the program with: + +```shell +./test_program +``` + +Or, if using MSYS2 (MINGW64): + +```shell +./test_program.exe +``` + +:::note[With 'skm'] + +You can also compile your C++ code using the following command: + +```shell +skm clang++ program.cpp -o test_program +``` + +Or: + +```shell +skm g++ program.cpp -o test_program +``` + +::: + + + + +To run C# SplashKit code with dotnet, you will need to first run the command below: + +```shell +dotnet add package SplashKit +``` + +This will add the SplashKit NuGet package, to link the SplashKit SDK to your project. + +Then you can run the program using: + +```shell +dotnet run +``` + +:::note[With 'skm'] + +You can also build and run your C# code using the following command: + +```shell +skm dotnet run +``` + +::: + + + + +To run SplashKit python code, you will use the following command (assuming the code file is named `program.py`): + +```shell +python3 program.py +``` + +:::note[With 'skm'] + +You can also run your Python code using the following command: + +```shell +skm python3 program.py +``` ::: -import GuidesList from "../../../components/Guides.astro"; + + + +### More Information + +More detailed guides on getting started with SplashKit coming soon... + +For now, you can look at these guides in the [programmers.guide](https://programmers.guide/) online textbook: - - +| Language | Overview | Link | +| -------- | --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | +| C# | Setting up a basic SplashKit C# project. | [**Your First Program**](https://programmers.guide/book/part-0-getting-started/3-building-programs/1-tour/1-hello-world-cli/) | +| C# | Building a graphical (GUI) SplashKit program. | [**Build Graphical Hello World**](https://programmers.guide/book/part-0-getting-started/3-building-programs/1-tour/1-hello-world-cli/) | +| C++ | Setting up a basic SplashKit C++ program. | [**Hello from C/C++**](https://programmers.guide/book/part-0-getting-started/3-building-programs/1-tour/3-hello-cpp/) | +| C++ | More in-depth C++ guide. | [**Building a C/C++ Program**](https://programmers.guide/book/part-2-organised-code/1-starting-cpp/2-trailside/1-0-building-cpp/) | diff --git a/src/content/docs/guides/Input/1-mouse-button-inputs.mdx b/src/content/docs/guides/input/user-inputs-in-graphical-applications.mdx similarity index 76% rename from src/content/docs/guides/Input/1-mouse-button-inputs.mdx rename to src/content/docs/guides/input/user-inputs-in-graphical-applications.mdx index 1308b3a3c..fd0e4a811 100644 --- a/src/content/docs/guides/Input/1-mouse-button-inputs.mdx +++ b/src/content/docs/guides/input/user-inputs-in-graphical-applications.mdx @@ -1,12 +1,14 @@ --- -title: Using Mouse Inputs -description: Introductory Mouse Input functionality guide -category: Guides -author: Various Authors -lastupdated: October 2024 +title: User Inputs in Graphical Applications +description: Introductory guide on reading text and mouse input functionality. +author: Various +lastupdated: July 2025 +tableOfContents: + minHeadingLevel: 2 + maxHeadingLevel: 4 --- -import { Tabs, TabItem } from "@astrojs/starlight/components"; +import { Tabs, TabItem, Steps } from "@astrojs/starlight/components"; **{frontmatter.description}** Written by: {frontmatter.author} @@ -14,11 +16,339 @@ _Last updated: {frontmatter.lastupdated}_ --- -## Mouse Button Functionality +## Reading Text in Graphical Applications + +Reading input from users in graphical applications is more complex than using command line inputs, as blocking operations will cause the entire graphical interface to freeze. + +With a graphical application, you need to keep redrawing, processing events, updating elements, and refreshing the screen. If you stop doing this to wait for user input, then any dynamic visuals will stop! + +### Example Code + +Let's see how to read input from the user using some example code. We can then talk through the different parts to understand how they come together to give you a dynamic application with user input. + + + + +```cpp +#include "splashkit.h" + +int main() +{ + // Lets read into this string... + string name = "unknown"; + + // Open a window to show the user... + open_window("Reading Input.", 800, 600); + + // Load a font for text rendering + load_font("input", "arial.ttf"); + + // Define area where text should appear + rectangle rect = rectangle_from(230.0, 50.0, 200.0, 30.0); + + // Start reading text in this area + start_reading_text(rect); + + // Here is our game loop + do + { + // Listen for input... this will update the text read + process_events(); + + // Click anywhere on the screen to trigger the text input + if (mouse_clicked(LEFT_BUTTON)) + { + // Start reading text in the rectagle area + start_reading_text(rect); + } + + // Looks like we finished reading text... + if (not reading_text()) + { + // Was input cancelled? + if (text_entry_cancelled()) + { + name = "unknown"; + } + else + { + // Get the name from the text input + name = text_input(); + } + } + + // Draw the screen... + clear_screen(COLOR_WHITE); + draw_rectangle(COLOR_BLACK, rect); + + // If we are reading text... then show what it is + if (reading_text()) + { + draw_collected_text(COLOR_BLACK, font_named("input"), 18, option_defaults()); + } + + // Draw text instructions + draw_text("Click anywhere to start reading text", COLOR_RED, font_named("input"), 18, 200, 100); + + // Draw what we have in the name + draw_text(name, COLOR_BLACK, font_named("input"), 18, 10, 10); + + // Show it.. + refresh_screen(60); + } while (!quit_requested()); + + close_all_windows(); + return 0; +} +``` + + + + + + + +```csharp +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Let's read into this string... +string name = "unknown"; + +// Open a window to show the user... +OpenWindow("Reading Input.", 800, 600); + +// Load a font for text rendering +LoadFont("input", "arial.ttf"); + +// Define the area where text should appear +Rectangle rect = RectangleFrom(230.0, 50.0, 200.0, 30.0); + +// Start reading text in this area +StartReadingText(rect); + +// Here is our game loop +do +{ + // Listen for input... this will update the text read + ProcessEvents(); + + // Click anywhere on the screen to trigger the text input + if (MouseClicked(MouseButton.LeftButton)) + { + // Start reading text in the rectagle area + StartReadingText(rect); + } + + // Looks like we finished reading text... + if (!ReadingText()) + { + // Was input canceled? + if (TextEntryCancelled()) + { + name = "unknown"; + } + else + { + // Get the name from the text input + name = TextInput(); + } + } + + // Draw the screen... + ClearScreen(ColorWhite()); + DrawRectangle(ColorBlack(), rect); + + // If we are reading text... then show what it is + if (ReadingText()) + { + DrawCollectedText(ColorBlack(), FontNamed("input"), 18, OptionDefaults()); + } + + // Draw text instructions + DrawText("Click anywhere to start reading text", Color.Red, SplashKit.FontNamed("input"), 18, 200, 100); + + // Draw what we have in the name + DrawText(name, ColorBlack(), FontNamed("input"), 18, 10, 10); + + // Show it... + RefreshScreen(60); +} while (!QuitRequested()); + +CloseAllWindows(); +``` + + + + +```csharp +using SplashKitSDK; + +namespace ReadingInput +{ + public class Program + { + public static void Main() + { + // Let's read into this string... + string name = "unknown"; + + // Open a window to show the user... + Window window = new Window("Reading Input.", 800, 600); + + // Load a font for text rendering + Font font = new Font("input", "arial.ttf"); + + // Define the area where text should appear + Rectangle rect = SplashKit.RectangleFrom(230.0, 50.0, 200.0, 30.0); + + // Start reading text in the rectagle area + SplashKit.StartReadingText(rect); + + // Here is our game loop + do + { + // Listen for input... this will update the text read + SplashKit.ProcessEvents(); + + // Click anywhere on the screen to trigger the text input + if (SplashKit.MouseClicked(MouseButton.LeftButton)) + { + // Start reading text in the rectagle area + SplashKit.StartReadingText(rect); + } + + // Looks like we finished reading text... + if (!SplashKit.ReadingText()) + { + // Was input canceled? + if (SplashKit.TextEntryCancelled()) + { + name = "unknown"; + } + else + { + // Get the name from the text input + name = SplashKit.TextInput(); + } + } + + // Draw the screen... + window.Clear(Color.White); + window.DrawRectangle(Color.Black, rect); + + // If we are reading text... then show what it is + if (SplashKit.ReadingText()) + { + SplashKit.DrawCollectedText(Color.Black, font, 18, SplashKit.OptionDefaults()); + } + + // Draw text instructions + window.DrawText("Click anywhere to start reading text", Color.Red, font, 18, 200, 100); + + // Draw what we have in the name + window.DrawText(name, Color.Black, font, 18, 10, 10); + + // Show it... + window.Refresh(60); + } while (!window.CloseRequested); + + SplashKit.CloseAllWindows(); + } + } +} +``` + + + + + + + +```python +from splashkit import * + +# Lets read into this string... +name = "unknown" + +# Open a window to show the user... +open_window("Reading Input.", 800, 600) + +# Load a font for text rendering +load_font("input", "arial.ttf") + +# Define area where text should appear +rect = rectangle_from(230.0, 50.0, 200.0, 30.0) + +# Start reading text in this area +start_reading_text(rect) + +# Here is our game loop +while not quit_requested(): + + # Listen for input... thiss will update the text read + process_events() + + # Click anywhere on the screen to trigger the text input + if (mouse_clicked(MouseButton.left_button)): + # Start reading text in the rectagle area + start_reading_text(rect) + + # Looks like we finished reading text... + if not reading_text(): + # Was input cancelled + if text_entry_cancelled(): + name = "unknown" + else: + # Get the name from the text input + name = text_input() + + # Draw the screen... + clear_screen(color_white()) + draw_rectangle_record(color_black(), rect) + + # If we are reading text... then show what it is + if reading_text(): + draw_collected_text(color_black(), font_named("input"), 18, option_defaults()) + + # Draw text instructions + draw_text("Click anywhere to start reading text", color_red(), font_named("input"), 18, 200, 100) + + # Draw what we have in the name + draw_text(name, color_black(), font_named("input"), 18, 10, 10) + + # Show it... + refresh_screen_with_target_fps(60) + +close_all_windows() +``` + + + + +### Understanding the code + + + +1. In the above program we want to read in the user's name and store it in the `name` variable. To get started with this we need to open a window and load a font to draw the text and input. There is also the standard event loop that repeats the basic actions of checking user input and drawing the screen until the program is closed. + +2. The logic for reading input starts with the call to [Start Reading Text](/api/input/#start-reading-text). This tells SplashKit that you want it to collect text input by the user, and that you want it drawn into the passed-in [Rectangle](/api/types/#rectangle) (in this case `rect`). SplashKit is now listening for input from, and collecting this text for you when you call [Process Events](/api/input/#process-events). + +3. SplashKit will continue reading text from the user until they hit the Escape or Enter key. You can check if text is still being read by calling the [Reading Text](/api/input/#reading-text) function. In this example, we use this to update the name. You can also end text input yourself using the [End Reading Text](/api/input/#end-reading-text) function. + +4. When the SplashKit is no longer reading text, you can use [Text Entry Cancelled](/api/input/#text-entry-cancelled) to check if the user cancelled (by hitting Escape) the input. To read the actual value entered, you call [Text Input](/api/input/#text-input). This will return the value entered by the user. If they did cancel the input, then this will be an empty string. + +5. The key with graphical input will be to keep updating the data associated with the graphical elements. This will keep the screen updating as you collect the input from the user. For this, you need to [Start Reading Text](/api/input/#start-reading-text), then at some point collect the [Text Input](/api/input/#text-input) and [End Reading Text](/api/input/#end-reading-text). + + + +## Using Mouse Inputs in Graphical Applications + +### Mouse Button Functionality Here are some functions that are used to handle mouse button inputs. These functions all use SplashKit's [Mouse Button](/api/input/#mouse-button) data type for the argument and check if the specified button has been clicked, held down, or released. -### List of Mouse Button Enum Values +#### List of Mouse Button Enum Values [Mouse Button](/api/input/#mouse-button) is an enumeration used by SplashKit to read inputs from the mouse. Understanding how to handle mouse buttons is crucial for developers who want users to control their programs using the mouse. @@ -61,7 +391,7 @@ Here are some functions that are used to handle mouse button inputs. These funct -### Mouse Clicked +#### Mouse Clicked [Mouse Clicked](/api/input/#mouse-clicked) is a boolean function that checks if the specified `Mouse Button` has been clicked since the last time [Process Events](/api/input/#process-events) was called. @@ -222,7 +552,7 @@ if __name__ == "__main__": -### Mouse Down +#### Mouse Down [Mouse Down](/api/input/#mouse-down) checks if the specified button is being held down. @@ -398,7 +728,7 @@ if __name__ == "__main__": -### Mouse Up +#### Mouse Up Opposite to the previous function, [Mouse Up](/api/input/#mouse-up) checks if the specified button is released. @@ -551,11 +881,11 @@ if __name__ == "__main__": -## Mouse Movement Functionality +### Mouse Movement Functionality Another thing we can do with mouse input, other than checking button presses, is to check mouse movement in the program. -### Mouse Movement +#### Mouse Movement [Mouse Movement](/api/input/#mouse-movement) is a function that returns the amount of accumulated mouse movement since the last time `Process Events` was called. It returns the value as a `Vector 2D` data type, which shows the direction and distance in the x and y scale. @@ -758,7 +1088,7 @@ if __name__ == "__main__": -### Mouse Wheel Scroll +#### Mouse Wheel Scroll [Mouse Wheel Scroll](/api/input/#mouse-wheel-scroll) returns the distance and direction of the mouse scroll since the last time `Process Events` was called. Like the previous function, this function returns the `Vector 2D` data type. @@ -924,12 +1254,12 @@ if __name__ == "__main__": -## Mouse Location Functionality +### Mouse Location Functionality Now that we have learned how to handle mouse inputs and movements, let's look at how to use the mouse's location in the window, which can be used in your program to make the experience more interactive. Combined with the mouse input functions, it can be used to spawn items where the player clicked or respond to the player clicking where an item is located. -### Mouse Position +#### Mouse Position [Mouse Position](/api/input/#mouse-position) returns the position of the mouse in the current window as a [Point 2d](/api/types/#point-2d) data type, which is its x and y coordinates. @@ -1060,7 +1390,7 @@ if __name__ == "__main__": -### Mouse Position Vector +#### Mouse Position Vector [Mouse Position Vector](/api/input/#mouse-position-vector) returns the position of the mouse relative to the window origin as a [Vector 2d](/api/types/#vector-2d). @@ -1188,7 +1518,7 @@ if __name__ == "__main__": -### Mouse X +#### Mouse X [Mouse X](/api/input/#mouse-x) returns the distance of the mouse from the left edge of the window. @@ -1344,7 +1674,7 @@ if __name__ == "__main__": -### Mouse Y +#### Mouse Y [Mouse Y](/api/input/#mouse-y) returns the distance of the mouse from the top edge of the window. @@ -1497,12 +1827,12 @@ if __name__ == "__main__": -## Mouse Visibility +### Mouse Visibility Finally, we can also alter the mouse visibility on SplashKit. The following functions handles the mouse visibility. These can be useful to create a more immersive environment for your game. -### Hide/Show Mouse +#### Hide/Show Mouse [Hide Mouse](/api/input/#hide-mouse) hides the mouse from the screen. [Show Mouse](/api/input/#show-mouse-functions) shows the mouse to the screen. @@ -1687,7 +2017,7 @@ if __name__ == "__main__": -### Show Mouse +#### Show Mouse There are two versions of the [Show Mouse](/api/input/#show-mouse-with-boolean) function. The first version is shown above. The second version shows or hides the mouse based on its boolean parameter. If true, it shows the mouse, while if false, it hides the mouse from the screen. diff --git a/src/content/docs/guides/Interface/00-interface.mdx b/src/content/docs/guides/interface/getting-started-with-interfaces.mdx similarity index 99% rename from src/content/docs/guides/Interface/00-interface.mdx rename to src/content/docs/guides/interface/getting-started-with-interfaces.mdx index 43deacd73..3027d666b 100644 --- a/src/content/docs/guides/Interface/00-interface.mdx +++ b/src/content/docs/guides/interface/getting-started-with-interfaces.mdx @@ -1,7 +1,6 @@ --- title: Getting Started Creating User Interfaces description: This article will help you get started creating interfaces in SplashKit. In this one we'll see how to create and use basic elements, like buttons and sliders. In later the next ones, we'll move on to advanced layouting, and finally we'll see how we can style the interface to match our project. -category: Tutorials author: Sean Boettger and others lastupdated: October 2024 --- @@ -17,7 +16,7 @@ In this article we'll see how to create user interfaces in SplashKit. This'll le Let's see how we can create a simple button. We'll start in an empty project, and focus on just _showing_ the button. Then we'll make it interactive. -1. Let's begin by setting up our main function and opening up a window for us to place our interface elements on. See [Drawing using Procedures](/guides/graphics/0-drawing-using-procedures/) if you aren't familiar with this part. In this example code, we've: +1. Let's begin by setting up our main function and opening up a window for us to place our interface elements on. See [Drawing using Procedures](/guides/graphics/drawing-using-procedures/) if you aren't familiar with this part. In this example code, we've: 1. opened up a window 2. _cleared_ the screen white 3. _refreshed_ the screen so we can see what's on it diff --git a/src/content/docs/guides/Interface/images/first_button.png b/src/content/docs/guides/interface/images/first_button.png similarity index 100% rename from src/content/docs/guides/Interface/images/first_button.png rename to src/content/docs/guides/interface/images/first_button.png diff --git a/src/content/docs/guides/Interface/images/panel_w_labeltextbox.png b/src/content/docs/guides/interface/images/panel_w_labeltextbox.png similarity index 100% rename from src/content/docs/guides/Interface/images/panel_w_labeltextbox.png rename to src/content/docs/guides/interface/images/panel_w_labeltextbox.png diff --git a/src/content/docs/guides/Interface/images/style_panel.png b/src/content/docs/guides/interface/images/style_panel.png similarity index 100% rename from src/content/docs/guides/Interface/images/style_panel.png rename to src/content/docs/guides/interface/images/style_panel.png diff --git a/src/content/docs/guides/Interface/images/styles/bubble.png b/src/content/docs/guides/interface/images/styles/bubble.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/bubble.png rename to src/content/docs/guides/interface/images/styles/bubble.png diff --git a/src/content/docs/guides/Interface/images/styles/bubble_colored.png b/src/content/docs/guides/interface/images/styles/bubble_colored.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/bubble_colored.png rename to src/content/docs/guides/interface/images/styles/bubble_colored.png diff --git a/src/content/docs/guides/Interface/images/styles/bubble_multicolored.png b/src/content/docs/guides/interface/images/styles/bubble_multicolored.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/bubble_multicolored.png rename to src/content/docs/guides/interface/images/styles/bubble_multicolored.png diff --git a/src/content/docs/guides/Interface/images/styles/flatdark.png b/src/content/docs/guides/interface/images/styles/flatdark.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/flatdark.png rename to src/content/docs/guides/interface/images/styles/flatdark.png diff --git a/src/content/docs/guides/Interface/images/styles/flatlight.png b/src/content/docs/guides/interface/images/styles/flatlight.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/flatlight.png rename to src/content/docs/guides/interface/images/styles/flatlight.png diff --git a/src/content/docs/guides/Interface/images/styles/shadeddark.png b/src/content/docs/guides/interface/images/styles/shadeddark.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/shadeddark.png rename to src/content/docs/guides/interface/images/styles/shadeddark.png diff --git a/src/content/docs/guides/Interface/images/styles/shadeddark_colored.png b/src/content/docs/guides/interface/images/styles/shadeddark_colored.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/shadeddark_colored.png rename to src/content/docs/guides/interface/images/styles/shadeddark_colored.png diff --git a/src/content/docs/guides/Interface/images/styles/shadedlight.png b/src/content/docs/guides/interface/images/styles/shadedlight.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/shadedlight.png rename to src/content/docs/guides/interface/images/styles/shadedlight.png diff --git a/src/content/docs/guides/Interface/images/styles/shadedlight_colored.png b/src/content/docs/guides/interface/images/styles/shadedlight_colored.png similarity index 100% rename from src/content/docs/guides/Interface/images/styles/shadedlight_colored.png rename to src/content/docs/guides/interface/images/styles/shadedlight_colored.png diff --git a/src/content/docs/guides/Interface/01-interface-layouting.mdx b/src/content/docs/guides/interface/interface-layouts.mdx similarity index 99% rename from src/content/docs/guides/Interface/01-interface-layouting.mdx rename to src/content/docs/guides/interface/interface-layouts.mdx index b94316af3..e922a5488 100644 --- a/src/content/docs/guides/Interface/01-interface-layouting.mdx +++ b/src/content/docs/guides/interface/interface-layouts.mdx @@ -1,7 +1,6 @@ --- title: Layouts in User Interfaces description: This article will help you understand how to customize the layouts of your interfaces in SplashKit. -category: Tutorials author: Sean Boettger and others lastupdated: October 2024 --- diff --git a/src/content/docs/guides/Interface/02-interface-styling.mdx b/src/content/docs/guides/interface/interface-styling.mdx similarity index 99% rename from src/content/docs/guides/Interface/02-interface-styling.mdx rename to src/content/docs/guides/interface/interface-styling.mdx index 4ce9f80c9..6e6c290a0 100644 --- a/src/content/docs/guides/Interface/02-interface-styling.mdx +++ b/src/content/docs/guides/interface/interface-styling.mdx @@ -1,7 +1,6 @@ --- title: Styling User Interfaces description: This article will explain how we can style our SplashKit interfaces to match our projects. -category: Tutorials author: Sean Boettger and others lastupdated: October 2024 --- diff --git a/src/content/docs/guides/json/getting-started-with-json.mdx b/src/content/docs/guides/json/getting-started-with-json.mdx new file mode 100644 index 000000000..2a50c0a1a --- /dev/null +++ b/src/content/docs/guides/json/getting-started-with-json.mdx @@ -0,0 +1,1356 @@ +--- +title: Using JSON in SplashKit +description: This tutorial focuses on provising an introduction to using JSON (JavaScript Object Notation), with specifics on how to read and parse JSON data, and how to create and write data to JSON files. Understanding how to read and write JSON data is useful for game development tasks such as loading or saving game settings, level configurations, saving player progress, etc. +author: Jonathan Tynan and others +lastupdated: October 2024 +--- + +import { Tabs, TabItem } from "@astrojs/starlight/components"; + +**{frontmatter.description}** +Written by: {frontmatter.author} +_Last updated: {frontmatter.lastupdated}_ + +--- + +## Introduction to Using JSON + +### What is JSON? + +[JSON](/api/json/) is often used in various programming environments, including game development, for data storage and configuration. In SplashKit, JSON functionality allows developers to efficiently manage game settings, level data, and more. This section of the tutorial introduces JSON, its basic structure, and provides an overview of its application in SplashKit. + +### Basic Structure of a JSON File + +A basic JSON file might look like this: + +```json +{ + "gameTitle": "My New Game", + "screenSize": { + "width": 800, + "height": 600 + }, + "levels": ["level1", "level2", "level3"] +} +``` + +JSON objects are made up of values associated with keys. In this example, `gameTitle` is the key associated with the string `"My New Game"`, `screenSize` is the key for an object with two numeric values (width and height), and an array of strings is assigned as the value for the key `levels`. + +### Overview of JSON in SplashKit + +SplashKit simplifies the process of working with JSON files in your games. It provides functions for reading JSON files, allowing us to easily retrieve values and load configurations or game data. Additionally, it offers functions for writing JSON files, enabling us to save configurations and game data. + +### Getting Started with JSON in SplashKit + +To begin using JSON in SplashKit, we must have our files in the correct locations. Run the following command in your project directory to generate the resources folder. + +```shell +skm resources +``` + +This command creates sub-folders for each type of resource. One of these is named `json` and that is where we place our JSON files. To begin lets take the example JSON file above and place it into the `json` folder with the name `game_data.json`. To access the values in this file we can now do the following: + + + + +```cpp +#include "splashkit.h" +int main() +{ + json game_data = json_from_file("game_data.json"); + string game_title = json_read_string(game_data, "gameTitle"); + + write_line("Game Title: " + game_title); + + free_json(game_data); + + return 0; +} +``` + + + + + + + +```csharp +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +Json gameData = JsonFromFile("game_data.json"); +string gameTitle = JsonReadString(gameData, "gameTitle"); + +WriteLine("Game Title: " + gameTitle); + +FreeJson(gameData); +``` + + + + +```csharp +using SplashKitSDK; + +namespace GameDataManagement +{ + public class Program + { + public static void Main() + { + Json gameData = SplashKit.JsonFromFile("game_data.json"); + string gameTitle = SplashKit.JsonReadString(gameData, "gameTitle"); + + SplashKit.WriteLine("Game Title: " + gameTitle); + + SplashKit.FreeJson(gameData); + } + } +} +``` + + + + + + + +```python +from splashkit import * + +def main(): + game_data = json_from_file("game_data.json") + game_title = json_read_string(game_data, "gameTitle") + + if not game_title: + write_line("Error retrieving gameTitle.") + else: + write_line(f"Game Title: {game_title}") + + free_json(game_data) + +if __name__ == "__main__": + main() +``` + + + + +In this code example, we first use [Json From File](/api/json/#json-from-file) to load a JSON object containing details from the `game_data.json` file. +Next, we retrieve the value associated with the `gameTitle` key using [Json Read String](/api/json/#json-read-string)and output it to the console. Finally, we free the JSON object using [Free Json](/api/json/#free-json) before exiting the program. This deallocates any memory that was allocated to the JSON object, helping to prevent memory-related errors such as `Segmentation Fault`. We can build this program using the following command. + + + + +```shell +g++ program.cpp -l SplashKit -o json_program +``` + + + + +```shell +dotnet build +``` + + + + +And run it with: + + + + +```shell +./json_program +``` + + + + +```shell +dotnet run +``` + + + + +```shell +skm python3 program.py +``` + + + + +When we run this program, it should display the following output in the console: + +```plaintext +Game Title: My New Game +``` + +### Checking Keys + +But what if we didn't have a `gameTitle` key in our JSON? Well, error messages will be produced indicating that this key is `null`. To prevent this, we can use the [Json Has Key](/api/json/#json-has-key) function to check if the key is present and then do actions based on whether it has been found or not. We could then turn the previous example into the following code: + + + + +```cpp +#include "splashkit.h" +int main() +{ + json game_data = json_from_file("game_data.json"); + + if(json_has_key(game_data, "gameTitle")) + { + string game_title = json_read_string(game_data, "gameTitle"); + write("Game Title: "); + write_line(game_title); + } + else + { + write_line("Key \"gameTitle\" not found."); + } + + free_json(game_data); + + return 0; +} +``` + + + + + + + +```csharp +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +Json gameData = JsonFromFile("game_data.json"); + +if (JsonHasKey(gameData, "gameTitle")) +{ + string gameTitle = JsonReadString(gameData, "gameTitle"); + WriteLine("Game Title: " + gameTitle); +} +else +{ + WriteLine("Key \"gameTitle\" not found."); +} + +FreeJson(gameData); +``` + + + + +```csharp +using SplashKitSDK; + +namespace GameDataManagement +{ + public class Program + { + public static void Main() + { + Json gameData = SplashKit.JsonFromFile("game_data.json"); + + if (SplashKit.JsonHasKey(gameData, "gameTitle")) + { + string gameTitle = SplashKit.JsonReadString(gameData, "gameTitle"); + SplashKit.WriteLine("Game Title: " + gameTitle); + } + else + { + SplashKit.WriteLine("Key \"gameTitle\" not found."); + } + + SplashKit.FreeJson(gameData); + } + } +} +``` + + + + + + + +```python +from splashkit import * + +def main(): + game_data = json_from_file("game_data.json") + + if json_has_key(game_data, "gameTitle"): + game_title = json_read_string(game_data, "gameTitle") + write_line(f"Game Title: {game_title}") + else: + write_line('Key "gameTitle" not found.') + + free_json(game_data) + +if __name__ == "__main__": + main() +``` + + + + +We have successfully loaded our JSON file and retrieved the value associated with the `gameTitle` key. In the next section below, we'll delve deeper into retrieving other values stored within a JSON object. + +--- + +## Reading JSON Objects + +In the previous tutorial we loaded the following JSON file and read the game title from it. Lets extend this a little, and dive a further into extracting values from this structure. + +```json +{ + "gameTitle": "My New Game", + "fullScreenMode": false, + "numPlayers": 1, + "screenSize": { + "width": 800, + "height": 600 + }, + "levels": ["level1", "level2", "level3"] +} +``` + +### Accessing Values + +To access values in JSON objects like strings, numbers, or booleans, you can use functions like [Json Read String](/api/json/#json-read-string), [Json Read Number As Int](/api/json/#json-read-number-as-int), or [Json Read Bool](/api/json/#json-read-bool). We use these functions like the following code snippet. + + + + +```cpp +json game_data = json_from_file("game_data.json"); + +string title = json_read_string(game_data, "gameTitle"); +int numPlayers = json_read_number_as_int(game_data, "numPlayers"); +bool isFullScreen = json_read_bool(game_data, "fullScreenMode"); +``` + + + + + + + + +```csharp +Json gameData = JsonFromFile("game_data.json"); + +string title = JsonReadString(gameData, "gameTitle"); +int numPlayers = JsonReadNumberAsInt(gameData, "numPlayers"); +bool isFullScreen = JsonReadBool(gameData, "fullScreenMode"); +``` + + + + +```csharp +Json gameData = SplashKit.JsonFromFile("game_data.json"); + +string title = SplashKit.JsonReadString(gameData, "gameTitle"); +int numPlayers = SplashKit.JsonReadNumberAsInt(gameData, "numPlayers"); +bool isFullScreen = SplashKit.JsonReadBool(gameData, "fullScreenMode"); +``` + + + + + + + +```python +game_data = json_from_file("game_data.json") + +title = json_read_string(game_data, "gameTitle") +num_players = json_read_number_as_int(game_data, "numPlayers") +is_full_screen = json_read_bool(game_data, "fullScreenMode") +``` + + + + +### Working with JSON Arrays + +If the data is an array, like the value stored for the `levels` key, we can obtain the data through [Json Read Array](/api/json/#json-read-array-functions) and store it into a dynamic string array variable (such as `vector` in C++, or `List` in C#). Then we can loop through the entries in the array, and do some actions with the stored data. + +Below is an example of this: + + + + +```cpp +vector levels; + +json_read_array(game_data, "levels", levels); + +int num_levels = levels.size(); + +for(int i = 0; i < num_levels; i++) +{ + write("Got level: "); + write_line(levels[i]); +} +``` + + + + + + + + +```csharp +List levels = new List(); + +JsonReadArray(gameData, "levels", ref levels); + +int numLevels = levels.Count; + +for (int i = 0; i < numLevels; i++) +{ + WriteLine($"Got level: {levels[i]}"); +} +``` + + + + +```csharp +List levels = new List(); + +SplashKit.JsonReadArray(gameData, "levels", ref levels); + +int numLevels = levels.Count; + +for (int i = 0; i < numLevels; i++) +{ + SplashKit.WriteLine($"Got level: {levels[i]}"); +} +``` + + + + + + + +```python +levels = [] + +json_read_array_of_string(game_data, "levels", levels) + +num_levels = len(levels) + +for i in range(num_levels): + write_line(f"Got level: {levels[i]}") +``` + + + + +Running this prints the following to the terminal: + +```plaintext +Got level: level1 +Got level: level2 +Got level: level3 +``` + +### Extracting Nested JSON Objects + +SplashKit's JSON functionality allows you to extract various types of data, including basic types mentioned previously, but also even nested JSON objects. In our example file the value for the `screenSize` key is a JSON object. The following code demonstrates how to extract this object: + + + + +```cpp +json game_screen_size = json_read_object(game_data, "screenSize"); +int width = json_read_number_as_int(game_screen_size, "width"); +int height = json_read_number_as_int(game_screen_size, "height"); + +write_line("Screen Width: " + to_string(width)); +write_line("Screen Height: " + to_string(height)); +``` + + + + + + + + +```csharp +Json gameScreenSize = JsonReadObject(gamedata, "screenSize"); +int width = JsonReadNumberAsInt(gameScreenSize, "width"); +int height = JsonReadNumberAsInt(gameScreenSize, "height"); + +WriteLine($"Screen Width: {width}"); +WriteLine($"Screen Height: {height}"); +``` + + + + +```csharp +Json gameScreenSize = SplashKit.JsonReadObject(gamedata, "screenSize"); +int width = SplashKit.JsonReadNumberAsInt(gameScreenSize, "width"); +int height = SplashKit.JsonReadNumberAsInt(gameScreenSize, "height"); + +SplashKit.WriteLine($"Screen Width: {width}"); +SplashKit.WriteLine($"Screen Height: {height}"); +``` + + + + + + + +```python +game_screen_size = json_read_object(game_data, "screenSize") +width = json_read_number_as_int(game_screen_size, "width") +height = json_read_number_as_int(game_screen_size, "height") + +write_line(f"Screen Width: {width}") +write_line(f"Screen Height: {height}") +``` + + + + +Running this prints the following to the terminal: + +```plaintext +Screen Width: 800 +Screen Height: 600 +``` + +### Putting it all together + +By combining all these examples we can create the full program shown below. + + + + +```cpp +#include "splashkit.h" +using namespace std; + +int main() +{ + // Load the game data JSON file + json game_data = json_from_file("game_data.json"); + + // Read the game data from the JSON + string title = json_read_string(game_data, "gameTitle"); + int numPlayers = json_read_number_as_int(game_data, "numPlayers"); + bool isFullScreen = json_read_bool(game_data, "fullScreenMode"); + vector levels; + + // Write the game data to the terminal + write_line("Game Title: " + title); + write_line("Number of Players: " + to_string(numPlayers)); + write_line("Full Screen Mode: " + to_string(isFullScreen)); + + // Read the levels array from the JSON + json_read_array(game_data, "levels", levels); + + int num_levels = levels.size(); + + for (int i = 0; i < num_levels; i++) + { + write("Got level: "); + write_line(levels[i]); + } + + // Extract the nested JSON objects + json game_screen_size = json_read_object(game_data, "screenSize"); + int width = json_read_number_as_int(game_screen_size, "width"); + int height = json_read_number_as_int(game_screen_size, "height"); + + // Write the screen size to the terminal + write_line("Screen Width: " + to_string(width)); + write_line("Screen Height: " + to_string(height)); +} +``` + + + + + + + + +```csharp +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +// Load the game data JSON file +Json gameData = JsonFromFile("game_data.json"); + +// Read the game data from the JSON +string title = JsonReadString(gameData, "gameTitle"); +int numPlayers = JsonReadNumberAsInt(gameData, "numPlayers"); +bool isFullScreen = JsonReadBool(gameData, "fullScreenMode"); +List levels = new List(); + +// Write the game data to the terminal +WriteLine($"Game Title: {title}"); +WriteLine($"Number of Players: {numPlayers}"); +WriteLine($"Full Screen Mode: {isFullScreen}"); + +// Read the levels array from the JSON +JsonReadArray(gameData, "levels", ref levels); + +int numLevels = levels.Count; + +for (int i = 0; i < numLevels; i++) +{ + WriteLine($"Got level: {levels[i]}"); +} + +// Extract the nested JSON objects +Json gameScreenSize = JsonReadObject(gameData, "screenSize"); +int width = JsonReadNumberAsInt(gameScreenSize, "width"); +int height = JsonReadNumberAsInt(gameScreenSize, "height"); + +// Write the screen size to the terminal +WriteLine($"Screen Width: {width}"); +WriteLine($"Screen Height: {height}"); +``` + + + + +```csharp +using System; +using System.Collections.Generic; +using SplashKitSDK; + +class Program +{ + static void Main() + { + // Load the game data JSON file + Json gameData = SplashKit.JsonFromFile("game_data.json"); + + // Read the game data from the JSON + string title = SplashKit.JsonReadString(gameData, "gameTitle"); + int numPlayers = SplashKit.JsonReadNumberAsInt(gameData, "numPlayers"); + bool isFullScreen = SplashKit.JsonReadBool(gameData, "fullScreenMode"); + List levels = new List(); + + // Write the game data to the terminal + SplashKit.WriteLine($"Game Title: {title}"); + SplashKit.WriteLine($"Number of Players: {numPlayers}"); + SplashKit.WriteLine($"Full Screen Mode: {isFullScreen}"); + + // Read the levels array from the JSON + SplashKit.JsonReadArray(gameData, "levels", ref levels); + + int numLevels = levels.Count; + + for (int i = 0; i < numLevels; i++) + { + SplashKit.WriteLine($"Got level: {levels[i]}"); + } + + // Extract the nested JSON objects + Json gameScreenSize = SplashKit.JsonReadObject(gameData, "screenSize"); + int width = SplashKit.JsonReadNumberAsInt(gameScreenSize, "width"); + int height = SplashKit.JsonReadNumberAsInt(gameScreenSize, "height"); + + // Write the screen size to the terminal + SplashKit.WriteLine($"Screen Width: {width}"); + SplashKit.WriteLine($"Screen Height: {height}"); + } +} + +``` + + + + + + + +```python +from splashkit import * + +# Load the game data JSON file +game_data = json_from_file("game_data.json") + +# Read the game data from the JSON object +title = json_read_string(game_data, "gameTitle") +num_players = json_read_number_as_int(game_data, "numPlayers") +is_full_screen = json_read_bool(game_data, "fullScreenMode") +levels = [] + +# Write the game data to the terminal +write_line(f"Game Title: {title}") +write_line(f"Number of Players: {num_players}") +write_line(f"Full Screen Mode: {is_full_screen}") + +# Read the levels array from the JSON file +json_read_array_of_string(game_data, "levels", levels) + +num_levels = len(levels) + +for i in range(num_levels): + write_line(f"Got level: {levels[i]}") + +# Extract the nested JSON objects +game_screen_size = json_read_object(game_data, "screenSize") +width = json_read_number_as_int(game_screen_size, "width") +height = json_read_number_as_int(game_screen_size, "height") + +# Write the screen size to the terminal +write_line(f"Screen Width: {width}") +write_line(f"Screen Height: {height}") +``` + + + + +In this example, [Json Read Object](/api/json/#json-read-object) is used to extract the nested JSON object, and then the values are read from this nested object. These variables can then be used to define the window size for this game. + +--- + +Reading JSON data with SplashKit is a straightforward process that can greatly enhance the flexibility and functionality of your game. It enables dynamic loading of game content and configurations, making your game more adaptable and easier to manage. + +In the next part of this tutorial, we explore how to write and modify JSON data, allowing you to save game states, configurations, and player preferences. + +--- + +## Writing JSON Objects + +### Creating JSON Objects and Arrays + +In SplashKit, you can programmatically create JSON objects and arrays, which then can be populated with data. Lets see how we can create the example JSON file from previous tutorials with this method. + + + + +```cpp +json new_game_data = create_json(); +json_set_string(new_game_data, "gameTitle", "My New Game"); +json_set_bool(new_game_data, "fullScreenMode", false); +json_set_number(new_game_data, "numPlayers", 1); +``` + + + + + + + +```csharp +Json newGameData = CreateJson(); +JsonSetString(newGameData, "gameTitle", "My New Game"); +JsonSetBool(newGameData, "fullScreenMode", false); +JsonSetNumber(newGameData, "numPlayers", 1); +``` + + + + +```csharp +Json newGameData = SplashKit.CreateJson(); +SplashKit.JsonSetString(newGameData, "gameTitle", "My New Game"); +SplashKit.JsonSetBool(newGameData, "fullScreenMode", false); +SplashKit.JsonSetNumber(newGameData, "numPlayers", 1); +``` + + + + + + + +```python +new_game_data = create_json() + +json_set_string(new_game_data, "gameTitle", "My New Game") +json_set_bool(new_game_data, "fullScreenMode", False) +json_set_number_integer(new_game_data, "numPlayers", 1) +``` + + + + +First we create the new JSON object using [Create Json](/api/json/#create-json), then we add basic data to **gameTitle**, **fullScreenMode**, and **numPlayers** using [Json Set String](/api/json/#json-set-string), [Json Set Bool](/api/json/#json-set-bool) and [Json Set Number](/api/json#json-set-number-functions). + + + + +```cpp +vector levels_array; + +levels_array.push_back("level1"); +levels_array.push_back("level2"); +levels_array.push_back("level3"); + +json_set_array(new_game_data, "levels", levels_array); +``` + + + + + + + +```csharp +List levelsArray = new List +{ + "level1", + "level2", + "level3" +}; + +JsonSetArray(newGameData, "levels", levelsArray); +``` + + + + +```csharp +List levelsArray = new List +{ + "level1", + "level2", + "level3" +}; + +SplashKit.JsonSetArray(newGameData, "levels", levelsArray); +``` + + + + + + + +```python +levels_array = ["level1", "level2", "level3"] +json_set_array_of_string(new_game_data, "levels", levels_array) +``` + + + + +Next we add the levels array to the JSON object. We create a vector to store the strings, and push back each string that we want. Finally we use [Json Set Array](/api/json/#json-set-array-functions) to store this data in JSON format. + + + + +```cpp +json screen_size_data = create_json(); + +json_set_number(screen_size_data, "width", 800); +json_set_number(screen_size_data, "height", 600); + +json_set_object(new_game_data, "screenSize", screen_size_data); +``` + + + + + + + +```csharp +Json screenSizeData = CreateJson(); + +JsonSetNumber(screenSizeData, "width", 800); +JsonSetNumber(screenSizeData, "height", 600); + +JsonSetObject(newGameData, "screenSize", screenSizeData); +``` + + + + +```csharp +Json screenSizeData = SplashKit.CreateJson(); + +SplashKit.JsonSetNumber(screenSizeData, "width", 800); +SplashKit.JsonSetNumber(screenSizeData, "height", 600); + +SplashKit.JsonSetObject(newGameData, "screenSize", screenSizeData); +``` + + + + + + + +```python +screen_size_data = create_json() + +json_set_number_integer(screen_size_data, "width", 800) +json_set_number_integer(screen_size_data, "height", 600) + +json_set_object(new_game_data, "screenSize", screen_size_data) +``` + + + + +Then we tackle the nested JSON object, the screen size object. We use [Create Json](/api/json/#create-json) to create a new object for this data, and then we add the width and the height to the object using [Json Set Number](/api/json/#json-set-number-functions). Now that we have this JSON object filled with the data we want, we add it to the `new_game_data` object with [Json Set Object](/api/json/#json-set-object). + +### Writing JSON Data to a File + +Now that we have the `new_game_data` object that stores the same values as the JSON file used previously. Now, we can save this using [Json To File](/api/json/#json-to-file) like in the code below. + +:::note +Make sure to run `skm resources` to create the `Resources/json/` folder before executing this code. +::: + + + + +```cpp +json_to_file(new_game_data, "new_game_data.json"); +``` + + + + + + + +```csharp +JsonToFile(newGameData, "new_game_data.json"); + +``` + + + + +```csharp +SplashKit.JsonToFile(newGameData, "new_game_data.json"); +``` + + + + + + + +```python +json_to_file(new_game_data, "new_game_data.json") +``` + + + + +By combining all these examples we can create the full program shown below. + + + + +```cpp +#include "splashkit.h" + +int main() +{ + json new_game_data = create_json(); + + json_set_string(new_game_data, "gameTitle", "My New Game"); + json_set_bool(new_game_data, "fullScreenMode", false); + json_set_number(new_game_data, "numPlayers", 1); + + json screen_size_data = create_json(); + + json_set_number(screen_size_data, "width", 800); + json_set_number(screen_size_data, "height", 600); + + json_set_object(new_game_data, "screenSize", screen_size_data); + + vector levels_array; + + levels_array.push_back("level1"); + levels_array.push_back("level2"); + levels_array.push_back("level3"); + + json_set_array(new_game_data, "levels", levels_array); + + json_to_file(new_game_data, "new_game_data.json"); + + free_all_json(); +} +``` + + + + + + + +```csharp +using SplashKitSDK; +using static SplashKitSDK.SplashKit; +using System.Collections.Generic; + +Json newGameData = CreateJson(); + +JsonSetString(newGameData, "gameTitle", "My New Game"); +JsonSetBool(newGameData, "fullScreenMode", false); +JsonSetNumber(newGameData, "numPlayers", 1); + +Json screenSizeData = CreateJson(); +JsonSetNumber(screenSizeData, "width", 800); +JsonSetNumber(screenSizeData, "height", 600); + +JsonSetObject(newGameData, "screenSize", screenSizeData); + +List levelsArray = new List +{ + "level1", + "level2", + "level3" +}; + +JsonSetArray(newGameData, "levels", levelsArray); + +JsonToFile(newGameData, "new_game_data.json"); +FreeJson(newGameData); + +FreeJson(screenSizeData); +``` + + + + +```csharp +using SplashKitSDK; +using System.Collections.Generic; + +namespace WritingJsonData +{ + public class Program + { + public static void Main() + { + Json newGameData = SplashKit.CreateJson(); + + SplashKit.JsonSetString(newGameData, "gameTitle", "My New Game"); + SplashKit.JsonSetBool(newGameData, "fullScreenMode", false); + SplashKit.JsonSetNumber(newGameData, "numPlayers", 1); + + Json screenSizeData = SplashKit.CreateJson(); + SplashKit.JsonSetNumber(screenSizeData, "width", 800); + SplashKit.JsonSetNumber(screenSizeData, "height", 600); + + SplashKit.JsonSetObject(newGameData, "screenSize", screenSizeData); + + List levelsArray = new List + { + "level1", + "level2", + "level3" + }; + + SplashKit.JsonSetArray(newGameData, "levels", levelsArray); + + SplashKit.JsonToFile(newGameData, "new_game_data.json"); + SplashKit.FreeJson(newGameData); + + SplashKit.FreeJson(screenSizeData); + } + } +} +``` + + + + + + + +```python +from splashkit import * + +new_game_data = create_json() + +json_set_string(new_game_data, "gameTitle", "My New Game") +json_set_bool(new_game_data, "fullScreenMode", False) +json_set_number_integer(new_game_data, "numPlayers", 1) + +screen_size_data = create_json() +json_set_number_integer(screen_size_data, "width", 800) +json_set_number_integer(screen_size_data, "height", 600) + +json_set_object(new_game_data, "screenSize", screen_size_data) + +levels_array = ["level1", "level2", "level3"] + +json_set_array_of_string(new_game_data, "levels", levels_array) +json_to_file(new_game_data, "new_game_data.json") + +free_all_json() +``` + + + + +Running this program results in a file named `new_game_data.json` being written to the `Resources/json/` folder. Open this up and you'll see something very similar or identical to the example JSON file we've been using previously. It should look something like this: + +```json +{ + "numPlayers": 1, + "fullScreenMode": false, + "gameTitle": "My New Game", + "levels": [ + "level1", + "level2", + "level3" + ], + "screenSize": { + "height": 600, + "width": 800 + } +} +``` + +Some of the keys can be in different positions, but this does not affect how we use it as we look for the key when retrieving values, not a particular data position in the JSON file. This new file is effectively the same JSON that we've used in previous JSON tutorials. + +### Modifying Existing JSON Data + +You can also load an existing JSON file, modify its contents, and save the changes back to the file. To demonstrate this, lets add the details of a player character to our game data. + + + + +```cpp +json player_data = create_json(); +json_set_string(player_data, "name", "Hero"); + +json stats_data = create_json(); +json_set_number(stats_data, "health", 100); +json_set_number(stats_data, "mana", 50); +json_set_number(stats_data, "strength", 75); + +json_set_object(player_data, "stats", stats_data); +``` + + + + + + + +```csharp +Json playerData = CreateJson(); +JsonSetString(playerData, "name", "Hero"); + +Json statsData = CreateJson(); +JsonSetNumber(statsData, "health", 100); +JsonSetNumber(statsData, "mana", 50); +JsonSetNumber(statsData, "strength", 75); + +JsonSetObject(playerData, "stats", statsData); +``` + + + + +```csharp +Json playerData = SplashKit.CreateJson(); +SplashKit.JsonSetString(playerData, "name", "Hero"); + +Json statsData = SplashKit.CreateJson(); +SplashKit.JsonSetNumber(statsData, "health", 100); +SplashKit.JsonSetNumber(statsData, "mana", 50); +SplashKit.JsonSetNumber(statsData, "strength", 75); + +SplashKit.JsonSetObject(playerData, "stats", statsData); +``` + + + + + + + +```python +player_data = create_json() +json_set_string(player_data, "name", "Hero") + +stats_data = create_json() +json_set_number_integer(stats_data, "health", 100) +json_set_number_integer(stats_data, "mana", 50) +json_set_number_integer(stats_data, "strength", 75) + +json_set_object(player_data, "stats", stats_data) +``` + + + + +First we create the player JSON object to store the data for an entire character, then we create an individual object to hold the stats for the character. After this we add the stats object and nest it in the `player_data` object we created earlier. + + + + +```cpp +json existing_data = json_from_file("new_game_data.json") +json_set_object(existing_data, "character", player_data); + +json_to_file(existing_data, "modified_game_data.json"); +``` + + + + + + + +```csharp +Json existingData = JsonFromFile("new_game_data.json"); +JsonSetObject(existingData, "character", playerData); + +JsonToFile(existingData, "modified_game_data.json"); +``` + + + + +```csharp +Json existingData = SplashKit.JsonFromFile("new_game_data.json"); +SplashKit.JsonSetObject(existingData, "character", playerData); + +SplashKit.JsonToFile(existingData, "modified_game_data.json"); +``` + + + + + + + +```python +existing_data = json_from_file("new_game_data.json") +json_set_object(existing_data, "character", player_data) + +json_to_file(existing_data, "modified_game_data.json") +``` + + + + +Next we load the game data we saved previously, add our `player_data` object to the existing data and save it. If we add this code to our previous program and run it a file is created in the `Resources/json/` folder named `modified_game_data.json`. Open it, and you should see something like the following: + +```json +{ + "character": { + "name": "Hero", + "stats": { + "health": 100, + "mana": 50, + "strength": 75 + } + }, + "fullScreenMode": false, + "numPlayers": 1, + "gameTitle": "My New Game", + "levels": [ + "levels1", + "levels2", + "levels3" + ], + "screenSize": { + "height": 600, + "width": 800 + } +} +``` + +Now we have a character object stored with this JSON file. We also now have multiple levels of nesting. When this is the case and we want to access the innermost key we must get these JSON objects. So, to access the health stat we can use the following code: + + + + +```cpp +// Load our JSON +json modified_game_data = json_from_file("modified_game_data.json"); +// Retrieve Character JSON object from the file. +json character = json_read_object(modified_game_data, "character"); +// Retrieve the Stats JSON object from the Character JSON +json stats = json_read_object(character, "stats"); +// Retrieve the value of health from the stats JSON object +int hp = json_read_number_as_int(stats, "health"); +``` + + + + + + + +```csharp +// Load our JSON +Json modifiedGameData = JsonFromFile("modified_game_data.json"); + +// Retrieve Character JSON object from the file. +Json modifiedGameData = JsonFromFile("modified_game_data.json"); + +// Retrieve the Stats JSON object from the Character JSON +Json stats = JsonReadObject(character, "stats"); + +// Retrieve the value of health from the stats JSON object +int hp = JsonReadNumberAsInt(stats, "health"); +``` + + + + +```csharp +// Load our JSON +Json modifiedGameData = SplashKit.JsonFromFile("modified_game_data.json"); + +// Retrieve Character JSON object from the file. +Json character = SplashKit.JsonReadObject(modifiedGameData, "character"); + +// Retrieve the Stats JSON object from the Character JSON +Json stats = SplashKit.JsonReadObject(character, "stats"); + +// Retrieve the value of health from the stats JSON object +int hp = SplashKit.JsonReadNumberAsInt(stats, "health"); +``` + + + + + + + +```python +# Load our JSON +modified_game_data = json_from_file("modified_game_data.json") + +# Retrieve Character JSON object from the file. +character = json_read_object(modified_game_data, "character") + +# Retrieve the Stats JSON object from the Character JSON +stats = json_read_object(character, "stats") + +# Retrieve the value of health from the stats JSON object +hp = json_read_number_as_int(stats, "health") +``` + + + + +By following this tutorial, you're now equipped with the foundational skills necessary to create, read and write JSON data objects with SplashKit. These examples have been focused around game development, but the JSON skills you've learnt extends beyond this as JSON is a versatile tool for any software development project. diff --git a/src/content/docs/guides/Networking/0-getting-started-with-servers.mdx b/src/content/docs/guides/networking/getting-started-with-servers.mdx similarity index 97% rename from src/content/docs/guides/Networking/0-getting-started-with-servers.mdx rename to src/content/docs/guides/networking/getting-started-with-servers.mdx index 9f41bc641..d47ebb0cb 100644 --- a/src/content/docs/guides/Networking/0-getting-started-with-servers.mdx +++ b/src/content/docs/guides/networking/getting-started-with-servers.mdx @@ -1,7 +1,6 @@ --- title: Getting Started With Servers -description: This guide is an introduction to using web servers -category: Guides +description: This guide is an introduction to using SplashKit's web servers. author: Andrew Cain, Isaac Wallis and others lastupdated: October 2024 --- @@ -20,7 +19,7 @@ Web browsers and servers are programs that make it possible for you to access re For the computer you connected with to know what to do there must be a program that is listening for these requests and performing some actions in response. In this case that program is what we generally call a "web server". It has an open port (somewhere for others to connect to) and listens on that port for incoming connections. When the connection arrives, it can read the request, perform some actions, and respond. -In this article you will see how to start listening for connections, how to send a file in response, and how to stop listening for new connections. This is then build upon in the [Routing With Servers](/guides/networking/1-routing-with-servers) article, which shows you how to customise your response based upon what the caller requested. +In this article you will see how to start listening for connections, how to send a file in response, and how to stop listening for new connections. This is then build upon in the [Routing With Servers](/guides/networking/routing-with-servers) article, which shows you how to customise your response based upon what the caller requested. ## Step 1: Getting Started @@ -382,4 +381,4 @@ stop_web_server(server) ## Next Step -See how to respond to different requests in the [routing with servers](/guides/networking/1-routing-with-servers) article. +See how to respond to different requests in the [routing with servers](/guides/networking/routing-with-servers) article. diff --git a/src/content/docs/guides/Networking/2-restful-api-call.mdx b/src/content/docs/guides/networking/restful-api-call.mdx similarity index 99% rename from src/content/docs/guides/Networking/2-restful-api-call.mdx rename to src/content/docs/guides/networking/restful-api-call.mdx index 7c26f2a03..ea0fdee71 100644 --- a/src/content/docs/guides/Networking/2-restful-api-call.mdx +++ b/src/content/docs/guides/networking/restful-api-call.mdx @@ -1,7 +1,6 @@ --- title: How to make a RESTful API call using SplashKit description: In the world of web services and microservices, many companies make their data available through a REST API in this document we want to use SplashKit to make a RESTful API call. -category: Guides author: Cyrill Illi and others lastupdated: October 2024 --- diff --git a/src/content/docs/guides/Networking/1-routing-with-servers.mdx b/src/content/docs/guides/networking/routing-with-servers.mdx similarity index 99% rename from src/content/docs/guides/Networking/1-routing-with-servers.mdx rename to src/content/docs/guides/networking/routing-with-servers.mdx index 322812e5f..dbaf24d4a 100644 --- a/src/content/docs/guides/Networking/1-routing-with-servers.mdx +++ b/src/content/docs/guides/networking/routing-with-servers.mdx @@ -1,7 +1,6 @@ --- title: Routing With Servers description: This guide is an intruduction to delivering different content based on route requested -category: Guides author: Isaac Wallis and others lastupdated: October 2024 --- @@ -14,7 +13,7 @@ _Last updated: {frontmatter.lastupdated}_ --- -This article extends the skills gained from [Getting Started With Servers](/guides/networking/0-getting-started-with-servers) specifically around serving different files for different paths +This article extends the skills gained from [Getting Started With Servers](/guides/networking/getting-started-with-servers) specifically around serving different files for different paths ## Routing diff --git a/src/content/docs/guides/Physics/0-introduction-to-vectors.mdx b/src/content/docs/guides/physics/0-introduction-to-vectors.mdx similarity index 99% rename from src/content/docs/guides/Physics/0-introduction-to-vectors.mdx rename to src/content/docs/guides/physics/0-introduction-to-vectors.mdx index c3920ea8e..ff89c1539 100644 --- a/src/content/docs/guides/Physics/0-introduction-to-vectors.mdx +++ b/src/content/docs/guides/physics/0-introduction-to-vectors.mdx @@ -1,7 +1,6 @@ --- title: Introduction to Vectors description: Vectors are a fundamental tool in game development, enabling precise control over movement, collision, and physics. Understanding vectors unlocks the ability to create dynamic and realistic game experiences. SplashKit excels in handling vector operations, offering intuitive functions and robust support for 2D game mechanics. -category: Guides authors: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/1-vector-magnitudes.mdx b/src/content/docs/guides/physics/1-vector-magnitudes.mdx similarity index 99% rename from src/content/docs/guides/Physics/1-vector-magnitudes.mdx rename to src/content/docs/guides/physics/1-vector-magnitudes.mdx index 9cc231f68..971df6646 100644 --- a/src/content/docs/guides/Physics/1-vector-magnitudes.mdx +++ b/src/content/docs/guides/physics/1-vector-magnitudes.mdx @@ -1,7 +1,6 @@ --- title: Vector Magnitudes description: Understanding vector magnitudes, squared magnitudes, and inversions is essential for various programming applications, from game mechanics to physics simulations. This tutorial explores these concepts using SplashKit functions to enhance your programming toolkit. -category: Guides author: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/2-vector-arithmetic.mdx b/src/content/docs/guides/physics/2-vector-arithmetic.mdx similarity index 99% rename from src/content/docs/guides/Physics/2-vector-arithmetic.mdx rename to src/content/docs/guides/physics/2-vector-arithmetic.mdx index 2cc20e2b5..e76bc3b0c 100644 --- a/src/content/docs/guides/Physics/2-vector-arithmetic.mdx +++ b/src/content/docs/guides/physics/2-vector-arithmetic.mdx @@ -1,7 +1,6 @@ --- title: Vector Arithmetic description: This tutorial covers essential vector arithmetic operations, including addition, subtraction, and multiplication, using SplashKit functions. These operations are fundamental for tasks such as calculating movement, force, and direction in game development and physics simulations. -category: Guides author: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/3-vector-geometry-angles.mdx b/src/content/docs/guides/physics/3-vector-geometry-angles.mdx similarity index 99% rename from src/content/docs/guides/Physics/3-vector-geometry-angles.mdx rename to src/content/docs/guides/physics/3-vector-geometry-angles.mdx index 996212d73..83795f7e4 100644 --- a/src/content/docs/guides/Physics/3-vector-geometry-angles.mdx +++ b/src/content/docs/guides/physics/3-vector-geometry-angles.mdx @@ -1,7 +1,6 @@ --- title: Vector Angles description: A guide to understanding vector angles using SplashKit functions, including dot product, vector angle, and angle between vectors. -category: Guides author: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/4-collision-detection-using-vectors.mdx b/src/content/docs/guides/physics/4-collision-detection-using-vectors.mdx similarity index 99% rename from src/content/docs/guides/Physics/4-collision-detection-using-vectors.mdx rename to src/content/docs/guides/physics/4-collision-detection-using-vectors.mdx index 501a88b18..052bcb294 100644 --- a/src/content/docs/guides/Physics/4-collision-detection-using-vectors.mdx +++ b/src/content/docs/guides/physics/4-collision-detection-using-vectors.mdx @@ -1,7 +1,6 @@ --- title: Resolving Collisions Using Vectors description: Learn how to detect and resolve collisions between moving objects using vectors in SplashKit. -category: Guides author: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/5-collisions-and-gravity.mdx b/src/content/docs/guides/physics/5-collisions-and-gravity.mdx similarity index 99% rename from src/content/docs/guides/Physics/5-collisions-and-gravity.mdx rename to src/content/docs/guides/physics/5-collisions-and-gravity.mdx index c2e9034c7..b2e3e8f7d 100644 --- a/src/content/docs/guides/Physics/5-collisions-and-gravity.mdx +++ b/src/content/docs/guides/physics/5-collisions-and-gravity.mdx @@ -1,7 +1,6 @@ --- title: Collisions and Gravity description: Learn how to simulate realistic wall collisions and apply gravity using vector-based physics in SplashKit. This guide explores key principles such as collision detection, response, and gravity simulation, while leveraging SplashKit's intuitive vector functions for 2D game mechanics. -category: Guides authors: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/6-raycasting-basics.mdx b/src/content/docs/guides/physics/6-raycasting-basics.mdx similarity index 99% rename from src/content/docs/guides/Physics/6-raycasting-basics.mdx rename to src/content/docs/guides/physics/6-raycasting-basics.mdx index ae05dee96..861c1e03c 100644 --- a/src/content/docs/guides/Physics/6-raycasting-basics.mdx +++ b/src/content/docs/guides/physics/6-raycasting-basics.mdx @@ -1,7 +1,6 @@ --- title: Raycasting Basics description: This tutorial introduces raycasting, a foundational technique in game development and computer graphics used to simulate line-of-sight, detect collisions, and render 3D effects in 2D environments. -category: Guides authors: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/7-raycasting-light.mdx b/src/content/docs/guides/physics/7-raycasting-light.mdx similarity index 99% rename from src/content/docs/guides/Physics/7-raycasting-light.mdx rename to src/content/docs/guides/physics/7-raycasting-light.mdx index 4a0fdac5f..510c3227d 100644 --- a/src/content/docs/guides/Physics/7-raycasting-light.mdx +++ b/src/content/docs/guides/physics/7-raycasting-light.mdx @@ -1,7 +1,6 @@ --- title: Raycasting and Illumination description: Learn how to implement a raycasting system with SplashKit to simulate light rays and object illumination. This tutorial covers collision detection, dynamic ray length adjustment, and interactive visuals for game development or physics simulations. -category: Guides authors: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Physics/8-3d-projection-raycasting.mdx b/src/content/docs/guides/physics/8-3d-projection-raycasting.mdx similarity index 99% rename from src/content/docs/guides/Physics/8-3d-projection-raycasting.mdx rename to src/content/docs/guides/physics/8-3d-projection-raycasting.mdx index 89c4af729..8201f24e9 100644 --- a/src/content/docs/guides/Physics/8-3d-projection-raycasting.mdx +++ b/src/content/docs/guides/physics/8-3d-projection-raycasting.mdx @@ -1,7 +1,6 @@ --- title: 2D to 3D Projection description: This tutorial demonstrates how to implement a 2D to 3D projection system using raycasting in SplashKit, combining a first-person 3D view with a top-down 2D map to visualise the player's field of view and interactions in a grid-based environment. -category: Guides authors: Shaun Ratcliff lastupdated: 08 Dec 24 --- diff --git a/src/content/docs/guides/Raspberry-GPIO/0-blink-led.mdx b/src/content/docs/guides/raspberry-gpio/0-blink-led.mdx similarity index 57% rename from src/content/docs/guides/Raspberry-GPIO/0-blink-led.mdx rename to src/content/docs/guides/raspberry-gpio/0-blink-led.mdx index 9f8c629b2..b4e2e2c5a 100644 --- a/src/content/docs/guides/Raspberry-GPIO/0-blink-led.mdx +++ b/src/content/docs/guides/raspberry-gpio/0-blink-led.mdx @@ -1,9 +1,8 @@ --- title: Get Started with SplashKit GPIO description: General-purpose input/output, or GPIO, pins are a type of pin found on many microcontrollers that can be used for a variety of purposes. In this guide we use them to control the state of an LED -category: Guides author: Jonathan Tynan -lastupdated: December 2024 +lastupdated: May 2025 --- import { Tabs, TabItem, Steps } from "@astrojs/starlight/components"; @@ -88,8 +87,8 @@ can be M/M, M/F, or F/F. We are using M/F jumper wires in this guide. ## The Circuit -Below we can see the circuit diagram for this project. We have the cathode of the LED connected to -GPIO Pin 11, while the anode is connected to ground pin 6 through a resistor. +Below we can see the circuit diagram for this project. We have the anode (longer wire) of the LED connected to +GPIO Pin 11, while the cathode (shorter wire) is connected to ground pin 6 through a resistor. ![Circuit Diagram for Blinking an LED](./images/circuits/blinkled.png) @@ -115,6 +114,12 @@ some output like the following: gpio_init() must be called before any other GPIO functions ``` +or + +```shell +ERROR [default] Pigpio error: bad connect. +``` + We can check if its running by using the following command: ```shell @@ -141,30 +146,30 @@ blinks an LED on and off. - ```cpp - #include "splashkit.h" - - int main() - { - raspi_init(); - pins led_pin = PIN_11; - raspi_set_mode(led_pin, GPIO_OUTPUT); - - open_window("dummy_window", 1, 1); - while(!any_key_pressed()) - { - process_events(); - raspi_write(led_pin, GPIO_HIGH); - delay(500); - raspi_write(led_pin, GPIO_LOW); - delay(500); - } - - close_all_windows(); - raspi_cleanup(); - return 0; - } - ``` +```cpp +#include "splashkit.h" + +int main() +{ + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + raspi_write(led_pin, GPIO_HIGH); + delay(500); + raspi_write(led_pin, GPIO_LOW); + delay(500); + } + + close_all_windows(); + raspi_cleanup(); + return 0; +} +``` @@ -177,16 +182,16 @@ using SplashKitSDK; using static SplashKitSDK.SplashKit; RaspiInit(); -Pins ledPin = (Pins)11; -RaspiSetMode(led_pin, (PinModes) 1); +GpioPin ledPin = (GpioPin) 11; +RaspiSetMode(ledPin, (GpioPinMode) 1); OpenWindow("dummy_window", 1, 1); while(!AnyKeyPressed()) { ProcessEvents(); - RaspiWrite(led_pin, (PinState) 1); + RaspiWrite(ledPin, (GpioPinValue) 1); Delay(500); - RaspiWrite(led_pin, (PinState) 0); + RaspiWrite(ledPin, (GpioPinValue) 0); Delay(500); } @@ -207,16 +212,16 @@ namespace RaspberryPiBlinkingLED public static void Main() { SplashKit.RaspiInit(); - Pins ledPin = (Pins)11; - SplashKit.RaspiSetMode(ledPin, (PinModes)1); + GpioPin ledPin = GpioPin.Pin11; + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); SplashKit.OpenWindow("dummy_window", 1, 1); while (!SplashKit.AnyKeyPressed()) { SplashKit.ProcessEvents(); - SplashKit.RaspiWrite(ledPin, (PinValues)1); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); SplashKit.Delay(500); - SplashKit.RaspiWrite(ledPin, (PinValues)0); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); SplashKit.Delay(500); } @@ -229,6 +234,7 @@ namespace RaspberryPiBlinkingLED + @@ -237,15 +243,39 @@ namespace RaspberryPiBlinkingLED To understand this code better, lets break it down and explore each section. -1. **Part 1** + +1. **Initialise GPIO Hardware:** + + In this bit of the code we're setting up the hardware, we call [Raspi Init](/api/raspberry/#raspi-init) to initialise the GPIO pins, and then we define the specific pin we're using which is Pin 11 in this case and it is of the [Gpio Pin](/api/types/#gpio-pin) type. + + We pass this value to [Raspi Set Mode](/api/raspberry/#raspi-set-mode) along with `GPIO_OUTPUT` which sets the pin to be ready to output a signal on our command. The `GPIO_OUTPUT` value is one of the [Gpio Pin Modes](/api/types/#gpio-pin-mode) that can be set. Each pin has alternative modes but we are only interested in the output mode for now. - ```cpp - raspi_init(); - pins led_pin = PIN_11; - raspi_set_mode(led_pin, GPIO_OUTPUT); + ```cpp {5-7} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + raspi_write(led_pin, GPIO_HIGH); + delay(500); + raspi_write(led_pin, GPIO_LOW); + delay(500); + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } ``` @@ -255,19 +285,59 @@ To understand this code better, lets break it down and explore each section. - ```csharp + ```csharp {4-6} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + RaspiInit(); - Pins ledPin = (Pins)11; - RaspiSetMode(led_pin, (PinModes) 1); + GpioPin ledPin = (GpioPin) 11; + RaspiSetMode(ledPin, (GpioPinMode) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + RaspiWrite(ledPin, (GpioPinValue) 1); + Delay(500); + RaspiWrite(ledPin, (GpioPinValue) 0); + Delay(500); + } + + CloseAllWindows(); + RaspiCleanup(); ``` - ```csharp - SplashKit.RaspiInit(); - Pins ledPin = (Pins)11; - SplashKit.RaspiSetMode(ledPin, (PinModes)1); + ```csharp {9-11} + using SplashKitSDK; + + namespace RaspberryPiBlinkingLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin ledPin = GpioPin.Pin11; + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + SplashKit.Delay(500); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + SplashKit.Delay(500); + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } ``` @@ -275,22 +345,35 @@ To understand this code better, lets break it down and explore each section. - In this bit of the code we're setting up the hardware, we call [Raspi Init](/api/raspberry/#raspi-init) to initialise the GPIO pins, - and then we define the specific pin we're using which is Pin 11 in this case and it is of the [Gpio Pin](/api/types/#gpio-pin) type. - - We pass this value to [Raspi Set Mode](/api/raspberry/#raspi-set-mode) along with `GPIO_OUTPUT` which sets the pin to be ready to output a signal on our command. The `GPIO_OUTPUT` value is one of the [Gpio Pin Modes](/api/types/#gpio-pin-mode) that can be set. Each pin has alternative modes but we are only interested in the output mode for now. +2. **Get User Inputs:** -2. **Part 2** + There is a small trick we can use to recognise keyboard inputs by opening a dummy window using [Open Window](/api/windows/#open-window), which initialises the backend so that we can detect input. We'll then use a loop that runs while [Any Key Pressed](/api/input/#any-key-pressed) returns false. We use [Process Events](/api/input/#process-events) at the start of the loop to actually detect any user input. We can now press a key to end the program and ensure we cleanup correctly. - ```cpp - open_window("dummy_window", 1, 1); - while(!any_key_pressed()) + ```cpp {9-12,17} + #include "splashkit.h" + + int main() { - process_events(); - ... + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + raspi_write(led_pin, GPIO_HIGH); + delay(500); + raspi_write(led_pin, GPIO_LOW); + delay(500); + } + + close_all_windows(); + raspi_cleanup(); + return 0; } ``` @@ -301,24 +384,58 @@ To understand this code better, lets break it down and explore each section. - ```csharp + ```csharp {8-11,16} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin ledPin = (GpioPin) 11; + RaspiSetMode(ledPin, (GpioPinMode) 1); + OpenWindow("dummy_window", 1, 1); while(!AnyKeyPressed()) { ProcessEvents(); - ... + RaspiWrite(ledPin, (GpioPinValue) 1); + Delay(500); + RaspiWrite(ledPin, (GpioPinValue) 0); + Delay(500); } + + CloseAllWindows(); + RaspiCleanup(); ``` - ```csharp - SplashKit.OpenWindow("dummy_window", 1, 1); - while (!SplashKit.AnyKeyPressed()) + ```csharp {13-16,21} + using SplashKitSDK; + + namespace RaspberryPiBlinkingLED { - SplashKit.ProcessEvents(); - ... + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin ledPin = GpioPin.Pin11; + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + SplashKit.Delay(500); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + SplashKit.Delay(500); + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } } ``` @@ -327,18 +444,36 @@ To understand this code better, lets break it down and explore each section. - This is a small trick we can do to recognise keyboard inputs. We open up a dummy window using [Open Window](/api/windows/#open-window) and this initialises the backend so that we can detect input. We'll create a loop that runs while [Any Key Pressed](/api/input/#any-key-pressed) returns false. We use [Process Events](/api/input/#process-events) at the start of the loop to actually detect any user input. We can now press a key to end the program and ensure we cleanup correctly. +3. **Blink the LED:** -3. **Part 3** + Now that we've setup our pins and defined our end condition, we can now manipulate the LED. Inside the while loop we first use [Raspi Write](/api/raspberry/#raspi-write) to change the output of our pin to `GPIO_HIGH`, one of the [Pin Values](/api/types/#gpio-pin-value). Doing this provides electricity to the LED and turn it on. We then wait for half a second using [Delay](/api/utilities/#delay). Then we turn our LED off using [Raspi Write](/api/raspberry/#raspi-write), but now we use `GPIO_LOW`, and wait for another half-second. - ```cpp - raspi_write(led_pin, GPIO_HIGH); - delay(500); - raspi_write(led_pin, GPIO_LOW); - delay(500); + ```cpp {13-16} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + raspi_write(led_pin, GPIO_HIGH); + delay(500); + raspi_write(led_pin, GPIO_LOW); + delay(500); + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } ``` @@ -348,21 +483,59 @@ To understand this code better, lets break it down and explore each section. - ```csharp - RaspiWrite(led_pin, (PinState) 1); - Delay(500); - RaspiWrite(led_pin, (PinState) 0); - Delay(500); + ```csharp {12-15} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin ledPin = (GpioPin) 11; + RaspiSetMode(ledPin, (GpioPinMode) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + RaspiWrite(ledPin, (GpioPinValue) 1); + Delay(500); + RaspiWrite(ledPin, (GpioPinValue) 0); + Delay(500); + } + + CloseAllWindows(); + RaspiCleanup(); ``` - ```csharp - SplashKit.RaspiWrite(ledPin, (PinValues)1); - SplashKit.Delay(500); - SplashKit.RaspiWrite(ledPin, (PinValues)0); - SplashKit.Delay(500); + ```csharp {17-20} + using SplashKitSDK; + + namespace RaspberryPiBlinkingLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin ledPin = GpioPin.Pin11; + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + SplashKit.Delay(500); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + SplashKit.Delay(500); + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } ``` @@ -370,17 +543,36 @@ To understand this code better, lets break it down and explore each section. - Now that we've setup our pins and defined our end condition, we can now manipulate the LED. Inside the while loop we first use [Raspi Write](/api/raspberry/#raspi-write) to change the output of our pin to `GPIO_HIGH`, one of the [Pin Values](/api/types/#gpio-pin-value). Doing this provides electricity to the LED and turn it on. We then wait for half a second using [Delay](/api/utilities/#delay). Then we turn our LED off using [Raspi Write](/api/raspberry/#raspi-write), but now we use `GPIO_LOW`, and wait for another half-second. +4. **Clean Up Memory:** -4. **Part 4** + Finally, as we exit the program we must ensure that we cleanup our program properly. We must first close the dummy window we opened use [Close All Windows](/api/windows/#close-all-windows). We then call [Raspi Cleanup](/api/raspberry/#raspi-cleanup) to ensure our pins are turned off and cleaned. - ```cpp - close_all_windows(); - raspi_cleanup(); - return 0; + ```cpp {19-20} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + raspi_write(led_pin, GPIO_HIGH); + delay(500); + raspi_write(led_pin, GPIO_LOW); + delay(500); + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } ``` @@ -390,7 +582,24 @@ To understand this code better, lets break it down and explore each section. - ```csharp + ```csharp {18-19} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin ledPin = (GpioPin) 11; + RaspiSetMode(ledPin, (GpioPinMode) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + RaspiWrite(ledPin, (GpioPinValue) 1); + Delay(500); + RaspiWrite(ledPin, (GpioPinValue) 0); + Delay(500); + } + CloseAllWindows(); RaspiCleanup(); ``` @@ -398,9 +607,34 @@ To understand this code better, lets break it down and explore each section. - ```csharp - SplashKit.CloseAllWindows(); - SplashKit.RaspiCleanup(); + ```csharp {23-24} + using SplashKitSDK; + + namespace RaspberryPiBlinkingLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin ledPin = GpioPin.Pin11; + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + SplashKit.Delay(500); + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + SplashKit.Delay(500); + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } ``` @@ -408,8 +642,6 @@ To understand this code better, lets break it down and explore each section. - Finally, as we exit the program we must ensure that we cleanup our program properly. We must first close the dummy window we opened use [Close All Windows](/api/windows/#close-all-windows). We then call [Raspi Cleanup](/api/raspberry/#raspi-cleanup) to ensure our pins are turned off and cleaned. - :::tip[Program Shutdown] diff --git a/src/content/docs/guides/raspberry-gpio/1-read-button-press.mdx b/src/content/docs/guides/raspberry-gpio/1-read-button-press.mdx new file mode 100644 index 000000000..a34f2b5f7 --- /dev/null +++ b/src/content/docs/guides/raspberry-gpio/1-read-button-press.mdx @@ -0,0 +1,823 @@ +--- +title: Reading Button Presses +description: + Reading GPIO inputs is a crucial component of creating responsive projects. In this guide we learn + to read GPIO inputs by using a simple button to turn an LED on and off. +author: Jonathan Tynan +lastupdated: May 2025 +--- + +import { Tabs, TabItem , Steps} from "@astrojs/starlight/components"; + +**{frontmatter.description}** +Written by: {frontmatter.author} +_Last updated: {frontmatter.lastupdated}_ + +--- + +:::caution[Before you begin:] +When working with Raspberry Pi GPIO pins, it's crucial to handle the setup and cleanup processes carefully. + +- Always ensure that the GPIO pins are properly initialised before use and cleaned up afterwards to prevent any damage to your Raspberry Pi +- Be mindful of static electricity which can pose a serious risk to the sensitive electronic components on the board +- Before touching the Raspberry Pi or any connected components, ground yourself to eliminate any static charge that may have accumulated. + +These precautions help to protect your device from potential harm caused by electrostatic discharges. +::: + +In this guide, we explore how to use the GPIO pins on a Raspberry Pi to read button presses. This ability is crucial for projects involving user input, like interactive installations or basic controls for robotics. We look at the basics of setting up a circuit with a button, how to use the SplashKit library to detect the button press and briefly introduce more advanced topics like the concept of floating pins and debouncing. + +## Components + +### Breadboard + +Breadboards are invaluable for testing and building circuits without the need for soldering. Arranged in rows and columns of holes, each row internally connected. See [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led/#components) for more details. + +### Push Button + +A push button allows electricity to flow between its two contacts by physically moving strips of metal together when pressed. This connects the circuit and provides power to our input pin. This pushbutton has four pins and each diagonal pin is paired with each other. It's a simple switch mechanism which we can detect and use. + +### Jumper Wires + +Jumper wires connect our components on the breadboard to the Raspberry Pi and each other. We use M/F jumper wires for this setup. See [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led/#components) for more details. + +## The Circuit + +Below is the circuit diagram for this project. We connect the power and ground to the appropriate rails on the breadboard and connect our components ground or power connections to these rails. We can have the LED directly connected to Pin 11 on the Raspberry Pi, and the button to Pin 29. + +![Circuit Diagram for reading a button press](./images/circuits/buttonpush.png) + +The physical circuit is show in the below image, where we can see the physical implementation of the provided circuit diagram. Note: The power and ground rail connections are swapped in the below image due to the orientation of the breadboard, ensure your connections are correct. + +![Photograph of circuit for reading a button press](./images/circuits/push_button_circuit.png) + +## The Code + +:::caution[Before running the code:] +This code requires the `pigpio` daemon, so make sure it is running! For more information see: [Starting the Daemon](/guides/raspberry-gpio/0-blink-led/#starting-the-daemon) +::: + + + + +```cpp +#include "splashkit.h" + +int main() +{ + raspi_init(); + gpio_pin button_pin = PIN_29; + gpio_pin led_pin = PIN_11; + gpio_pin_value led_state = GPIO_LOW; + + raspi_set_mode(button_pin, GPIO_INPUT); + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pull_up_down(button_pin, PUD_DOWN); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + if(raspi_read(button_pin) == GPIO_HIGH) + { + led_state = raspi_read(led_pin); + if(led_state == GPIO_LOW) + { + raspi_write(led_pin, GPIO_HIGH); + } + else + { + raspi_write(led_pin, GPIO_LOW); + } + } + } + + close_all_windows(); + raspi_cleanup(); + return 0; +} +``` + + + + + + + +```csharp +using SplashKitSDK; +using static SplashKitSDK.SplashKit; + +RaspiInit(); +GpioPin buttonPin = (GpioPin)29; +GpioPin ledPin = (GpioPin)11; +GpioPinValue ledState = (GpioPinValue) 0; + +RaspiSetMode(buttonPin, (GpioPinMode) 0); +RaspiSetMode(ledPin, (GpioPinMode) 1); + +RaspiSetPullUpDown(buttonPin, (PullUpDown) 1); + +OpenWindow("dummy_window", 1, 1); +while(!AnyKeyPressed()) +{ + ProcessEvents(); + if(RaspiRead(buttonPin) == (GpioPinValue) 1) + { + ledState = RaspiRead(ledPin); + if(ledState == (GpioPinValue) 0) + { + RaspiWrite(ledPin, (GpioPinValue) 1); + } + else + { + RaspiWrite(ledPin, (GpioPinValue) 0); + } + } +} + +CloseAllWindows(); +RaspiCleanup(); +``` + + + + +```csharp +using SplashKitSDK; + +namespace RaspberryPiButtonLED +{ + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin buttonPin = GpioPin.Pin29; + GpioPin ledPin = GpioPin.Pin11; + GpioPinValue ledState = GpioPinValue.GpioLow; + + SplashKit.RaspiSetMode(buttonPin, GpioPinMode.GpioInput); + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.RaspiSetPullUpDown(buttonPin, PullUpDown.PudDown); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + if (SplashKit.RaspiRead(buttonPin) == GpioPinValue.GpioHigh) + { + ledState = SplashKit.RaspiRead(ledPin); + if (ledState == GpioPinValue.GpioLow) + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + } + else + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + } + } + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } +} +``` + + + + + + +### Understanding the code + +Lets break down this code and analyse it in sections. + + + +1. **Initialise GPIO Hardware:** + + We start this code by initialising our hardware through [Raspi Init](/api/raspberry/#raspi-init), we then define the [Pins](/api/types/#gpio-pin) that we're are using for the button (Pin 29), and the LED (Pin 11). We also initialise a variable, `led_state`, to hold the state of the LED at any point in time. We use `led_state` later to determine whether to switch the LED on, or off. + + Next, we set the mode for each pin using [Raspi Set Mode](/api/raspberry/#raspi-set-mode). The button pin is set to [`GPIO_INPUT`](/api/types/#gpio-pin-mode) and the LED pin is set to [`GPIO_OUTPUT`](/api/types/#gpio-pin-mode). We do this as in this program we are detecting the input of the button and are writing the output of the LED. Then we use [Raspi Set Pull Up Down](/api/raspberry/#raspi-set-pull-up-down) on the button pin with the argument [`PUD_DOWN`](/api/types/#pull-up-down). This sets the internal pull-down resistor to prevent the pin from being a ["floating pin."](#floating-pins) + + + + + ```cpp {5-8,10,11,13} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin button_pin = PIN_29; + gpio_pin led_pin = PIN_11; + gpio_pin_value led_state = GPIO_LOW; + + raspi_set_mode(button_pin, GPIO_INPUT); + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pull_up_down(button_pin, PUD_DOWN); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + if(raspi_read(button_pin) == GPIO_HIGH) + { + led_state = raspi_read(led_pin); + if(led_state == GPIO_LOW) + { + raspi_write(led_pin, GPIO_HIGH); + } + else + { + raspi_write(led_pin, GPIO_LOW); + } + } + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } + ``` + + + + + + + + + ```csharp {4-7,9-10,12} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin buttonPin = (GpioPin)29; + GpioPin ledPin = (GpioPin)11; + GpioPinValue ledState = (GpioPinValue) 0; + + RaspiSetMode(buttonPin, (GpioPinMode) 0); + RaspiSetMode(ledPin, (GpioPinMode) 1); + + RaspiSetPullUpDown(buttonPin, (PullUpDown) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + if(RaspiRead(buttonPin) == (GpioPinValue) 1) + { + ledState = RaspiRead(ledPin); + if(ledState == (GpioPinValue) 0) + { + RaspiWrite(ledPin, (GpioPinValue) 1); + } + else + { + RaspiWrite(ledPin, (GpioPinValue) 0); + } + } + } + + CloseAllWindows(); + RaspiCleanup(); + ``` + + + + + ```csharp {9-12,14-15,17} + using SplashKitSDK; + + namespace RaspberryPiButtonLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin buttonPin = GpioPin.Pin29; + GpioPin ledPin = GpioPin.Pin11; + GpioPinValue ledState = GpioPinValue.GpioLow; + + SplashKit.RaspiSetMode(buttonPin, GpioPinMode.GpioInput); + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.RaspiSetPullUpDown(buttonPin, PullUpDown.PudDown); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + if (SplashKit.RaspiRead(buttonPin) == GpioPinValue.GpioHigh) + { + ledState = SplashKit.RaspiRead(ledPin); + if (ledState == GpioPinValue.GpioLow) + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + } + else + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + } + } + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } + ``` + + + + + + +2. **Get User Inputs:** + + Just like in the first [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led), we create a process that limits how long our program runs for. We do this so we know that our pins are cleaned properly upon exiting the program. + + + + + ```cpp {15-18,31} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin button_pin = PIN_29; + gpio_pin led_pin = PIN_11; + gpio_pin_value led_state = GPIO_LOW; + + raspi_set_mode(button_pin, GPIO_INPUT); + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pull_up_down(button_pin, PUD_DOWN); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + if(raspi_read(button_pin) == GPIO_HIGH) + { + led_state = raspi_read(led_pin); + if(led_state == GPIO_LOW) + { + raspi_write(led_pin, GPIO_HIGH); + } + else + { + raspi_write(led_pin, GPIO_LOW); + } + } + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } + ``` + + + + + + + + + ```csharp {14-17,30} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin buttonPin = (GpioPin)29; + GpioPin ledPin = (GpioPin)11; + GpioPinValue ledState = (GpioPinValue) 0; + + RaspiSetMode(buttonPin, (GpioPinMode) 0); + RaspiSetMode(ledPin, (GpioPinMode) 1); + + RaspiSetPullUpDown(buttonPin, (PullUpDown) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + if(RaspiRead(buttonPin) == (GpioPinValue) 1) + { + ledState = RaspiRead(ledPin); + if(ledState == (GpioPinValue) 0) + { + RaspiWrite(ledPin, (GpioPinValue) 1); + } + else + { + RaspiWrite(ledPin, (GpioPinValue) 0); + } + } + } + + CloseAllWindows(); + RaspiCleanup(); + ``` + + + + + ```csharp {19-22,35} + using SplashKitSDK; + + namespace RaspberryPiButtonLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin buttonPin = GpioPin.Pin29; + GpioPin ledPin = GpioPin.Pin11; + GpioPinValue ledState = GpioPinValue.GpioLow; + + SplashKit.RaspiSetMode(buttonPin, GpioPinMode.GpioInput); + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.RaspiSetPullUpDown(buttonPin, PullUpDown.PudDown); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + if (SplashKit.RaspiRead(buttonPin) == GpioPinValue.GpioHigh) + { + ledState = SplashKit.RaspiRead(ledPin); + if (ledState == GpioPinValue.GpioLow) + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + } + else + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + } + } + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } + ``` + + + + + + +3. **Read the Button Press:** + + Below is the main section of this code. On each loop we read the state of the button pin using [Raspi Read](/api/raspberry/#raspi-read) and if the result is `GPIO_HIGH`, then this indicates that the button has been pressed. We then read the state of the led, which can either be `GPIO_LOW` indicated the LED is not on, or `GPIO_HIGH` indicating that the LED is on. Once we have this state we can use [Raspi Write](/api/raspberry/#raspi-write) to change the pin to the opposite of what has been read. + + + + + ```cpp {19-30} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin button_pin = PIN_29; + gpio_pin led_pin = PIN_11; + gpio_pin_value led_state = GPIO_LOW; + + raspi_set_mode(button_pin, GPIO_INPUT); + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pull_up_down(button_pin, PUD_DOWN); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + if(raspi_read(button_pin) == GPIO_HIGH) + { + led_state = raspi_read(led_pin); + if(led_state == GPIO_LOW) + { + raspi_write(led_pin, GPIO_HIGH); + } + else + { + raspi_write(led_pin, GPIO_LOW); + } + } + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } + ``` + + + + + + + + + ```csharp {18-29} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin buttonPin = (GpioPin)29; + GpioPin ledPin = (GpioPin)11; + GpioPinValue ledState = (GpioPinValue) 0; + + RaspiSetMode(buttonPin, (GpioPinMode) 0); + RaspiSetMode(ledPin, (GpioPinMode) 1); + + RaspiSetPullUpDown(buttonPin, (PullUpDown) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + if(RaspiRead(buttonPin) == (GpioPinValue) 1) + { + ledState = RaspiRead(ledPin); + if(ledState == (GpioPinValue) 0) + { + RaspiWrite(ledPin, (GpioPinValue) 1); + } + else + { + RaspiWrite(ledPin, (GpioPinValue) 0); + } + } + } + + CloseAllWindows(); + RaspiCleanup(); + ``` + + + + + ```csharp {23-34} + using SplashKitSDK; + + namespace RaspberryPiButtonLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin buttonPin = GpioPin.Pin29; + GpioPin ledPin = GpioPin.Pin11; + GpioPinValue ledState = GpioPinValue.GpioLow; + + SplashKit.RaspiSetMode(buttonPin, GpioPinMode.GpioInput); + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.RaspiSetPullUpDown(buttonPin, PullUpDown.PudDown); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + if (SplashKit.RaspiRead(buttonPin) == GpioPinValue.GpioHigh) + { + ledState = SplashKit.RaspiRead(ledPin); + if (ledState == GpioPinValue.GpioLow) + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + } + else + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + } + } + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } + ``` + + + + + + +4. **Clean Up Memory:** + + Just like in the first [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led) and most projects involving GPIO pins, we must ensure that the hardware and resources we've used are cleaned properly, and we do this by stopping and freeing our timers and calling [Raspi Cleanup](/api/raspberry/#raspi-cleanup). + + + + + ```cpp {33-34} + #include "splashkit.h" + + int main() + { + raspi_init(); + gpio_pin button_pin = PIN_29; + gpio_pin led_pin = PIN_11; + gpio_pin_value led_state = GPIO_LOW; + + raspi_set_mode(button_pin, GPIO_INPUT); + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pull_up_down(button_pin, PUD_DOWN); + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + if(raspi_read(button_pin) == GPIO_HIGH) + { + led_state = raspi_read(led_pin); + if(led_state == GPIO_LOW) + { + raspi_write(led_pin, GPIO_HIGH); + } + else + { + raspi_write(led_pin, GPIO_LOW); + } + } + } + + close_all_windows(); + raspi_cleanup(); + return 0; + } + ``` + + + + + + + + + ```csharp {32-33} + using SplashKitSDK; + using static SplashKitSDK.SplashKit; + + RaspiInit(); + GpioPin buttonPin = (GpioPin)29; + GpioPin ledPin = (GpioPin)11; + GpioPinValue ledState = (GpioPinValue) 0; + + RaspiSetMode(buttonPin, (GpioPinMode) 0); + RaspiSetMode(ledPin, (GpioPinMode) 1); + + RaspiSetPullUpDown(buttonPin, (PullUpDown) 1); + + OpenWindow("dummy_window", 1, 1); + while(!AnyKeyPressed()) + { + ProcessEvents(); + if(RaspiRead(buttonPin) == (GpioPinValue) 1) + { + ledState = RaspiRead(ledPin); + if(ledState == (GpioPinValue) 0) + { + RaspiWrite(ledPin, (GpioPinValue) 1); + } + else + { + RaspiWrite(ledPin, (GpioPinValue) 0); + } + } + } + + CloseAllWindows(); + RaspiCleanup(); + ``` + + + + + ```csharp {37-38} + using SplashKitSDK; + + namespace RaspberryPiButtonLED + { + public class Program + { + public static void Main() + { + SplashKit.RaspiInit(); + GpioPin buttonPin = GpioPin.Pin29; + GpioPin ledPin = GpioPin.Pin11; + GpioPinValue ledState = GpioPinValue.GpioLow; + + SplashKit.RaspiSetMode(buttonPin, GpioPinMode.GpioInput); + SplashKit.RaspiSetMode(ledPin, GpioPinMode.GpioOutput); + + SplashKit.RaspiSetPullUpDown(buttonPin, PullUpDown.PudDown); + + SplashKit.OpenWindow("dummy_window", 1, 1); + while (!SplashKit.AnyKeyPressed()) + { + SplashKit.ProcessEvents(); + if (SplashKit.RaspiRead(buttonPin) == GpioPinValue.GpioHigh) + { + ledState = SplashKit.RaspiRead(ledPin); + if (ledState == GpioPinValue.GpioLow) + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioHigh); + } + else + { + SplashKit.RaspiWrite(ledPin, GpioPinValue.GpioLow); + } + } + } + + SplashKit.CloseAllWindows(); + SplashKit.RaspiCleanup(); + } + } + } + ``` + + + + + + + + + +### Build and run the code + +We can build this program with the following command: + + + + + ```shell + g++ button_press.cpp -l SplashKit -o button_press + ``` + + + + + ```shell + dotnet build + ``` + + + + +We can then run the program with the following command: + + + + + ```shell + ./button_press + ``` + + + + + ```shell + dotnet run + ``` + + + + +![GIF of the button press circuit in action.](/gifs/guides/gpio-tutorial-gifs/push_button.gif) + +## Further Information + +### Floating Pins + +A 'floating' pin is one that is not actively driven high (connected to some kind of power) or driven low (connected to ground). When this is the case the pin is said to be 'floating' as the state of the pin can change due to electrical noise or interference. If we were to read the pin in this state, then the value returned would be randomly either [`GPIO_HIGH`](/api/types/#gpio-pin-value) or [`GPIO_LOW`](/api/types/#gpio-pin-value) + +In this tutorial we've used an internal pull-down resistor to prevent this. A pull-down resistor connects the pin to ground which effectively neutralises the electrical interference. Doing this ensures the pin only reads[`GPIO_LOW`](/api/types/#gpio-pin-value) until the button is actually pressed and the pin is powered. + +### Debouncing + +The button that is used in this tutorial works by physically moving a strip of metal against another strip of metal to complete a circuit. When you press or release the button, these electrical contacts can physically bounce and create multiple on-off signals. This phenomenon is known as 'debouncing' and can be remedied through hardware and software solutions. One basic way to address this in software is create a non-blocking delay when reading the input (in this case the button). To do this we record the time when we last read the input and take it away from the current time in the loop. We then only read the button when this result is greater than some interval we've set. diff --git a/src/content/docs/guides/raspberry-gpio/2-pwm-control-led.mdx b/src/content/docs/guides/raspberry-gpio/2-pwm-control-led.mdx new file mode 100644 index 000000000..1680cd5ef --- /dev/null +++ b/src/content/docs/guides/raspberry-gpio/2-pwm-control-led.mdx @@ -0,0 +1,589 @@ +--- +title: Using PWM to control LED brightness +description: Pulse Width Modulation is a technique in which we emulate analog signals in digital pins. This tutorial we explore how to use PWM parameters to modify the operation of an LED. + +author: Jonathan Tynan +lastupdated: May 11 2025 +tableOfContents: + minHeadingLevel: 2 + maxHeadingLevel: 4 +--- + +import { Tabs, TabItem, Steps } from "@astrojs/starlight/components"; + +**{frontmatter.description}** +Written by: {frontmatter.author} +_Last updated: {frontmatter.lastupdated}_ + +--- + +Pulse Width Modulation (PWM) is a technique for emulating analog signals when using a digital signal source - like the pins we've been using. It does this by rapidly turning the digital pins on and off, effectively controlling the amount of power sent to a device. This method is widely used for controlling lights, motors and other devices. When using PWM we have several parameters we can control and modify: the PWM duty cycle, the PWM frequency and the PWM range. + +### PWM Frequency + +PWM operates through cycles, which are set by the frequency. The frequency of PWM indicates how many times per second the PWM signal completes one on-and-off cycle. A higher frequency means the individual cycles are completed more rapidly, which can help in smoothing the output in devices like LED's and motors. It is measured in Hertz (Hz) and as it increases, this rapid switching becomes less and less perceptible to human senses. At low frequencies this switching is noticeable and this is seen later in this tutorial. + +### PWM Duty Cycle + +In each of these cycles, the pin is powered high for a some part of the cycle and unpowered for the other part. We define this through the duty cycle, and this allows for fine control over the amount of power delivered to a device. In this tutorial it is shown that increasing the duty cycle of a PWM signal sent to an LED makes it appear brighter as the LED is on for more of the cycle. This value is often expressed as a percentage, for example a 50% duty cycle means that the signal is on for half of the cycle, and off for the other half. + +### PWM Range + +The range of the PWM refers to the resolution we can achieve when adjusting the duty cycle. For example, a range of 255 means that the duty cycle can be adjusted in 256 increments so that the pin could be always off (0%) or always on (100%). A larger range allows for more precise control of the output device and we explore this further in the next tutorial. + +## Components + +### Breadboard + +Breadboards are reusable devices used to build and test circuits. They are made up of a number of +holes that are connected by hidden metal strips. Along the top and bottoms are the ground and power +rails, and in the middle there are two sections separated by a channel. Each hole in a section is +connected to the adjacent vertical holes. More information can be found at +[How to Use a Breadboard](https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/all). + +### LED + +An LED (Light Emitting Diode) is a device that emits light when an electric current passes through +it. They feature two legs, a longer positive leg (the [anode](https://en.wikipedia.org/wiki/Anode)) +and a shorter negative leg (the [cathode](https://en.wikipedia.org/wiki/Cathode)). The longer leg is +often kinked so that both legs protrude the same distance from the LED. To use it we connect the positive +lead to the GPIO pin and the negative lead to a ground pin. More information can be found at +[Light-Emitting Diodes (LEDs)](https://learn.sparkfun.com/tutorials/light-emitting-diodes-leds/all) + +### 220 Ω Resistor + +The power that the Raspberry Pi can provide is actually too much for these LEDs. To prevent the LED +from burning out, we must add a resistor to the circuit. The resistor limits the current that +flows through the LED, preventing it from burning out. The exact value of the resistor is not +critical, but too high a value does not allow enough illumination of the LED. A resistor in the +range of 220 Ω to 1 kΩ should work well. More information on resistors can be found at +[Sparkfun - Resistors](https://learn.sparkfun.com/tutorials/resistors/all) + +:::tip[Resistor Colour Code] +The colours on a resistor indicate the resistance value. Each coloured band corresponds to specific +numbers and multipliers which can be used to calculate the resistance value. More information +can be found at [Electronic Colour Code](https://en.wikipedia.org/wiki/Electronic_color_code) +::: + +### Jumper Wires + +Jumper Wires, or DuPont wires, are used to make a temporary connection different components. They +can be M/M, M/F, or F/F. We are using M/F jumper wires in this guide. + +## The Circuit + +Below we can see the circuit diagram for this project. Just like the blink-LED tutorial, we have the cathode of the LED connected to +GPIO Pin 11, while the anode is connected to ground pin 6 through a resistor. + +![Circuit Diagram for Blinking an LED](./images/circuits/blinkled.png) + +And the physical circuit looks like the following image, in which we've connected an M/F jumper wire +from Pin 11 to the cathode of the LED. The anode of the LED is connected to the resistor, which is +then connected to the ground pin through another M/F jumper wire. + +![Photograph of a circuit to blink an LED](./images/circuits/blink_led_circuit.jpg) + +## The Code + +:::caution[Before running the code:] +This code requires the `pigpio` daemon, so make sure it is running! For more information see: [Starting the Daemon](/guides/raspberry-gpio/0-blink-led/#starting-the-daemon) +::: + +### Changing Frequency + +Below is an example program to iterate over the entire range of frequencies available. + + + + +```cpp +#include "splashkit.h" + +int main() +{ + const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, + 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; + const int pwm_range = 255; + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_range(led_pin, pwm_range); + raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); + + for(int i = 0; i < 18; i++) + { + write("At Frequency: "); + write_line(freqs[i]); + raspi_set_pwm_frequency(led_pin, freqs[i]); + delay(1000); + } + + raspi_cleanup(); + return 0; +} +``` + + + + +#### Understanding the code \{#understanding-the-code-changing-frequency\} + +Lets break down this code and look at it in sections. + + + +1. **Initialise GPIO Hardware and values:** + + When using `pigpiod`, we can actually set the sample rate for the daemon, which is a value determining how many times it can read a pin in a second. Each sample rate has a set of available frequencies, with the values defined in freqs array being the available frequencies for the default sample rate (more information can be found at [Pigpio library -`set_PWM_frequency`](https://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_frequency)). + + So, we define these values in an array and as a constant as these we don't want them changing during the running of the program. We then define a standard range for our PWM, also as a constant, and then we do the usual initialisation of the Raspberry Pi Pins. + + + + + ```cpp {5-10} + #include "splashkit.h" + + int main() + { + const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, + 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; + const int pwm_range = 255; + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_range(led_pin, pwm_range); + raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); + + for(int i = 0; i < 18; i++) + { + write("At Frequency: "); + write_line(freqs[i]); + raspi_set_pwm_frequency(led_pin, freqs[i]); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + +2. **Set PWM Range and Duty Cycle:** + + In this section we set the PWM range and duty cycles that we are using. We are setting the duty cycle to be half the PWM range, or in other words we're setting it to 50%. We are not changing these values so we can specifically see the effects of changing frequency. + + + + + ```cpp {12-13} + #include "splashkit.h" + + int main() + { + const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, + 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; + const int pwm_range = 255; + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_range(led_pin, pwm_range); + raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); + + for(int i = 0; i < 18; i++) + { + write("At Frequency: "); + write_line(freqs[i]); + raspi_set_pwm_frequency(led_pin, freqs[i]); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + +3. **Change the PWM Frequency:** + + This part is the main component of the code. We iterate over the previously defined frequencies and write where we're at to the terminal. We then set the PWM to the particular frequency and wait for one second. This delay allows us to see the changes in the LED as the frequency increases. At the beginning there is a noticeable flicker, before the flickering stabilises to full illumination as the frequency increases. + + + + + ```cpp {15-21} + #include "splashkit.h" + + int main() + { + const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, + 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; + const int pwm_range = 255; + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_range(led_pin, pwm_range); + raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); + + for(int i = 0; i < 18; i++) + { + write("At Frequency: "); + write_line(freqs[i]); + raspi_set_pwm_frequency(led_pin, freqs[i]); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + + :::note[Flicking at low frequencies] + When running this program, you may be able to see a noticeable flicker when the frequency is at a low value but it quickly stabilises as it increases. + + This happens due to the way our eyes perceive light, specifically the [Persistence of Vision](https://en.wikipedia.org/wiki/Persistence_of_vision). If the frequency is faster than the time that images remain in our vision, then we do not notice the times when the LED is unlit. + ::: + +4. **Clean Up Memory:** + + Finally we clean up and exit the program. + + + + + ```cpp {23} + #include "splashkit.h" + + int main() + { + const int freqs[] = {10, 20, 40, 50, 80, 100, 160, 200, 250, + 320, 400, 500, 800, 1000, 1600, 2000, 4000, 8000 }; + const int pwm_range = 255; + raspi_init(); + gpio_pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_range(led_pin, pwm_range); + raspi_set_pwm_dutycycle(led_pin, (pwm_range / 2)); + + for(int i = 0; i < 18; i++) + { + write("At Frequency: "); + write_line(freqs[i]); + raspi_set_pwm_frequency(led_pin, freqs[i]); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + + + +#### Build and run the code \{#build-and-run-the-code-changing-frequency\} + +We can build this program with the following command: + + + + + ```shell + g++ pwm_frequency.cpp -l SplashKit -o pwm_frequency + ``` + + + + + +We can then run the program with the following command: + + + + + ```shell + ./pwm_frequency + ``` + + + + +### Changing Duty Cycle + +Below is an example program, very similar to the previous program, that demonstrates what the effect of modifying the duty cycle does to the LED. + + + + +```cpp +#include "splashkit.h" + +int main() +{ + const int pwm_range = 255; + + raspi_init(); + pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_frequency(led_pin, 1000); + raspi_set_pwm_range(led_pin, pwm_range); + + for(int i = 0; i <= pwm_range; i += 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + for(int i = pwm_range; i >= 0; i -= 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + + raspi_cleanup(); + return 0; +} +``` + + + + +#### Understanding the code \{#understanding-the-code-changing-duty-cycle\} + +Lets break down this code and look at the sections that are different. + + + +1. **Initialise GPIO Hardware and values:** + + Like before we set our PWM range to a constant value. We are using **255** as a general default, but it is important to know that the real range of PWM is dependant on the frequency that we set. More information can be found at [Pigpio library - `set_pwm_range`](https://abyz.me.uk/rpi/pigpio/pdif2.html#set_PWM_range). + + + + + ```cpp {5,7-9} + #include "splashkit.h" + + int main() + { + const int pwm_range = 255; + + raspi_init(); + pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_frequency(led_pin, 1000); + raspi_set_pwm_range(led_pin, pwm_range); + + for(int i = 0; i <= pwm_range; i += 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + for(int i = pwm_range; i >= 0; i -= 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + +2. **Set PWM Range and Duty Cycle:** + + When we set our frequency, we're are using 1000Hz (which cycles at 1000 times per second). We then set our predefined PWM range, and if we refer back to the Pigpiod library we can see that a frequency of 1000 is the 14th available frequency at the default sample rate. This means that at this frequency we really have a range of 2500 and so our PWM range of 255 is valid. + + + + + ```cpp {11-12} + #include "splashkit.h" + + int main() + { + const int pwm_range = 255; + + raspi_init(); + pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_frequency(led_pin, 1000); + raspi_set_pwm_range(led_pin, pwm_range); + + for(int i = 0; i <= pwm_range; i += 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + for(int i = pwm_range; i >= 0; i -= 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + +3. **Change the PWM Duty Cycle:** + + In this section we have the main functionality of this program. We iterate over the range that we've set in increments of 10, and at each step we print out the duty cycle we're currently on. We then set the duty cycle to this value and wait for a second so we can see the changes. We then reverse the loop and iterate back down to zero. + + + + + ```cpp {14-27} + #include "splashkit.h" + + int main() + { + const int pwm_range = 255; + + raspi_init(); + pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_frequency(led_pin, 1000); + raspi_set_pwm_range(led_pin, pwm_range); + + for(int i = 0; i <= pwm_range; i += 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + for(int i = pwm_range; i >= 0; i -= 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + +4. **Clean Up Memory:** + + Like usual, we clean up and exit the program. + + + + + ```cpp {29} + #include "splashkit.h" + + int main() + { + const int pwm_range = 255; + + raspi_init(); + pin led_pin = PIN_11; + raspi_set_mode(led_pin, GPIO_OUTPUT); + + raspi_set_pwm_frequency(led_pin, 1000); + raspi_set_pwm_range(led_pin, pwm_range); + + for(int i = 0; i <= pwm_range; i += 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + for(int i = pwm_range; i >= 0; i -= 10) + { + write("At Duty Cycle: "); + write_line(i); + raspi_set_pwm_dutycycle(led_pin, i); + delay(1000); + } + + raspi_cleanup(); + return 0; + } + ``` + + + + + + +#### Build and run the code \{#build-and-run-the-code-changing-duty-cycle\} + +We can build this program with the following command: + + + + +```shell +g++ pwm_dutycycle.cpp -l SplashKit -o pwm_dutycycle +``` + + + + +We can then run the program with the following command: + + + + +```shell +./pwm_dutycycle +``` + + + + +:::note[LED Brightness:] +Changing the duty cycle results in a noticeable change in the brightness of the LED. This occurs due to there being literally more or less power flowing through the device, resulting in the increase or decrease in brightness, as shown below: + +!["GIF of LED duty cycle changes."](/gifs/guides/gpio-tutorial-gifs/pwm_led.gif) +::: + +## Further Information + +### Changing PWM Range + +As previously mentioned, when we increase the PWM range we increase the number of steps between the pin being always off and always on. We could change the range in the previous program and observe finer and more subtle adjustments occurring to the LED as the duty cycle increases. But this may be difficult to see when using a regular LED. A more effective demonstration of the capabilities of PWM would be through the use of an RGB LED, which can interpret analog-like signals achieved through PWM to mix red, green, and blue light in varying intensities. This allows for the creation of a wider spectrum of colours by adjusting the PWM range for each of the LED's colour components. diff --git a/src/content/docs/guides/raspberry-gpio/3-pwm-button-control.mdx b/src/content/docs/guides/raspberry-gpio/3-pwm-button-control.mdx new file mode 100644 index 000000000..f0d720d47 --- /dev/null +++ b/src/content/docs/guides/raspberry-gpio/3-pwm-button-control.mdx @@ -0,0 +1,568 @@ +--- +title: Modify PWM through button presses +description: Learn to control LED brightness using Pulse Width Modulation (PWM) by button presses on a Raspberry Pi + +author: Jonathan Tynan +lastupdated: May 11 2025 +--- + +import { Tabs, TabItem, Steps } from "@astrojs/starlight/components"; + +**{frontmatter.description}** +Written by: {frontmatter.author} +_Last updated: {frontmatter.lastupdated}_ + +--- + +In this tutorial, we bring all the previous lessons together. We are reading button presses and will use these readings to modify the brightness of an LED by changing the PWM duty cycle. This tutorial brings together digital pin reading, writing and PWM modification. This is a simple demonstration of how to integrate various physical components and get them working with each other. + +## Components + +See [Blink LED Tutorial](/guides/raspberry-gpio/0-blink-led/#components) for more details on these components. + +- Breadboard +- LED +- 220 Ω Resistor +- Jumper Wires + +See [Read Button Press Tutorial](/guides/raspberry-gpio/1-read-button-press/#components) for more details on these components: + +- 2 Push Buttons + +## The Circuit + +Below we can see the circuit diagram for this project. First we have the Raspberry Pi ground connected to the ground rail of the breadboard and a 3.3V pin connected to the power rail of the bread board. We then have an LED which is connected to the ground rail and to Pin 11 through a 220 Ω resistor. Next we have 2 buttons, where both are connected to the powered rail on the breadboard and the otherside of the buttons are connected to pins 13 and 29. + +![Circuit Diagram for using button presses to modify PWM.](./images/circuits/pwm_buttons.png) + +![Photograph of a circuit for using button presses to modify PWM.](./images/circuits/pwm_buttons_circuit.png) + +## The Code + +:::caution[Before running the code.] +This code requires the `pigpio` daemon, so make sure it is running! For more information see: [Starting the Daemon](/guides/raspberry-gpio/0-blink-led/#starting-the-daemon) +::: + +Below is an example program that will detect button presses to increase or decrease the brightness of an LED. + + + + +```cpp +#include "splashkit.h" + +int main() +{ + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; +} +``` + + + + +### Understanding the code + +Okay, now lets break down this code and look at its sections. + + + +1. **Initialise Values:** + + Firtly, we set up the variables that we're going to need: `brightness` is given an inital value of 128 which is 50% of our maximum, 255. `last_read_time` is set to 0 and `read_interval` is set to 400. + + We are using this to implement a simple debounce technique, in which we wait a short period of time (the interval), in a non-blocking manner, to make sure the pushbutton is definitely pressed. + + + + + ```cpp {5-8} + #include "splashkit.h" + + int main() + { + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; + } + ``` + + + + +2. **Initialise Hardware:** + + Now we do our GPIO setup, where we call `raspi_init` and define the pins we are using. + + + + + ```cpp {10-13} + #include "splashkit.h" + + int main() + { + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; + } + ``` + + + + +3. **Set PWM Range, Duty Cycle and GPIO Pins:** + + Next, we setup our individual pins. We're going to write to the `led_pin` so we're setting that to output, and then we're setting its dutycycle to our initial brightness setting. Then we set our buttons to be inputs and set the pull-down resistors on them so that they are no longer floating and we can be sure they read `LOW` when not pressed. + + + + + ```cpp {15-22} + #include "splashkit.h" + + int main() + { + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; + } + ``` + + + + +4. **Get User Inputs (with debouncing):** + + So we can debounce our buttons we'll create timers and a variable to hold the current time. Like in previous tutorials, we define how our program is going to end to ensure cleanup. In this case we are opening up our dummy window and watching for any key presses. + + + + + ```cpp {24-26,28-31,52} + #include "splashkit.h" + + int main() + { + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; + } + ``` + + + + +5. **Change LED Brightness:** + + Below is the main section of this code. At the start of every loop we are getting the current time from `timer_ticks`. We are then checking if more time has elapsed since the last button read than the interval that we set earlier. + + If this is the case, then it's time to check the buttons. We then read both buttons and if they're high then we'll either increase or decrease the brightness appropriately, set the duty cycle to this new brightness and record the last read time as the current time. + + + + + ```cpp {32-51} + #include "splashkit.h" + + int main() + { + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; + } + ``` + + + + +6. **Clean Up Memory:** + + As usual, once our program has run, we cleanup all our resources and safely exit the program. + + + + + ```cpp {54-57} + #include "splashkit.h" + + int main() + { + int brightness = 128; + const int max_brightness = 255; + unsigned long last_read_time = 0; + const unsigned long read_interval = 400; + + raspi_init(); + gpio_pin led_pin = PIN_11; + gpio_pin increase_btn_pin = PIN_13; + gpio_pin decrease_btn_pin = PIN_29; + + raspi_set_mode(led_pin, GPIO_OUTPUT); + raspi_set_pwm_dutycycle(led_pin, brightness); + + raspi_set_mode(increase_btn_pin, GPIO_INPUT); + raspi_set_mode(decrease_btn_pin, GPIO_INPUT); + + raspi_set_pull_up_down(increase_btn_pin, PUD_DOWN); + raspi_set_pull_up_down(decrease_btn_pin, PUD_DOWN); + + timer run_timer = create_timer("run_timer"); + start_timer(run_timer); + unsigned long current_time = 0; + + open_window("dummy_window", 1, 1); + while(!any_key_pressed()) + { + process_events(); + current_time = timer_ticks(run_timer); + if(current_time - last_read_time > read_interval) + { + if(raspi_read(increase_btn_pin) == GPIO_HIGH) + { + brightness += 25; + if(brightness > max_brightness) + brightness = max_brightness; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + if(raspi_read(decrease_btn_pin) == GPIO_HIGH) + { + brightness -= 25; + if(brightness < 0) + brightness = 0; + raspi_set_pwm_dutycycle(led_pin, brightness); + last_read_time = current_time; + } + } + } + + close_all_windows(); + stop_timer(run_timer); + free_all_timers(); + raspi_cleanup(); + return 0; + } + ``` + + + + + + +If we run this we should see an output like the following GIF. + +![A GIF of the LED increasing then decreasing in brightness.](/gifs/guides/gpio-tutorial-gifs/pwm_button.gif) + +## Further Information + +### Modifying PWM Range + +As described in the previous tutorial, we can change the range of possible PWM values and have finer control over the brightness of the LED. In this tutorial, we use the typical PWM range of 0-255, but we could expand this to a higher resolution, like 1023, for more precise control of the exact brightness levels. Experiment with adjustments to the PWM range, modifying the parameters in your code, and observe how these changes affect the LED's response to button presses. Each step increase in the PWM range will allow for more nuanced adjustments and provide smoother transitions between light levels. Conversely, a decrease in the PWM range will limit these transitions, and make each button press cause a more noticeable change in brightness. diff --git a/src/content/docs/guides/Raspberry-GPIO/4-analog-signals.mdx b/src/content/docs/guides/raspberry-gpio/4-analog-signals.mdx similarity index 99% rename from src/content/docs/guides/Raspberry-GPIO/4-analog-signals.mdx rename to src/content/docs/guides/raspberry-gpio/4-analog-signals.mdx index 65a17f170..e83f924fb 100644 --- a/src/content/docs/guides/Raspberry-GPIO/4-analog-signals.mdx +++ b/src/content/docs/guides/raspberry-gpio/4-analog-signals.mdx @@ -1,7 +1,6 @@ --- title: Reading Analog Signal description: Learn to read analog signals with an Analog-to-Digital converter to connect a joystick to the Raspberry Pi -category: Guides author: Jonathan Tynan lastupdated: Apr 27 2024 sidebar: diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/blink_led_circuit.jpg b/src/content/docs/guides/raspberry-gpio/images/circuits/blink_led_circuit.jpg similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/blink_led_circuit.jpg rename to src/content/docs/guides/raspberry-gpio/images/circuits/blink_led_circuit.jpg diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/blinkled.png b/src/content/docs/guides/raspberry-gpio/images/circuits/blinkled.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/blinkled.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/blinkled.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/buttonpush.png b/src/content/docs/guides/raspberry-gpio/images/circuits/buttonpush.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/buttonpush.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/buttonpush.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/joystick.png b/src/content/docs/guides/raspberry-gpio/images/circuits/joystick.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/joystick.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/joystick.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/joystick_circuit.png b/src/content/docs/guides/raspberry-gpio/images/circuits/joystick_circuit.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/joystick_circuit.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/joystick_circuit.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/push_button_circuit.png b/src/content/docs/guides/raspberry-gpio/images/circuits/push_button_circuit.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/push_button_circuit.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/push_button_circuit.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/pwm_buttons.png b/src/content/docs/guides/raspberry-gpio/images/circuits/pwm_buttons.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/pwm_buttons.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/pwm_buttons.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/circuits/pwm_buttons_circuit.png b/src/content/docs/guides/raspberry-gpio/images/circuits/pwm_buttons_circuit.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/circuits/pwm_buttons_circuit.png rename to src/content/docs/guides/raspberry-gpio/images/circuits/pwm_buttons_circuit.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/ctrl-bit_table.png b/src/content/docs/guides/raspberry-gpio/images/ctrl-bit_table.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/ctrl-bit_table.png rename to src/content/docs/guides/raspberry-gpio/images/ctrl-bit_table.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/joystick_pinout.png b/src/content/docs/guides/raspberry-gpio/images/joystick_pinout.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/joystick_pinout.png rename to src/content/docs/guides/raspberry-gpio/images/joystick_pinout.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/mcp3008_pinout.png b/src/content/docs/guides/raspberry-gpio/images/mcp3008_pinout.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/mcp3008_pinout.png rename to src/content/docs/guides/raspberry-gpio/images/mcp3008_pinout.png diff --git a/src/content/docs/guides/Raspberry-GPIO/images/transmit_details.png b/src/content/docs/guides/raspberry-gpio/images/transmit_details.png similarity index 100% rename from src/content/docs/guides/Raspberry-GPIO/images/transmit_details.png rename to src/content/docs/guides/raspberry-gpio/images/transmit_details.png diff --git a/src/content/docs/guides/Resource-Bundles/images/output.png b/src/content/docs/guides/resources/images/output.png similarity index 100% rename from src/content/docs/guides/Resource-Bundles/images/output.png rename to src/content/docs/guides/resources/images/output.png diff --git a/src/content/docs/guides/Resource-Bundles/0-loading-resources-with-bundles.mdx b/src/content/docs/guides/resources/loading-resources-with-bundles.mdx similarity index 97% rename from src/content/docs/guides/Resource-Bundles/0-loading-resources-with-bundles.mdx rename to src/content/docs/guides/resources/loading-resources-with-bundles.mdx index 7782ea15b..c87d71920 100644 --- a/src/content/docs/guides/Resource-Bundles/0-loading-resources-with-bundles.mdx +++ b/src/content/docs/guides/resources/loading-resources-with-bundles.mdx @@ -1,7 +1,6 @@ --- title: Loading Resources with Bundles description: Simplify the process of loading your program's resources using a resource bundle. This file lists the different resources you want loaded, which can then be loaded and freed as a group. -category: Guides author: Various Authors lastupdated: November 2024 --- @@ -53,7 +52,7 @@ Bitmap and font resources also require additional information. **BITMAP** can optionally be followed by bitmap cell details useful for animations. This is in the format: `BITMAP, name, filename, width, height, cellCols, cellRows, cellCount`. Once the bitmap is loaded the bundle will set the cell details from the information given. -See [Using Animations](/guides/animations/0-using-animations) guide for more details, and example code and files to test. +See [Using Animations](/guides/animations/using-animations) guide for more details, and example code and files to test. **FONT** must be followed by the point size for the font. diff --git a/src/content/docs/guides/Utilities/0-useful-utilities.mdx b/src/content/docs/guides/utilities/useful-utilities.mdx similarity index 86% rename from src/content/docs/guides/Utilities/0-useful-utilities.mdx rename to src/content/docs/guides/utilities/useful-utilities.mdx index c80acdf2e..fd64df1b8 100644 --- a/src/content/docs/guides/Utilities/0-useful-utilities.mdx +++ b/src/content/docs/guides/utilities/useful-utilities.mdx @@ -1,7 +1,6 @@ --- title: Useful Utilities description: In this article, we discuss useful utilities that you can use to convert, check and manipulate common data types in SplashKit programs. -category: Guides author: Richard Denton and others lastupdated: October 2024 --- @@ -14,7 +13,7 @@ _Last updated: {frontmatter.lastupdated}_ --- -SplashKit's [Utilities library](/api/utilities) provides a range of useful functions that can assist you with converting, checking, and manipulating common data types in your SplashKit program. +SplashKit's [Utilities](/api/utilities) library provides a range of useful functions that can assist you with converting, checking, and manipulating common data types in your SplashKit program. These functions are useful in many areas of programming. @@ -24,6 +23,114 @@ These functions are useful in many areas of programming. - [Usage scenario: accept user input as a number](#usage-scenario-accept-user-input-as-a-number) - [Manipulating strings](#manipulating-strings) +--- + +Before getting started with these utilities functions, it is important to be able to get inputs from the user using the command line (terminal). + +## Reading Text from the Command Line + +Reading text input from the user is straightforward for terminal-based applications. + +In this context, [Read Line](/api/terminal/#read-line) allows you to read a line of text entered at the Terminal. This is a **blocking** function call, meaning it waits for the user to input the line before it returns. For command line applications, this is fine; you want it to wait for the input. + +The following code demonstrates the use of [Read Line](/api/terminal/#read-line) in order to read in and display the user's name. + + + + +```cpp +#include "splashkit.h" + +int main() +{ + string name; // declare a variable to store the name + string quest; // and another to store a quest + + write("What is your name: "); // prompt the user for input + name = read_line(); // read user input + + // read in another value + write("And what is your quest? "); + quest = read_line(); + + write_line(name + "'s quest is: " + quest); // output quest to the terminal + + return 0; +} +``` + + + + + + + +```csharp +using static SplashKitSDK.SplashKit; + +string name; // declare a variable to store the name +string quest; // and another to store a quest + +Write("What is your name: "); // prompt the user for input +name = ReadLine(); // read user input + +// Read in another value +Write("And what is your quest? "); +quest = ReadLine(); + +WriteLine(name + "'s quest is: " + quest); // output quest to the terminal +``` + + + + +```csharp +using SplashKitSDK; + +namespace ReadingText +{ + public class Program + { + public static void Main() + { + string name; // declare a variable to store the name + string quest; // and another to store a quest + + SplashKit.Write("What is your name: "); // prompt the user for input + name = SplashKit.ReadLine(); // read user input + + // Read in another value + SplashKit.Write("And what is your quest? "); + quest = SplashKit.ReadLine(); + + SplashKit.WriteLine(name + "'s quest is: " + quest); // output quest to the terminal + } + } +} +``` + + + + + + + +```python +from splashkit import * + +write("What is your name: ") # prompt the user for input +name = read_line() # read user input and store in a variable + +# Read in another value +write("And what is your quest? ") +quest = read_line() + +write_line(name + "'s quest is: " + quest) +``` + + + + ## Converting a string to a number SplashKit provides two useful functions for handling the conversion of a `string` to either an `int` or a `double`. @@ -135,7 +242,7 @@ write_line_double(pi) -### Usage scenario: converting user input to an integer +### Usage scenario: Converting user input to an integer Consider you want to write a program that accepts two numbers as input from a user, multiplies them, and outputs the result. One way to accomplish this is to use SplashKit's [Convert To Integer](/api/utilities/#convert-to-integer) function. diff --git a/src/content/docs/index.mdx b/src/content/docs/index.mdx index c6aae2879..885102e55 100644 --- a/src/content/docs/index.mdx +++ b/src/content/docs/index.mdx @@ -25,6 +25,7 @@ hero: import { Card, LinkCard, CardGrid } from "@astrojs/starlight/components"; +import PopularTutorials from "../../components/PopularTutorials.astro"; #### To install SplashKit, copy and paste the following into your terminal @@ -34,6 +35,8 @@ bash <(curl -s https://raw.githubusercontent.com/splashkit/skm/master/install-sc
See the [Installation Guides](/installation/) for more details.
+ + ## Features diff --git a/src/content/docs/installation/Linux/4-vscode.mdx b/src/content/docs/installation/Linux/4-vscode.mdx index 8f8bdeb12..1b440d4c2 100644 --- a/src/content/docs/installation/Linux/4-vscode.mdx +++ b/src/content/docs/installation/Linux/4-vscode.mdx @@ -129,34 +129,32 @@ If you are using code OSS you won't be able to install extensions via the comman ### C# Extensions - + You can install these C# extensions directly from the terminal by running: ```shell code --install-extension ms-dotnettools.csharp code --install-extension ms-dotnettools.csdevkit -code --install-extension ms-dotnettools.vscodeintellicode-csharp ``` - + To add these extensions within Visual Studio Code: 1. Open the Extensions view by pressing `Ctrl+Shift+X`. -2. Search for "C# Microsoft" and the top 3 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. +2. Search for "C#" and the top 2 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. ![Adding C# extensions in Visual Studio Code](/images/installation/csharp-in-vscode.png) - + Install the following C# extensions directly from the Visual Studio Marketplace: C# C# Dev Kit -Intellicode for C# Dev Kit @@ -164,7 +162,7 @@ Install the following C# extensions directly from the Visual Studio Marketplace: ### C++ Extensions - + To install the C++ Extension Pack directly from the terminal: @@ -173,7 +171,7 @@ code --install-extension ms-vscode.cpptools-extension-pack ``` - + To add the C++ extension within Visual Studio Code: @@ -183,7 +181,7 @@ To add the C++ extension within Visual Studio Code: ![Adding C++ extensions in Visual Studio Code](/images/installation/cplus-in-vscode.png) - + Install the C++ Extension Pack for comprehensive C++ support: @@ -195,30 +193,30 @@ Install the C++ Extension Pack for comprehensive C++ support: ### Python Extensions - + -To install the Python Extension Pack directly from the terminal: +To install the Python extension directly from the terminal: ```shell -code --install-extension donjayamanne.python-extension-pack +code --install-extension ms-python.python ``` - + -To install the Python Extension Pack within Visual Studio Code: +To install the Python extension within Visual Studio Code: 1. Open the Extensions view (`Ctrl+Shift+X`). -2. Search for "Python Extension Pack" and click **Install**. +2. Search for "Python" and click **Install**. ![Adding Python extensions in Visual Studio Code](/images/installation/python-in-vscode.png) - + -For Python support, install the Python Extension Pack from the Visual Studio Marketplace: +For Python support, install the Python extension from the Visual Studio Marketplace: -Python Extension Pack +Python @@ -231,6 +229,6 @@ Congratulations! You've completed the setup of everything you need to get starte You can find more information about compiling and running SplashKit programs in the link below: -Using SplashKit +Using SplashKit ::: diff --git a/src/content/docs/installation/Linux/index.mdx b/src/content/docs/installation/Linux/index.mdx index d8cd92486..ba563a4fa 100644 --- a/src/content/docs/installation/Linux/index.mdx +++ b/src/content/docs/installation/Linux/index.mdx @@ -10,6 +10,17 @@ sidebar: import { LinkCard, CardGrid } from "@astrojs/starlight/components"; +:::tip[Using the Programmer's Field Guide?] + +If you are using the Field Guide, we *strongly recommend* that you follow its installation guide: + +- [Set up my Linux Box](https://programmers.guide/book/appendix/0-installation/2-0-setup-linux/) +- [Set up my Raspberry Pi](https://programmers.guide/book/appendix/0-installation/2-3-setup-pi/#3-setup-raspberry-pi-os) (if using a Raspberry Pi) + +These guides also include an automated script for an easier installation option. + +::: + To get SplashKit installed on Linux, follow the four steps: diff --git a/src/content/docs/installation/MacOS/4-vscode.mdx b/src/content/docs/installation/MacOS/4-vscode.mdx index eb2a1da80..54cdcde13 100644 --- a/src/content/docs/installation/MacOS/4-vscode.mdx +++ b/src/content/docs/installation/MacOS/4-vscode.mdx @@ -24,34 +24,32 @@ After setting up Visual Studio Code, enhance your development environment by add ### C# Extensions - + You can install these C# extensions directly from the terminal by running: ```shell code --install-extension ms-dotnettools.csharp code --install-extension ms-dotnettools.csdevkit -code --install-extension ms-dotnettools.vscodeintellicode-csharp ``` - + To add these extensions within Visual Studio Code: 1. Open the Extensions view by pressing `Command+Shift+X`. -2. Search for "C# Microsoft" and the top 3 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. +2. Search for "C#" and the top 2 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. ![Adding C# extensions in Visual Studio Code](/images/installation/csharp-in-vscode.png) - + Install the following C# extensions directly from the Visual Studio Marketplace: C# C# Dev Kit -Intellicode for C# Dev Kit @@ -59,7 +57,7 @@ Install the following C# extensions directly from the Visual Studio Marketplace: ### C++ Extensions - + To install the C++ Extension Pack directly from the terminal: @@ -68,7 +66,7 @@ code --install-extension ms-vscode.cpptools-extension-pack ``` - + To add the C++ extension within Visual Studio Code: @@ -78,7 +76,7 @@ To add the C++ extension within Visual Studio Code: ![Adding C++ extensions in Visual Studio Code](/images/installation/cplus-in-vscode.png) - + Install the C++ Extension Pack for comprehensive C++ support: @@ -90,30 +88,30 @@ Install the C++ Extension Pack for comprehensive C++ support: ### Python Extensions - + -To install the Python Extension Pack directly from the terminal: +To install the Python extension directly from the terminal: ```shell -code --install-extension donjayamanne.python-extension-pack +code --install-extension ms-python.python ``` - + -To install the Python Extension Pack within Visual Studio Code: +To install the Python extension within Visual Studio Code: 1. Open the Extensions view (`Command+Shift+X`). -2. Search for "Python Extension Pack" and click **Install**. +2. Search for "Python" and click **Install**. ![Adding Python extensions in Visual Studio Code](/images/installation/python-in-vscode.png) - + -For Python support, install the Python Extension Pack from the Visual Studio Marketplace: +For Python support, install the Python extension from the Visual Studio Marketplace: -Python Extension Pack +Python @@ -126,6 +124,6 @@ Congratulations! You've completed the setup of everything you need to get starte You can find more information about compiling and running SplashKit programs in the link below: -Using SplashKit +Using SplashKit ::: diff --git a/src/content/docs/installation/MacOS/index.mdx b/src/content/docs/installation/MacOS/index.mdx index 8b9318efc..d86bed1e8 100644 --- a/src/content/docs/installation/MacOS/index.mdx +++ b/src/content/docs/installation/MacOS/index.mdx @@ -9,6 +9,14 @@ sidebar: import { LinkCard, CardGrid } from "@astrojs/starlight/components"; +:::tip[Using the Programmer's Field Guide?] + +If you are using the Field Guide, we *strongly recommend* that you follow its installation guide: + +- [Set up my macOS](https://programmers.guide/book/appendix/0-installation/2-1-setup-macos/) + +::: + To get SplashKit installed on macOS, follow the four steps: diff --git a/src/content/docs/installation/Windows (MSYS2)/1-command-line-tools.mdx b/src/content/docs/installation/Windows (MSYS2)/1-command-line-tools.mdx index 6d6128898..512531a3f 100644 --- a/src/content/docs/installation/Windows (MSYS2)/1-command-line-tools.mdx +++ b/src/content/docs/installation/Windows (MSYS2)/1-command-line-tools.mdx @@ -23,7 +23,13 @@ MSYS2 provides a Unix-like terminal environment for Windows, allowing you to run Double-click the downloaded executable file and follow the on-screen instructions to complete the installation. - *We recommend using the default installation path, though you may customize other options as needed.* + :::caution[Use the default install path] + + Make sure to use the default install path: `C:\msys64` + + *Using other paths may cause issues.* + + ::: 3. **Open the MINGW64 Terminal** @@ -46,9 +52,10 @@ MSYS2 provides a Unix-like terminal environment for Windows, allowing you to run To prepare for SplashKit, you’ll need to install essential tools using the `pacman` package manager within **MINGW64**. - Copy and paste the following command into the **MINGW64** terminal window to install `git`, `clang`, `gcc`, and `gdb`: + Copy and paste the following commands into the **MINGW64** terminal window to update the packages and then install `git`, `clang`, `gcc`, and `gdb`: ```shell + pacman -Syy pacman -S git mingw-w64-x86_64-clang mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb --noconfirm --disable-download-timeout ``` diff --git a/src/content/docs/installation/Windows (MSYS2)/2-language-tools.mdx b/src/content/docs/installation/Windows (MSYS2)/2-language-tools.mdx index 11f9cd8a0..e699df452 100644 --- a/src/content/docs/installation/Windows (MSYS2)/2-language-tools.mdx +++ b/src/content/docs/installation/Windows (MSYS2)/2-language-tools.mdx @@ -43,7 +43,18 @@ For C++ development, your MSYS2 setup already includes the necessary tools for S ### Python -To develop with Python in SplashKit, follow these steps to install Python on your system. +To develop with Python in SplashKit, you can install the `python` and `pip` MSYS2 packages by running the following command in your MINGW64 terminal: + +```shell +pacman -S mingw-w64-x86_64-python mingw-w64-x86_64-python-pip --noconfirm --disable-download-timeout +``` + +:::note[Alternative Option] + +
+Follow these steps to install Python from the official website: + +For an alternative option, follow these steps to install Python on your system. @@ -73,6 +84,10 @@ To develop with Python in SplashKit, follow these steps to install Python on you +
+ +::: + ### Other Languages Support for other languages such as Rust and Pascal are coming soon. diff --git a/src/content/docs/installation/Windows (MSYS2)/4-vscode.mdx b/src/content/docs/installation/Windows (MSYS2)/4-vscode.mdx index 022a2c87a..c52b95cd1 100644 --- a/src/content/docs/installation/Windows (MSYS2)/4-vscode.mdx +++ b/src/content/docs/installation/Windows (MSYS2)/4-vscode.mdx @@ -20,34 +20,32 @@ After setting up Visual Studio Code, enhance your development environment by add ### C# Extensions - + You can install these C# extensions directly from the terminal by running: ```shell code --install-extension ms-dotnettools.csharp code --install-extension ms-dotnettools.csdevkit -code --install-extension ms-dotnettools.vscodeintellicode-csharp ``` - + To add these extensions within Visual Studio Code: 1. Open the Extensions view by pressing `Ctrl+Shift+X`. -2. Search for "C# Microsoft" and the top 3 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. +2. Search for "C#" and the top 2 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. ![Adding C# extensions in Visual Studio Code](/images/installation/csharp-in-vscode.png) - + Install the following C# extensions directly from the Visual Studio Marketplace: C# C# Dev Kit -Intellicode for C# Dev Kit @@ -55,7 +53,7 @@ Install the following C# extensions directly from the Visual Studio Marketplace: ### C++ Extensions - + To install the C++ Extension Pack directly from the terminal: @@ -64,7 +62,7 @@ code --install-extension ms-vscode.cpptools-extension-pack ``` - + To add the C++ extension within Visual Studio Code: @@ -74,7 +72,7 @@ To add the C++ extension within Visual Studio Code: ![Adding C++ extensions in Visual Studio Code](/images/installation/cplus-in-vscode.png) - + Install the C++ Extension Pack for comprehensive C++ support: @@ -86,30 +84,30 @@ Install the C++ Extension Pack for comprehensive C++ support: ### Python Extensions - + -To install the Python Extension Pack directly from the terminal: +To install the Python extension directly from the terminal: ```shell -code --install-extension donjayamanne.python-extension-pack +code --install-extension ms-python.python ``` - + -To install the Python Extension Pack within Visual Studio Code: +To install the Python extension within Visual Studio Code: 1. Open the Extensions view (`Ctrl+Shift+X`). -2. Search for "Python Extension Pack" and click **Install**. +2. Search for "Python" and click **Install**. ![Adding Python extensions in Visual Studio Code](/images/installation/python-in-vscode.png) - + -For Python support, install the Python Extension Pack from the Visual Studio Marketplace: +For Python support, install the Python extension from the Visual Studio Marketplace: -Python Extension Pack +Python @@ -122,6 +120,6 @@ Congratulations! You've completed the setup of everything you need to get starte You can find more information about compiling and running SplashKit programs in the link below: -Using SplashKit +Using SplashKit ::: diff --git a/src/content/docs/installation/Windows (MSYS2)/index.mdx b/src/content/docs/installation/Windows (MSYS2)/index.mdx index ca5922515..30e0abaf3 100644 --- a/src/content/docs/installation/Windows (MSYS2)/index.mdx +++ b/src/content/docs/installation/Windows (MSYS2)/index.mdx @@ -9,6 +9,16 @@ sidebar: import { LinkCard, CardGrid } from "@astrojs/starlight/components"; +:::tip[Using the Programmer's Field Guide?] + +If you are using the Field Guide, we *strongly recommend* that you follow its installation guide: + +- [Set up my Windows (with MSYS2)](https://programmers.guide/book/appendix/0-installation/2-5-setup-win-msys/) + +This guide also includes an automated script for an easier installation option. + +::: + To get SplashKit installed on Windows, follow the four steps: diff --git a/src/content/docs/installation/Windows (WSL)/4-vscode.mdx b/src/content/docs/installation/Windows (WSL)/4-vscode.mdx index 6e4a509b5..f036aed18 100644 --- a/src/content/docs/installation/Windows (WSL)/4-vscode.mdx +++ b/src/content/docs/installation/Windows (WSL)/4-vscode.mdx @@ -19,7 +19,7 @@ After setting up Visual Studio Code, enhance your development environment by add ### WSL Extension - + You can install the WSL extension directly from the terminal by running: @@ -28,7 +28,7 @@ code --install-extension ms-vscode-remote.remote-wsl ``` - + To add the WSL extension within Visual Studio Code: @@ -38,7 +38,7 @@ To add the WSL extension within Visual Studio Code: ![Adding WSL extension in Visual Studio Code](/images/installation/WSL-in-vscode.png) - + Install the WSL extension directly from the Visual Studio Marketplace: @@ -50,34 +50,32 @@ Install the WSL extension directly from the Visual Studio Marketplace: ### C# Extensions - + You can install these C# extensions directly from the terminal by running: ```shell code --install-extension ms-dotnettools.csharp code --install-extension ms-dotnettools.csdevkit -code --install-extension ms-dotnettools.vscodeintellicode-csharp ``` - + To add these extensions within Visual Studio Code: 1. Open the Extensions view by pressing `Ctrl+Shift+X`. -2. Search for "C# Microsoft" and the top 3 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. +2. Search for "C#" and the top 2 extensions listed above should appear. Click **Install** for each. If they don't then search for them individually. ![Adding C# extensions in Visual Studio Code](/images/installation/csharp-in-vscode.png) - + Install the following C# extensions directly from the Visual Studio Marketplace: C# C# Dev Kit -Intellicode for C# Dev Kit @@ -85,7 +83,7 @@ Install the following C# extensions directly from the Visual Studio Marketplace: ### C++ Extensions - + To install the C++ Extension Pack directly from the terminal: @@ -94,7 +92,7 @@ code --install-extension ms-vscode.cpptools-extension-pack ``` - + To add the C++ extension within Visual Studio Code: @@ -104,7 +102,7 @@ To add the C++ extension within Visual Studio Code: ![Adding C++ extensions in Visual Studio Code](/images/installation/cplus-in-vscode.png) - + Install the C++ Extension Pack for comprehensive C++ support: @@ -116,30 +114,30 @@ Install the C++ Extension Pack for comprehensive C++ support: ### Python Extensions - + -To install the Python Extension Pack directly from the terminal: +To install the Python extension directly from the terminal: ```shell -code --install-extension donjayamanne.python-extension-pack +code --install-extension ms-python.python ``` - + -To install the Python Extension Pack within Visual Studio Code: +To install the Python extension within Visual Studio Code: 1. Open the Extensions view (`Ctrl+Shift+X`). -2. Search for "Python Extension Pack" and click **Install**. +2. Search for "Python" and click **Install**. ![Adding Python extensions in Visual Studio Code](/images/installation/python-in-vscode.png) - + -For Python support, install the Python Extension Pack from the Visual Studio Marketplace: +For Python support, install the Python extension from the Visual Studio Marketplace: -Python Extension Pack +Python @@ -152,6 +150,6 @@ Congratulations! You've completed the setup of everything you need to get starte You can find more information about compiling and running SplashKit programs in the link below: -Using SplashKit +Using SplashKit ::: diff --git a/src/content/docs/installation/Windows (WSL)/index.mdx b/src/content/docs/installation/Windows (WSL)/index.mdx index 1da775156..4516233c4 100644 --- a/src/content/docs/installation/Windows (WSL)/index.mdx +++ b/src/content/docs/installation/Windows (WSL)/index.mdx @@ -9,6 +9,16 @@ sidebar: import { LinkCard, CardGrid } from "@astrojs/starlight/components"; +:::tip[Using the Programmer's Field Guide?] + +If you are using the Field Guide, we *strongly recommend* that you follow its installation guide: + +- [Set up my Windows (with WSL)](https://programmers.guide/book/appendix/0-installation/2-6-setup-win-wsl/) + +This guide also includes an automated script for an easier installation option. + +::: + To get SplashKit installed on Windows, follow the four steps: diff --git a/src/content/docs/installation/index.mdx b/src/content/docs/installation/index.mdx index 47c3bfd6e..8cf132fda 100644 --- a/src/content/docs/installation/index.mdx +++ b/src/content/docs/installation/index.mdx @@ -10,8 +10,15 @@ import { Card, LinkCard, CardGrid } from "@astrojs/starlight/components"; If you have previously installed SplashKit, see the [Updating SplashKit](#updating-splashkit) section below. ::: +:::tip[Using the Programmer's Field Guide?] + +If you are using the Field Guide, we *strongly recommend* that you follow the one of these [**installation guides**](https://programmers.guide/book/appendix/0-installation/0-overview/) for more detailed instructions. +Most of these guides also include an automated script for an easier installation option. + +::: + - + {/* TODO: Add short text about Windows here */} - + {/* TODO: Add short text about MacOS here */} - + {/* TODO: Add short text about Linux here */} - + {/* TODO: Add short text about VMs here */} ```shell -echo "export PATH=\"\$PATH:\$HOME/.dotnet\"" >> ~/.zshrc -echo "export PATH=\"\$DOTNET_ROOT:\$HOME/.dotnet\"" >> ~/.zshrc -source ~/.zshrc +echo "export PATH=\"\$PATH:\$HOME/.dotnet\"" >> ~/.bashrc +echo "export PATH=\"\$DOTNET_ROOT:\$HOME/.dotnet\"" >> ~/.bashrc +source ~/.bashrc ``` diff --git a/src/pages/api/top-docs.ts b/src/pages/api/top-docs.ts new file mode 100644 index 000000000..b7676af99 --- /dev/null +++ b/src/pages/api/top-docs.ts @@ -0,0 +1,185 @@ +// ------------------------------------------------------------------------------ +// API Route: Popular Tutorials Data +// Returns mock tutorial statistics for the popular tutorials feature +// Phase 1: Mock data, Phase 2: Real analytics integration +// ------------------------------------------------------------------------------ + +export interface TopDoc { + path: string; // Page URL path as stable ID + title: string; // Tutorial title + views: number; // Total page views + avgTimeSpent: number; // Average time spent on page (seconds) + category: string; // Auto-extracted from path (first segment) +} + +// Mock tutorial data based on real SplashKit documentation paths +const mockTutorialData: TopDoc[] = [ + { + path: '/guides/graphics/drawing-sprites/', + title: 'Drawing', + views: 3247, + avgTimeSpent: 145, + category: 'guides' + }, + { + path: '/installation/windows-msys2/4-vscode/', + title: 'VS Code Setup for Windows', + views: 2891, + avgTimeSpent: 220, + category: 'installation' + }, + { + path: '/guides/animations/simple-animations/', + title: 'Simple Animations', + views: 2654, + avgTimeSpent: 180, + category: 'guides' + }, + { + path: '/guides/audio/playing-sounds/', + title: 'Playing Sounds', + views: 2103, + avgTimeSpent: 95, + category: 'guides' + }, + { + path: '/guides/input/handling-input/', + title: 'Handling User Input', + views: 1987, + avgTimeSpent: 165, + category: 'guides' + }, + { + path: '/installation/ubuntu/', + title: 'Ubuntu Installation Guide', + views: 1845, + avgTimeSpent: 280, + category: 'installation' + }, + { + path: '/guides/physics/collision-detection/', + title: 'Collision Detection', + views: 1672, + avgTimeSpent: 200, + category: 'guides' + }, + { + path: '/api/graphics/#draw-bitmap-named', + title: 'Draw Bitmap API Reference', + views: 1534, + avgTimeSpent: 75, + category: 'api' + } +]; + +// Attempt to load GA4 when env is present +async function fetchFromGA4(limit: number, host?: string) { + const propertyId = process.env.GA4_PROPERTY_ID; + const clientEmail = process.env.GA4_CLIENT_EMAIL; + let privateKey = process.env.GA4_PRIVATE_KEY; + + if (!propertyId || !clientEmail || !privateKey) { + return { items: null as TopDoc[] | null, reason: 'missing-env' as const }; + } + + // Handle escaped newlines in env var + privateKey = privateKey.replace(/\\n/g, '\n'); + + // Lazy import GA client so build works even if not configured locally + const { BetaAnalyticsDataClient } = await import('@google-analytics/data'); + const analytics = new BetaAnalyticsDataClient({ + credentials: { + client_email: clientEmail, + private_key: privateKey + } + }); + + // Request: last 30 days, by pagePath + const request: any = { + property: `properties/${propertyId}`, + dateRanges: [{ startDate: '30daysAgo', endDate: 'yesterday' }], + dimensions: [{ name: 'hostName' }, { name: 'pagePath' }, { name: 'pageTitle' }], + metrics: [{ name: 'screenPageViews' }, { name: 'userEngagementDuration' }], + orderBys: [{ metric: { metricName: 'screenPageViews' }, desc: true }], + limit: BigInt(Math.max(1, Math.min(limit, 50))) + }; + + if (host) { + request.dimensionFilter = { + filter: { + fieldName: 'hostName', + stringFilter: { matchType: 'EXACT', value: host } + } + }; + } + + const [response] = await analytics.runReport(request); + + const rows = (response.rows ?? []) as any[]; + const items: TopDoc[] = rows.map((r: any) => { + const path = r.dimensionValues?.[1]?.value || '/'; + const title = r.dimensionValues?.[2]?.value || 'Untitled'; + const views = parseInt(r.metricValues?.[0]?.value ?? '0', 10) || 0; + const totalEngagement = parseFloat(r.metricValues?.[1]?.value ?? '0') || 0; + const avgTime = views > 0 ? Math.round(totalEngagement / views) : 0; // seconds + const category = path.split('/').filter(Boolean)[0] ?? 'site'; + return { path, title, views, avgTimeSpent: avgTime, category }; + }); + + return { items, reason: 'ok' as const }; +} + +// API endpoint handler +export async function GET({ url }: { url: URL }) { + try { + // Parse query parameters + const limitParam = url.searchParams.get('limit'); + const limit = limitParam ? parseInt(limitParam, 10) : 6; + const source = (url.searchParams.get('source') || 'auto').toLowerCase(); + + // Prefer GA4 if requested or auto and env is present + if (source === 'ga4' || source === 'auto') { + const host = url.searchParams.get('host') || undefined; + try { + const ga = await fetchFromGA4(limit, host); + if (ga.items && ga.items.length > 0) { + return new Response(JSON.stringify({ + items: ga.items, + meta: { source: 'ga4', returned: ga.items.length, ismock: false, host: host ?? null } + }), { status: 200, headers: { 'Content-Type': 'application/json', 'Cache-Control': 'public, max-age=120' } }); + } + } catch (e) { + console.warn('GA4 fetch failed, falling back to mock:', e); + } + } + + // Fallback to mock data (Phase 1) + const sortedTutorials = [...mockTutorialData].sort((a, b) => b.views - a.views); + const limitedTutorials = sortedTutorials.slice(0, Math.max(1, Math.min(limit, 20))); + + return new Response(JSON.stringify({ + items: limitedTutorials, + meta: { + total: mockTutorialData.length, + returned: limitedTutorials.length, + source: 'mock', + ismock: true + } + }), { + status: 200, + headers: { + 'Content-Type': 'application/json', + 'Cache-Control': 'public, max-age=60' + } + }); + } catch (error) { + console.error('Error in top-docs API:', error); + return new Response(JSON.stringify({ + error: 'Internal server error', + message: 'Failed to fetch tutorial data' + }), { + status: 500, + headers: { 'Content-Type': 'application/json' } + }); + } +} diff --git a/src/styles/cards.css b/src/styles/cards.css index 6c169516a..e7f0a85a4 100644 --- a/src/styles/cards.css +++ b/src/styles/cards.css @@ -1,7 +1,8 @@ /* --- START: Link card styling ------*/ .sl-markdown-content .sl-link-card { - border: 2px solid var(--sk-logo-orange); - background-color: var(--sk-logo-orange-transparent); + border: none; + outline: 1px solid var(--sk-logo-blue); + background-color: var(--sl-color-gray-5); .description { color: var(--sl-color-gray-2); @@ -10,8 +11,9 @@ /* Hover effects */ .sl-markdown-content .sl-link-card:hover { - border: 2px solid var(--sk-logo-blue); - background-color: var(--sk-logo-blue-transparent); + border: none; + outline: 2px solid var(--sk-logo-orange); + background-color: var(--sl-color-gray-7); .description { color: var(--sl-color-gray-1); @@ -31,4 +33,4 @@ article.card { box-shadow: var(--sl-shadow-md); } -/* --- END: Card styling ------*/ +/* --- END: Card styling ------*/ \ No newline at end of file diff --git a/src/styles/custom.css b/src/styles/custom.css index b6687a02f..0a9618d09 100644 --- a/src/styles/custom.css +++ b/src/styles/custom.css @@ -259,6 +259,11 @@ a.decent:hover { padding-left: 15px; } +.sl-markdown-content .function-parameters-list table td:nth-child(1), +.sl-markdown-content .function-parameters-list table td:nth-child(2) { + white-space: nowrap; +} + .sl-markdown-content table td:last-child, .sl-markdown-content table th:last-child { border-right: none; @@ -499,4 +504,123 @@ mjx-container svg { border: 3px solid var(--sl-color-white); transform: scale(1.05); /* Slight zoom effect on hover */ -} \ No newline at end of file +} + +/* + ----- Start of new Tab Styling ----- +*/ + +/* Variables for light and dark theme colors*/ +:root { + --tab-bg: var(--sl-color-gray-5); + --tab-hover-bg: var(--sl-color-gray-6); + --tab-text: var(--sl-color-gray-3); + --tab-hover-text: var(--sl-color-white); + --focused-tab-bg: var(--sl-color-bg); +} + +[data-theme="dark"] { + --tab-outline: var(--sk-logo-orange); + --focused-tab-outline: var(--sk-logo-blue); +} + +[data-theme="light"] { + --tab-outline: var(--sk-logo-blue); + --focused-tab-outline: var(--sk-logo-orange); + + .accordionContent { + --focused-tab-bg: var(--sl-color-gray-7); + } +} + +/* Basic Tab Style */ +.tab { + position: relative; + margin-right: 4px; + margin-left: 4px; + padding-top: 5px; + border-radius: 0.5rem 0.5rem 0 0; + border: 2px solid var(--focused-tab-outline); + background-color: var(--tab-bg); +} + +/* Fill whole tab area when tab text is different heights */ +[role="tab"] { + display: block; + height: 100%; +} + +.tab:has(> [role="tab"][aria-selected="true"]) { + background-color: var(--focused-tab-bg); + border-bottom-color: var(--focused-tab-bg); + + [role="tab"][aria-selected="true"] { + border-bottom-color: var(--focused-tab-bg); + } +} + +.tab:has(> [role="tab"][aria-selected="false"]) { + margin-top: 3px; + margin-bottom: 0px; + color: var(--tab-text); + border-color: var(--tab-outline); + border-width: 1px; + border-bottom: none; +} + +.tab:has(> [role="tab"][aria-selected="false"]):hover { + cursor: pointer; + color: var(--tab-hover-text); + background-color: var(--tab-hover-bg); + + [role="tab"][aria-selected="false"] { + border-bottom-color: var(--tab-hover-bg); + } +} + +[role="tablist"] { + border-bottom-color: var(--focused-tab-outline); + margin-bottom: 3px; +} + +/* Round out styling using circle pseudo-element - right side */ +.tab:has(> [role="tab"][aria-selected="true"])::after { + content: ""; + display: block; + position: absolute; + bottom: -3px; + right: -15px; + width: 15px; + height: 15px; + border-radius: 50%; + background: transparent; + border: 2px solid transparent; + border-left-color: var(--focused-tab-outline); + border-bottom-color: var(--focused-tab-outline); + clip-path: inset(7px 5px 1px 0); + z-index: 2; + box-shadow: -4px 6px 0 var(--focused-tab-bg); +} + +/* Round out styling using circle pseudo-element - left side */ +.tab:has(> [role="tab"][aria-selected="true"])::before { + content: ""; + display: block; + position: absolute; + bottom: -3px; + left: -15px; + width: 15px; + height: 15px; + border-radius: 50%; + background: transparent; + border: 2px solid transparent; + border-right-color: var(--focused-tab-outline); + border-bottom-color: var(--focused-tab-outline); + clip-path: inset(7px 0 1px 5px); + z-index: 2; + box-shadow: 4px 6px 0 var(--focused-tab-bg); +} + +/* + ----- End Tab Styling ----- +*/ \ No newline at end of file