commit 5424fff322ab363aab0c917811324dc509d06406 Author: Benjamin Kraft Date: Sun Mar 19 10:23:17 2023 +0100 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6ef218 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea + diff --git a/project.json b/project.json new file mode 100644 index 0000000..31eace8 --- /dev/null +++ b/project.json @@ -0,0 +1,6 @@ +{ + "display_name": "Colors", + "info_text": "Many colors.", + "visible": false, + "tags": ["Simulation"] +} \ No newline at end of file diff --git a/public/data/images/favicon.ico b/public/data/images/favicon.ico new file mode 100644 index 0000000..3172667 Binary files /dev/null and b/public/data/images/favicon.ico differ diff --git a/public/data/scripts/colors.js b/public/data/scripts/colors.js new file mode 100644 index 0000000..4dc4826 --- /dev/null +++ b/public/data/scripts/colors.js @@ -0,0 +1,35 @@ +class Colors{ + + constructor() { + this.minSize = 25; + p.colorMode(p.HSB); + } + + display(){ + this.paint({x: 0, y: 0, w: p.width, h: p.height}, p.color(p.random(360), 100, 100)); + } + + paint(rect, colorScheme){ + if (rect.w < this.minSize || rect.h < this.minSize){ + p.stroke(0); + p.strokeWeight(1); + p.fill(colorScheme); + p.rect(rect.x, rect.y, rect.w, rect.h); + } else { + let change = 25; + colorScheme = p.color(p.hue(colorScheme) + p.noise(p.frameCount) * change, 100, 100); + let axis = ranBoolP(rect.w / rect.h - 0.5); //true -> x, false -> y + let offset = 0.2; + if (axis){ + let w = p.random(rect.w * offset, rect.w * (1 - offset)); + this.paint({x: rect.x, y: rect.y, w: w, h: rect.h}, colorScheme); + this.paint({x: rect.x + w, y: rect.y, w: rect.w - w, h: rect.h}, colorScheme); + } else { + let h = p.random(rect.h * offset, rect.h * (1 - offset)); + this.paint({x: rect.x, y: rect.y, w: rect.w, h: h}, colorScheme); + this.paint({x: rect.x, y: rect.y + h, w: rect.w, h: rect.h - h}, colorScheme); + } + } + } + +} \ No newline at end of file diff --git a/public/data/scripts/events.js b/public/data/scripts/events.js new file mode 100644 index 0000000..179f94e --- /dev/null +++ b/public/data/scripts/events.js @@ -0,0 +1,31 @@ +'use strict'; + +p.keyPressed = () => { + switch (p.keyCode){ + //Ctrl + D + case 68: + if (p.keyIsDown(17)){ + debug = !debug; + let msg = 'Debug mode turned ' + (debug ? 'ON' : 'OFF'); + console.info(msg); + return false; + } + break; + case 67: + colors.display(); + break; + case 76: + if (p.isLooping()){ + p.noLoop(); + } else{ + p.loop(); + } + } +}; + +p.windowResized = () => { + let element = $('#canvas_holder'); + let w = element.width(), + h = element.height(); + p.resizeCanvas(w, h); +}; \ No newline at end of file diff --git a/public/data/scripts/init.js b/public/data/scripts/init.js new file mode 100644 index 0000000..8573bc0 --- /dev/null +++ b/public/data/scripts/init.js @@ -0,0 +1,95 @@ +'use strict'; + +let debug = false, + font, + settings, + loader; + +//Only for online games +let socket; + +let antiCacheQuery = '?_=' + new Date().getTime(); + +let colors; + +const p = new p5((p) => { + + p.preload = () => { + settings = p.loadJSON('data/settings/settings.json' + antiCacheQuery, {}, 'json', (json) => { + console.log('Local settings loaded: ', json); + }, (error) => { + console.log('Local settings failed: ', error); + }); + + font = p.loadFont('data/styles/fonts/Tajawal/Tajawal-Regular.ttf' + antiCacheQuery, (font) => { + console.log('Local font loaded: ', font); + }, (error) => { + console.log('Local font failed: ', error); + }); + }; + + p.setup = () => { + interfaceSetup(); + canvasSetup(); + //loader = new Loader(p.createVector(p.width / 2, p.height / 2), Math.min(p.width, p.height) / 2); + loadDynamicScripts().then(() => { + //Load other stuff, then => + //loader = null; + colors = new Colors(); + colors.display(); + }); + }; + + p.draw = () => { + p.background(30); + + if (loader){ + loader.update(); + loader.display(); + } + + if (colors){ + colors.display(); + } + + if (debug) debugInformation(); + }; +}); + +function debugInformation(){ + +} + + +function interfaceSetup(){ + +} + +function canvasSetup(){ + p.frameRate(60); + let element = $('#canvas_holder'); + let w = element.width(), + h = element.height(); + let canvas = p.createCanvas(w, h); + canvas.parent('canvas_holder'); + p.textFont(font); + p.frameRate(5); +} + +async function loadDynamicScripts(){ + const json = await p.httpGet('data/settings/libraries.json' + antiCacheQuery, 'json'); + let requests = []; + for (let script in json) { + if (json.hasOwnProperty(script)){ + if (json[script]) { + let url = '/lib/benjocraeft/' + script + '.js'; + requests.push($.getScript(url, () => { + console.log('Successfully loaded script: ', url); + })); + } + } + + } + await $.when(...requests); + console.log('All dynamic scripts have been loaded!'); +} \ No newline at end of file diff --git a/public/data/scripts/loader.js b/public/data/scripts/loader.js new file mode 100644 index 0000000..500750f --- /dev/null +++ b/public/data/scripts/loader.js @@ -0,0 +1,46 @@ +class Loader{ + + constructor(pos, radius){ + this.pos = pos; + this.c = p.createGraphics(radius * 2, radius * 2); + this.radius = radius; + this.center = p.createVector(radius, radius); + this.message = 'Loading...'; + this.progress = 0; + this.angle = 0; + } + + update(){ + this.angle += Math.PI / 10; + } + + display(){ + let c = this.c; + c.clear(); + c.noFill(); + c.stroke(20, 100, 200); + c.strokeWeight(this.radius * 0.025); + //c.arc(this.center.x, this.center.y, this.radius * 2, this.radius * 2, this.angle, this.angle + Math.PI * 1.5); + c.strokeWeight(2); + c.rect(this.center.x - this.radius + 5, this.center.y - 25, this.radius * 2 - 50, 50); + c.fill(50, 150, 255); + c.rect(this.center.x - this.radius + 5, this.center.y - 25, (this.radius - 50) * this.progress, 50); + + c.textAlign(p.CENTER, p.CENTER); + c.textSize(25); + c.fill(220); + c.strokeWeight(4); + c.text(this.message, this.radius, this.radius * 1.5); + + c.textSize(40); + c.text(Math.floor(this.progress * 100) + '%', this.radius, this.radius / 2); + + p.imageMode(p.CENTER); + p.image(c, this.pos.x, this.pos.y); + } + + destroy(){ + this.c.remove(); + } + +} \ No newline at end of file diff --git a/public/data/scripts/online.js b/public/data/scripts/online.js new file mode 100644 index 0000000..90cf91f --- /dev/null +++ b/public/data/scripts/online.js @@ -0,0 +1,12 @@ +'use strict'; + +function socketConnect(project = settings.project, name = "noone"){ + $.get('/php/get_nodejs_port.php', port => { + let urlQueries = '?game=' + project.name + '&name=' + name; + let url = 'https://' + location.hostname + ":" + port + urlQueries; + + socket = io.connect(url); + socket.on('connect', () => console.log('Connected to ', url)); + }); + +} \ No newline at end of file diff --git a/public/data/settings/libraries.json b/public/data/settings/libraries.json new file mode 100644 index 0000000..31098c4 --- /dev/null +++ b/public/data/settings/libraries.json @@ -0,0 +1,7 @@ +{ + "collision": false, + "colorPicker": false, + "cookie": false, + "prototypes": false, + "technical": true +} \ No newline at end of file diff --git a/public/data/settings/settings.json b/public/data/settings/settings.json new file mode 100644 index 0000000..01dad8a --- /dev/null +++ b/public/data/settings/settings.json @@ -0,0 +1,23 @@ +{ + "project": { + "name": "project_pattern", + "author": "BenjoCraeft", + "version": "0.0.0", + "playerCounts": [], + "online": { + "iceServers": [ + {"urls": "stun:stun.l.google.com:19302"}, + { + "urls": "turn:numb.viagenie.ca", + "credential": "muazkh", + "username": "webrtc@live.com" + } + ] + } + }, + "frameWork": { + "frameRate": 60, + "width": null, + "height": null + } +} \ No newline at end of file diff --git a/public/data/styles/color_picker.css b/public/data/styles/color_picker.css new file mode 100644 index 0000000..a5b510e --- /dev/null +++ b/public/data/styles/color_picker.css @@ -0,0 +1,88 @@ +#color_picker{ + width: 300px; + height: 25%; + margin: 20px; + margin-top: 50px; + border: 5px solid #000; + background-color: #000; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + position: relative; +} +#color_picker_numeric{ + width: 80%; + padding: 5%; + margin: 5%; + background-color: #888; + border-radius: 10px; + overflow: hidden; +} +.color_picker_rgb{ + float: left; + width: 22%; + height: 35px; + font-size: 25px; + color: #000; +} +.color_picker_rgb:nth-child(1){ + margin-right: 10%; + margin-left: 3%; + background-color: #F00; + +} +.color_picker_rgb:nth-child(2){ + background-color: #0F0; +} +.color_picker_rgb:nth-child(3){ + margin-left: 10%; + background-color: #00F; + color: #FFF; +} +#color_picker_hex{ + width: 50%; + height: 30px; + font-size: 25px; + margin: 10% 25% 0 25%; +} +#saturation{ + position: relative; + width: calc(100% - 33px); + height: 100%; + background: linear-gradient(to right, #FFF 0%, #F00 100%); + float: left; + margin-right: 6px; +} +#value { + width: 100%; + height: 100%; + background: linear-gradient(to top, #000 0%, rgba(255,255,255,0) 100%); +} +#sb_picker{ + border: 2px solid; + border-color: #FFF; + position: absolute; + width: 14px; + height: 14px; + border-radius: 10px; + bottom: 50px; + left: 50px; + box-sizing: border-box; + z-index: 10; +} +#hue { + width: 27px; + height: 100%; + position: relative; + float: left; + background: linear-gradient(to bottom, #F00 0%, #F0F 17%, #00F 34%, #0FF 50%, #0F0 67%, #FF0 84%, #F00 100%); +} +#hue_picker { + position: absolute; + background: #000; + border-bottom: 1px solid #000; + top: 0; + width: 27px; + height: 2px; +} \ No newline at end of file diff --git a/public/data/styles/fonts/Elronet/Elronmonospace.ttf b/public/data/styles/fonts/Elronet/Elronmonospace.ttf new file mode 100644 index 0000000..c4b5f2a Binary files /dev/null and b/public/data/styles/fonts/Elronet/Elronmonospace.ttf differ diff --git a/public/data/styles/fonts/Tajawal/OFL.txt b/public/data/styles/fonts/Tajawal/OFL.txt new file mode 100644 index 0000000..b389da1 --- /dev/null +++ b/public/data/styles/fonts/Tajawal/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2018 Boutros International. (https://www.boutrosfonts.com) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/public/data/styles/fonts/Tajawal/Tajawal-Black.ttf b/public/data/styles/fonts/Tajawal/Tajawal-Black.ttf new file mode 100644 index 0000000..19d52ed Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-Black.ttf differ diff --git a/public/data/styles/fonts/Tajawal/Tajawal-Bold.ttf b/public/data/styles/fonts/Tajawal/Tajawal-Bold.ttf new file mode 100644 index 0000000..159a3b5 Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-Bold.ttf differ diff --git a/public/data/styles/fonts/Tajawal/Tajawal-ExtraBold.ttf b/public/data/styles/fonts/Tajawal/Tajawal-ExtraBold.ttf new file mode 100644 index 0000000..c44b766 Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-ExtraBold.ttf differ diff --git a/public/data/styles/fonts/Tajawal/Tajawal-ExtraLight.ttf b/public/data/styles/fonts/Tajawal/Tajawal-ExtraLight.ttf new file mode 100644 index 0000000..5956e03 Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-ExtraLight.ttf differ diff --git a/public/data/styles/fonts/Tajawal/Tajawal-Light.ttf b/public/data/styles/fonts/Tajawal/Tajawal-Light.ttf new file mode 100644 index 0000000..95493f5 Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-Light.ttf differ diff --git a/public/data/styles/fonts/Tajawal/Tajawal-Medium.ttf b/public/data/styles/fonts/Tajawal/Tajawal-Medium.ttf new file mode 100644 index 0000000..5b7ec2b Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-Medium.ttf differ diff --git a/public/data/styles/fonts/Tajawal/Tajawal-Regular.ttf b/public/data/styles/fonts/Tajawal/Tajawal-Regular.ttf new file mode 100644 index 0000000..14394f9 Binary files /dev/null and b/public/data/styles/fonts/Tajawal/Tajawal-Regular.ttf differ diff --git a/public/data/styles/range_input.css b/public/data/styles/range_input.css new file mode 100644 index 0000000..6c9eaeb --- /dev/null +++ b/public/data/styles/range_input.css @@ -0,0 +1,89 @@ +input[type=range] { + -webkit-appearance: none; + margin: 18px 0; + width: 100%; + background: none; +} +input[type=range]:focus { + outline: none; +} +input[type=range]::-webkit-slider-runnable-track { + width: 100%; + height: 8.4px; + cursor: pointer; + animate: 0.2s; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + background: #3071a9; + border-radius: 1.3px; + border: 0.2px solid #010101; +} +input[type=range]::-webkit-slider-thumb { + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + border: 1px solid #000000; + height: 36px; + width: 16px; + border-radius: 3px; + background: #ffffff; + cursor: pointer; + -webkit-appearance: none; + margin-top: -14px; +} +input[type=range]:focus::-webkit-slider-runnable-track { + background: #367ebd; +} +input[type=range]::-moz-range-track { + width: 100%; + height: 8.4px; + cursor: pointer; + animate: 0.2s; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + background: #3071a9; + border-radius: 1.3px; + border: 0.2px solid #010101; +} +input[type=range]::-moz-range-thumb { + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + border: 1px solid #000000; + height: 36px; + width: 16px; + border-radius: 3px; + background: #ffffff; + cursor: pointer; +} +input[type=range]::-ms-track { + width: 100%; + height: 8.4px; + cursor: pointer; + animate: 0.2s; + background: transparent; + border-color: transparent; + border-width: 16px 0; + color: transparent; +} +input[type=range]::-ms-fill-lower { + background: #2a6495; + border: 0.2px solid #010101; + border-radius: 2.6px; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; +} +input[type=range]::-ms-fill-upper { + background: #3071a9; + border: 0.2px solid #010101; + border-radius: 2.6px; + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; +} +input[type=range]::-ms-thumb { + box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d; + border: 1px solid #000000; + height: 36px; + width: 16px; + border-radius: 3px; + background: #ffffff; + cursor: pointer; +} +input[type=range]:focus::-ms-fill-lower { + background: #3071a9; +} +input[type=range]:focus::-ms-fill-upper { + background: #367ebd; +} \ No newline at end of file diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..6c0f54c --- /dev/null +++ b/public/index.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + Colors + + +
+
+
+
+ + \ No newline at end of file diff --git a/public/styles.css b/public/styles.css new file mode 100644 index 0000000..5bc64e5 --- /dev/null +++ b/public/styles.css @@ -0,0 +1,49 @@ +a:link, a:hover, a:active, a:visited{color: #000;} + +html, body{margin: 0; padding: 0; height: 100%; width: 100%;} + +canvas{margin: 0; padding: 0; border: none; display: block;} + +button:hover{cursor: pointer;} + +@font-face{ + font-family: "Tajawal"; + src: url("data/styles/fonts/Tajawal/Tajawal-Regular.ttf"); +} +@font-face{ + font-family: "Elronet"; + src: url("data/styles/fonts/Elronet/Elronmonospace.ttf"); +} + +*{ + font-family: "Tajawal"; + color: #000; + font-size: 17px; +} + +:root{ + --width: 100vw; + --height: 100vh; +} + +/** + * Standard styles + */ + +#canvas_holder{ + position: relative; + width: var(--width); + height: var(--height); +} +#canvas_holder canvas{ + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + border-radius: inherit; +} +#p5_loading{ + display: none; +} +