Here is an example how to use grep a “reverse diff” to find different lines in sorted text files. Command grep is using options: -F, –fixed-strings PATTERN is a set of newline-separated strings -x, –line-regexp force PATTERN to match only whole lines -f, –file=FILE obtain PATTERN from FILE
I recently went through NASA’s “meatball” logo, originally designed by James Modarelli in 1959. Looking at the svg version of this famous logo, I was interested in the svg code. It was obviously designed by some editor and not “by hand”. Here is an updated “beautified” version, at least from the code perspective, the result of a good and interesting svg exercise. There is an interesting fact that paths for all four letters are mixing absolute and relative path commands. It means that it is impossible to easily change a letter’s location, if necessary.
Sometimes there is a need to resize svg element by javascript. SVG image with pink background in the following example has initial “Fullsize” dimensions 1920×1080. SVGLength interface and more is described at https://developer.mozilla.org/en-US/docs/Web/API under letter S with prefix SVG . Initial width and height is resized to 200×100 in this code snippet.
There is a new kid on the block: ChatGPT powered by OpenAI. And here is a test question: “How to make web page with toggle button in Javascript to resize to full screen page showing screen dimensions“. It’s fascinating to see writing answer is the real time. Here it is:
To create a web page with a toggle button that resizes the page to full screen and shows the screen dimensions, you can use the following steps:
1. First, create a new HTML file and add the following code to create a basic structure for your web page:
2. Next, add a <button> element to the page, which will be used as the toggle button. You can add the following code to the <body> element:
<button id="toggle-fullscreen">Toggle Full Screen</button>
3. Then, create a <div> element that will be used to display the screen dimensions. You can add the following code to the <body> element:
<div id="screen-dimensions"></div>
4. After that, add a <script> element to the page, which will contain the JavaScript code that will make the toggle button work. You can add the following code to the <body> element:
<script>
// JavaScript code goes here
</script>
5. Inside the <script> element, add the following code to get the dimensions of the screen and display them in the <div> element:
// Get the screen dimensions
var screenWidth = window.innerWidth;
var screenHeight = window.innerHeight;
// Get the <div> element for displaying the screen dimensions
var screenDimensionsElement = document.getElementById("screen-dimensions");
// Set the text content of the <div> element to the screen dimensions
screenDimensionsElement.textContent = "Screen dimensions: " + screenWidth + " x " + screenHeight;
6. Finally, add the following code to make the toggle button toggle between full screen and normal screen mode:
// Get the toggle button
var toggleButton = document.getElementById("toggle-fullscreen");
// Add a click event listener to the toggle button
toggleButton.addEventListener("click", function() {
// Check if full screen mode is enabled
if (document.fullscreenElement) {
// If full screen mode is enabled, exit full
Conclusion: Not bad for the first attempt. But script at last step is not done, there are missing curly brackets and code. On the other hand this code could be a good starting point to develop such page, but a real programmer has to do the last “details”. So here is a Full Screen Toggle dimensions report web page code:
<!DOCTYPE html>
<!-- 2022-1211 Chat GPT: How to make web page with toggle button in Javascript to resize to full screen page showing screen dimensions -->
<html>
<head>
<title>Full Screen Toggle dimensions report</title>
<style>
.center {
text-align: center;
}
</style>
<script>
var elem = document.documentElement;
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.webkitRequestFullscreen) { /* Safari */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE11 */
elem.msRequestFullscreen();
}
}
function closeFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) { /* Safari */
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) { /* IE11 */
document.msExitFullscreen();
}
}
function toggleFullscreen() {
// Check if full screen mode is enabled
if (document.fullscreenElement) {
closeFullscreen();
} else {
openFullscreen();
}
}
</script>
</head>
<body>
<div class="center">
<h2>Full Screen Toggle dimensions report</h2>
<button id="toggle-fullscreen">Toggle Full Screen</button>
<h1 id="screen-dimensions"></h1>
</div>
<script>
// Get the element for displaying the screen dimensions
var screenDimensionsElement = document.getElementById("screen-dimensions");
// Set the text content of the <div> element to the screen dimensions
function textContentUpdate(fullScreen) {
// Get the screen dimensions
var screenWidth = window.innerWidth;
var screenHeight = window.innerHeight;
var screenType = fullScreen ? "Fullscreen" : "Screen";
var dimensions = screenType + " dimensions: " + screenWidth + " x " + screenHeight;
screenDimensionsElement.textContent = dimensions;
console.info(dimensions);
}
textContentUpdate();
// Get the toggle button
var toggleButton = document.getElementById("toggle-fullscreen");
function toggleAndReportDimensions() {
toggleFullscreen();
// Add 300ms delay to make sure window.innerWidth and window.innerHeight values are updated by js system
setTimeout(function () {
textContentUpdate(document.fullscreenElement);
}, 300);
}
// Add a click event listener to the toggle button
toggleButton.addEventListener("click", toggleAndReportDimensions);
</script>
</body>
</html>
Sometimes is needed circular text. Here is few examples how it can be done. All of them are working with a circular path with radius 100, then circumference is 628. The first example is going to create circular path from starting point A very close to the bottom circle and it ends on opposite side of the vertical axis point B. Let’s say that point A and B will be just 1 unit off the vertical axis, so they will be 2 units distant. The circle with radius 100 has circumference 628, but in this case we have to subtract distance AB, so path length is 628. Here is SVG code snippet:
<path id="path1" d="M0,0 m-1,100 a100,100 0 1,1 2,0 " style="fill:none;fill-opacity: 1;stroke:green;stroke-width: 1"/>
<text dy="12" dx="0" textLength="626">
<textPath xlink:href="#path1">This text starts at bottom "6" and goes around</textPath>
</text>
We can notice that end of the text is too close to the start. We can start with offset dx=”12″ and we should make textLength twice as much shorter to 628-2-12-12=602. And here is result:
Now what if we would like the text outside of the circular path. Than offset y should be zero dy=”0″.
Text almost around 360 degrees is not so easy to read. Solution can be to split text into two parts. Here is an example with SVG code snippet:
<path id="path1a" d="M0,0 m-70.7,70.7 a100,100 0 1,1 141.4,0 " style="fill:none;fill-opacity: 1;stroke:green;stroke-width: 1"></path>
<text dy="12" dx="0" textLength="471">
<textPath xlink:href="#path1a">This is upper text and goes around circle</textPath>
</text>
<path id="path2a" d="M0,0 m-70.7,70.7 a100,100 0 0,0 141.4,0 " style="fill:none;fill-opacity: 1;stroke:red;stroke-width: 1"></path>
<text dy="-2" dx="5" textLength="147">
<textPath xlink:href="#path2a">* Bottom text *</textPath>
</text>
In the recent post have been described how to create spiky star. Let’s utilize that knowledge to create star cluster Pleiades from the eight brightest spiky stars. Relative size can be computed by formula sqrt(8000/POW(2,511886432;magnitude). Number 8000 is just arbitrarily selected constant for this example. More can be find at Wikipedia. Positions are taken from the map of Pleiades. Of course, better would be to create gnomonic map of this star cluster, maybe in the future.
Let’s say we would like to create spiky star. One option would be to utilize tag path. Picture below should help to explain, how to design path. In the center “C” is a unit circle with radius 1. Each spike has base 0.8 wide (2*0.4) and height 1.5. Now let’s compute absolute coordinates for the green path points. Vertical distance for the first point g1 has value sqrt(1*1 -0.4*0.4) = 0.9165… Here is list of the few points.
In similar fashion can be computed red path points. It is obvious, that in this case is much easier to compute their coordinates. On the other hand radius of the arc connecting point r3 and r4 is not just 1, but it has a value sqrt(1*1+ 0.4*0.4) = 1.077… In reality arc with radius 1 or arc with radius 1.077 is almost the same, especially for narrow spike base.
NASA tested in 2019 in mission GPIM so called green fuel. Here is chemical composition of this substance called hydroxylammonium nitrate or hydroxylamine nitrate with the chemical formula [NH3OH+][NO3-]. It is a colorless hygroscopic solid usually handled as an aqueous solution.