User:Alessia/coding+3d: Difference between revisions

From XPUB & Lens-Based wiki
mNo edit summary
Line 98: Line 98:
oppure
oppure
  [system.media.systemsounds]::beep.play()
  [system.media.systemsounds]::beep.play()
==https://see.fontimg.com/api/renderfont4/x3J88/eyJyIjoiZnMiLCJoIjozOSwidyI6MTI1MCwiZnMiOjMxLCJmZ2MiOiIjMDYwMDA3IiwiYmdjIjoiI0VERURFQSIsInQiOjF9/Ym91bmNpbmcgYmFsbCBhbmltYXRpb24/magnific-chaos-personal-use-regular.png ᳂==
function definition
function Start-bouncingball {
setting the dimensions of the animation area
$width = 20
$height = 10
variables for the ball's position ($ballX, $ballY) and direction of movement ($directionX, $directionY)
$ballX = 1
$ballY = 1
$directionX = 1
$directionY = 1
clear the console
Clear-Host
animation loop (until ctrl+c)
while ($true) {
cleat the console again to update the animation
  Clear-Host
appareance of the bouncing ball, nested loop. -le comparison operator (output $true or $false).
for ($y = 1; $y -le $height; $y++) {
    for ($x = 1; $x -le $width; $x++) {
        if ($x -eq $ballX -and $y -eq $ballY) {
            Write-Host -NoNewline "O"
        } else {
            Write-Host -NoNewline "."
        }
    }
    Write-Host ""  # Newline
}
frammentiamo: <br>
this first line is the outer loop, that control the vertical position.
for ($y = 1; $y -le $height; $y++) {
the inner loop (horizontal position)
for ($x = 1; $x -le $width; $x++) {
conditional statement that check the position both in $x and $y, and if they match it prints the character "O", if not it prints a period. -NoNewline the same as before, to ensure that the characters are printed on the same line.
if ($x -eq $ballX -and $y -eq $ballY) {
    Write-Host -NoNewline "O"
} else {
    Write-Host -NoNewline "."
}
writing a Newline, an empty string
Write-Host "" 
update the position of the ball
$ballX += $directionX
$ballY += $directionY
check if the ball has reached the boundaries of the area, if so it reverse the direction of movement to simulate the bouncing. * for the negative values.
if ($ballX -eq 1 -or $ballX -eq $width) {
    $directionX *= -1
}
if ($ballY -eq 1 -or $ballY -eq $height) {
    $directionY *= -1
}
pause for the animation frame, the speed of the ball
Start-Sleep -Milliseconds 100
  }
}
start animation
Start-bouncingball

Revision as of 00:56, 28 December 2023

Python


https://runestone.academy/ns/books/published/thinkcspy/index.html

Python ASCII


https://pypi.org/project/keyboard/

Blender Python scripting


Python API documentation: https://docs.blender.org/api/current/

A set of rules and tools to let software applications communicate with each other, it defines the methods that apps use to exchange data.
API Application Programming Interface
https://www.youtube.com/watch?v=ByGJQzlzxQg&ab_channel=AaronJack
UI to the user, API for the code. Log in —- UI —- Front End —- API —- Back End
++++Enable Developer Extra and Python Tooltips!++++
The Python Console has autocompletion

The Blender Python API can’t create Blender data that exists outside the main Blender database (accessed through bpy.data)
bpy (Blender Python), there are some specific modules in Blender that may not be found in standard Python

Cheat Sheet
https://docs.blender.org/manual/en/dev/advanced/operators.html#bpy-ops-wm-operator-cheat-sheet

Shell scripting languages

powershell

https://learn.microsoft.com/en-us/training/modules/introduction-to-powershell/

Cmdlets:(pronounced commandlets) commands to perform tasks and operations. Building blocks for Powershell scripts and commands.

Get-Command

To filter the list, keep in mind the verb-noun naming standard for cmdlets. For example, in the Get-Random command, Get is the verb and Random is the noun. Use flags to target either the verb or the noun in the command you want. The flag you specify expects a value that's a string. You can add pattern-matching characters to that string to ensure you express that, for example, a flag's value should start or end with a certain string.

Get-Location / pwd 


Set-Location oppure cd (change directory)
dir / Get-ChildItem per vedere file in directory

(=ls)

Cd .. torna indietro di uno
Cls clear (doesn't affect the command history)

Open a text file with the default associated editor

Start-Process -FilePath "C:\Path\To\Your\Filename.extension"

To open the file with a specific application use the Verb parameter
“Edit” open the file with the default editor

Start-Process -FilePath "C:\Path\To\Your\Filename.extension" -Verb "Edit"

To open the file with a different application (example with visual studio code, “code” is the command to launch vscode)

Start-Process "code" -ArgumentList "C:\Path\To\Your\Filename.extension"

version of powershell

$PSVersionTable



automatic variables: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4



newrocker.png 【┘】



To set the timer duration (seconds)

$timerDuration = 30

to ask the user for the timer duration tho (second choice)

do {
    $timerInput = Read-Host "Enter timer duration in seconds"
} while (-not [System.Int32]::TryParse($timerInput, [ref]$timerDuration) -or $timerDuration -lt 0)

Display then a message when the timer starts

Write-Host "Timer running for $timerDuration seconds..."

Start the countdown. $i, i for index, the loop counter. -gt is to compare 2 numbers, comparison operator (greater than, it returns true or false). Start-Sleep for the delay to get the countdown effect. -NoNewline to not print different lines but just one- "r" escape sequence, carriage return character, to clear the current line in the console.

  for ($i = $timerDuration; $i -gt 0; $i--) {
    Write-Host -NoNewline "Time remaining: $i seconds... "
    Start-Sleep -Seconds 1
    Write-Host -NoNewline "`r"
}

Display a message when the timer has finished

Write-Host "The end!"

sound notification (da aggiungere dopo start the countdown)

[console]::beep()

oppure

[system.media.systemsounds]::beep.play()

magnific-chaos-personal-use-regular.png

function definition

function Start-bouncingball {

setting the dimensions of the animation area

$width = 20
$height = 10

variables for the ball's position ($ballX, $ballY) and direction of movement ($directionX, $directionY)

$ballX = 1
$ballY = 1
$directionX = 1
$directionY = 1

clear the console

Clear-Host

animation loop (until ctrl+c)

while ($true) {

cleat the console again to update the animation

  Clear-Host

appareance of the bouncing ball, nested loop. -le comparison operator (output $true or $false).

for ($y = 1; $y -le $height; $y++) {
    for ($x = 1; $x -le $width; $x++) {
        if ($x -eq $ballX -and $y -eq $ballY) {
            Write-Host -NoNewline "O"
        } else {
            Write-Host -NoNewline "."
        }
    }
    Write-Host ""  # Newline
}

frammentiamo:
this first line is the outer loop, that control the vertical position.

for ($y = 1; $y -le $height; $y++) {

the inner loop (horizontal position)

for ($x = 1; $x -le $width; $x++) {

conditional statement that check the position both in $x and $y, and if they match it prints the character "O", if not it prints a period. -NoNewline the same as before, to ensure that the characters are printed on the same line.

if ($x -eq $ballX -and $y -eq $ballY) {
    Write-Host -NoNewline "O"
} else {
    Write-Host -NoNewline "."
}

writing a Newline, an empty string

Write-Host ""  

update the position of the ball

$ballX += $directionX
$ballY += $directionY

check if the ball has reached the boundaries of the area, if so it reverse the direction of movement to simulate the bouncing. * for the negative values.

if ($ballX -eq 1 -or $ballX -eq $width) {
    $directionX *= -1
}

if ($ballY -eq 1 -or $ballY -eq $height) {
   $directionY *= -1
}

pause for the animation frame, the speed of the ball

Start-Sleep -Milliseconds 100
  }
}

start animation

Start-bouncingball