Keyboard → T-shirt

Workshop HfG Novembre 28 2022

The starter kit

How to use the starter kit ?

Installation

Dependencies

You need a local PHP server to run the program

On OSX and Linux

On Windows

Documentation

Keyboard events

The starter kit has some functions include for demo. All functions are fired by a keypress.

App architecture

Add / remove medias

Markdown memo

# Big Title (h1)
## Sub Title (h2)
### Sub Sub Title (h3)
#### Sub Sub Sub Title (h4)
#### Sub Sub Sub Sub Title (h5)
*Italic*
**Bold**

PHP functions

getListFile(nameOfDirectory)

The getListFile() function list all the files in a specific directory

Usage Examples

Files structure example :

medias
      - text.txt
      - image.png
      - youpi.png
      

PHP usage :

$mediaslist = getListFile('medias');
      echo "<ul class='medias-list'>";
      // loop throught each media from "medias" directory
      foreach($mediaslist as $file){
        // check for the extension of the file to detect the type of media
        $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
        // if the media is an image, display it as image in html
        if($ext == 'jpg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpeg' || $ext == 'JPG'){
          // get the file path
          $filePath = $file['name'];
          // add the image in html in the list
          echo "<li class='image'>";
          echo "<figure>";
          echo "<img src='{$filePath}'/>";
          echo "</figure>";
          echo "</li>";
        }
        // if the media is text, display it as text in html
        if($ext == 'txt'){
          // get file content 
          $content = file_get_contents($file['name']);
          // add the text in html in the list
          echo "<li class='text'>";
            // convert the markdown content to html
            echo $Parsedown->text($content);
          echo "</li>";
        }
      }
      echo "</ul>";
      

getFolderList(nameOfDirectory)

The getFolderList() function list all the folders in a specific directory

Usage Example

Files structure example :

medias
      - dossier-1
        + text.txt
        + image.png
        + youpi.png
      - dossier-2
        + text-test.txt
        + image-test.png
        + youhou.png
      

PHP usage :

// add all folders from "medias" directory in $folderlist array
      $folderlist = getFolderList("medias");
      // loop throught each folders from "medias" directory
      foreach($folderlist as $folder){
        echo "<ul>";
        // add all medias from current folder in $filelist array
        $filelist = getFileList($folder);
        // loop throught each media from current folder
        foreach($filelist as $file){
          $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
          // if the media is an image, display it as image in html
          if($ext == 'jpg' || $ext == 'png' || $ext == 'gif' || $ext == 'jpeg' || $ext == 'JPG'){
            // get the file path
            $filePath = $file['name'];
            // add the image in html in the list
            echo "<li class='image'>";
            echo "<figure>";
            echo "<img src='{$filePath}'/>";
            echo "</figure>";
            echo "</li>";
          }
          // if the media is text, display it as text in html
          if($ext == 'txt'){
            // get file content 
            $content = file_get_contents($file['name']);
            // add the text in html in the list
            echo "<li class='text'>";
              // convert the markdown content to html
              echo $Parsedown->text($content);
            echo "</li>";
          }
        }
        echo "</ul>";
      }
      

JS functions

getRandomColor()

Use the getRandomColor() function to generate a random color in HEX

var randomColor = getRandomColor();
      $('.teeshirt').css('background', randomColor);
      

getRandomInt(min, max)

Use the getRandomInt(min, max) function to generate a integer number between a min and a max number

var randomNumber = getRandomInt(10, 100);
      $('.medias-list img').css('max-height', randomNumber + "px");
      

License

GPL v.3