Browse Source

Added Visual Code

master
Graeme Dyas 4 months ago
parent
commit
cdd876cc85
  1. 29
      Day 11/Part_1.php
  2. 13
      Day 11/Part_2.php
  3. 68
      Day 11/func.php
  4. 4
      Day 11/img/makegif.sh

29
Day 11/Part_1.php

@ -1,4 +1,5 @@
<?php
include_once "./func.php";
function get_foramt_data($fn)
{
@ -52,7 +53,7 @@ function get_neighbors($grid, $x, $y)
if (check_neighbors_exist($grid, $x + 1, $y + 1)) {
array_push($ret, $grid[$y + 1][$x + 1]);
}
return $ret;
}
@ -109,10 +110,19 @@ function ppp($indata)
}
$data = get_foramt_data("input.txt");
while(true) {
$x = 0;
while (true) {
$new = ppp($data);
if (!($x % 2)) {
$xs = (string)$x;
while (strlen($xs) < 5) {
$xs = "0" . $xs;
}
make_img($new, "./img/" . $xs . ".png");
}
$old = $data;
$data = $new;
@ -120,14 +130,15 @@ while(true) {
$n = implode("", $n);
}
$new = implode("\n", $new);
foreach ($old as &$o) {
$o = implode("", $o);
}
$old = implode("\n", $old);
if ($old == $new) {
echo substr_count($new,"#"). "\n";
die();
}
}
if ($old == $new) {
echo substr_count($new, "#") . "\n";
die();
}
$x++;
}

13
Day 11/Part_2.php

@ -1,4 +1,5 @@
<?php
include_once "./func.php";
function get_foramt_data($fn)
{
@ -252,10 +253,19 @@ function ppp($indata)
}
$data = get_foramt_data("input.txt");
$x = 0;
while(true) {
$new = ppp($data);
if ($x % 2) {
$xs = (string)$x;
while (strlen($xs) < 5) {
$xs = "0" . $xs;
}
make_img($new, "./img/" . $xs . ".png");
}
$old = $data;
$data = $new;
@ -275,4 +285,5 @@ while(true) {
echo substr_count($new,"#"). "\n";
die();
}
$x++;
}

68
Day 11/func.php

@ -0,0 +1,68 @@
<?php
function make_img($data, $outfile)
{
$img_width = 981;
$img_height = 931;
$img = imagecreatetruecolor($img_width, $img_height);
$black = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 255, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
$blue = imagecolorallocate($img, 0, 0, 255);
$white = imagecolorallocate($img, 255, 255, 255);
$pink = imagecolorallocate($img, 255, 100, 100);
imagefill($img, 0, 0, $white);
$sf = 10;
foreach ($data as $y => $a) {
foreach ($a as $x => $val) {
$xa = (10 + ($x * 100)) / $sf;
$ya = (10 + ($y * 100)) / $sf;
switch ($val) {
case ".":
$color = imagecolorallocate($img, 255, 255, 255);
break;
case "#":
$color = imagecolorallocate($img, 0, 0, 255);
$full = true;
break;
case "L":
$color = imagecolorallocate($img, 0, 0, 255);
$full = false;
break;
}
if ($full) {
imagefilledrectangle(
$img,
$xa,
$ya,
$xa + 80 / $sf,
$ya + 80 / $sf,
$color
);
} else {
imagerectangle(
$img,
$xa,
$ya,
$xa + 80 / $sf,
$ya + 80 / $sf,
$color
);
}
}
}
imagepng($img,$outfile);
}

4
Day 11/img/makegif.sh

@ -0,0 +1,4 @@
#!/bin/bash
convert -delay 20 -loop 1 *.png myimage.gif
rm *.png
ffmpeg -i myimage.gif -movflags faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" video.mp4
Loading…
Cancel
Save