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

From XPUB & Lens-Based wiki
No edit summary
Line 49: Line 49:
https://media.giphy.com/media/cJXx8C2rucjl5PKhfp/giphy.gif
https://media.giphy.com/media/cJXx8C2rucjl5PKhfp/giphy.gif
https://media.giphy.com/media/urjwVjzklAtR1DFqN6/giphy.gif
https://media.giphy.com/media/urjwVjzklAtR1DFqN6/giphy.gif
<br>
python > frames > jpg > blender <br>
> svg > pen plotter <br>


=Shell scripting languages=
=Shell scripting languages=

Revision as of 12:00, 23 February 2024

Python


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

Python ASCII


https://pypi.org/project/keyboard/
Inspired by Victor Barthel
+ mandelbrot
+https://github.com/kpberry/image-to-ascii
NumPy: Numerical Python, library, numerical data, multidimensional array

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

Open Shading Language

C syntax
creating nodes that work with CPU and Optix rendering.
Cell, Simplex and Gabor as denoiser don't work.
Ambient occlusion and bevel nodes don't work either.

https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/blob/main/src/doc/osl-languagespec.pdf

maze generator #2

https://github.com/topics/maze-generator?l=python
https://github.com/john-science/mazelib/blob/main/docs/EXAMPLES.md
https://github.com/john-science/mazelib
https://github.com/john-science/mazelib/blob/main/docs/MAZE_GEN_ALGOS.md

mini pen plotted flipbooks

giphy.gif giphy.gif
python > frames > jpg > blender
> svg > pen plotter

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



easy timer 【┘】


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()

bouncing ball animation ᳂

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 "" 
}

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


spinner \

$spinnerChars contains the characters, while ($true) for the loop, foreach it iterates each character in the spinner set, "`b" is used to move the cursor back.

function Start-Spinner {
    $spinnerChars = @('/', '-', '\', '|')
    $delayMilliseconds = 100

    while ($true) {
        foreach ($char in $spinnerChars) {
            Write-Host -NoNewline $char
            Start-Sleep -Milliseconds $delayMilliseconds
            Write-Host -NoNewline "`b" 
        }
    }
}
Start-Spinner

bouncing horizontal text

function Start-bouncingtext {
    $text = "text"
    $width = 50
    $delayMilliseconds = 100
   
    $position = 1
    $direction = 1
    
    while ($true) {
        Clear-Host

calculate the padding on each side

$padding = " " * ($width - $position)

display the text at the current position

Write-Host -NoNewline "$padding$text"

animation speed - pauses

Start-Sleep -Milliseconds $delayMilliseconds

update the animation

Write-Host -NoNewline "`r"

update position based on direction

$position += $direction

check boundaries and direction reversed

if ($position -eq 1 -or $position -eq ($width - [string]$text.Length + 1)) {
            $direction *= -1
        }
    }
} 
Start-bouncingtext


blinking text animation

function Start-blinkingtext {
    $text = "Sleep!"
    $delayMilliseconds = 500

    while ($true) {
        Clear-Host

        Write-Host $text
        
        Start-Sleep -Milliseconds $delayMilliseconds

        Clear-Host

        Start-Sleep -Milliseconds $delayMilliseconds
    }
}
Start-blinkingtext

random character magic

per colore casuale dei caratteri:

$colors = @("Red", "Yellow", "Green", "Cyan", "Blue", "Magenta")
$randomColor = $colors | Get-Random


function Start-randomcharacter {
    $width = 20
    $height = 20
    $delayMilliseconds = 100

    while ($true) {
        Clear-Host

        $randomX = Get-Random -Minimum 1 -Maximum $width
        $randomY = Get-Random -Minimum 1 -Maximum $height
        $randomCharacter = [char](Get-Random -Minimum 33 -Maximum 127)

display the random character at a random position + color of the character and background

        Write-Host -NoNewline "`r"
        $colors = @("Red", "Yellow", "Green", "Cyan", "Blue", "Magenta")
        $randomColor = $colors | Get-Random
        Write-Host "$randomCharacter" -ForegroundColor  $randomColor -BackgroundColor Black -NoNewline
        Start-Sleep -Milliseconds $delayMilliseconds
    }
}

Start-randomcharacter

3d

🕸️cobweb geometry nodes🕸️

needs objects to interect with in the scene
create different collection, one must be of the scene (you need to add it easily as a node)
the beziercurve, need to be out of the collection. Drawing tool

🕷 resample curve: to let the curve not stick onto the surface, count to 2
🕷 curve to mesh: makes the line thicker
🕷 curve circle: resolution to 3, radius around .005
🕷 instances on points: (makes data disappears) add lines attached to the main lines
vjoin geometry node, great!

🕷 (node wrangler reminder = easy connect: shift+rmb, draw the connection: alt+rmb)

🕷 to control a value: to get it easier in the mess, control through modifiers tab, add input node connected from the grey circle to the value