Created
November 9, 2023 19:41
-
-
Save schnoddelbotz/8077dee2524d7dbc73f4ff99bdf98d14 to your computer and use it in GitHub Desktop.
Zahlenstrahl (number line) & Brüche (fractions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require('fpdf.php'); // from fpdf.org | |
function BruchZahlenStrahl($pdf, $yOff) { | |
$yBase = 2; | |
$lnX1 = 20; | |
$lnX2 = 200; | |
$lineLength = $lnX2 - $lnX1; | |
$lnY = $yOff * 14 + $yBase; | |
$pdf->SetFont('Arial','',11); | |
$pdf->Text($lnX1-10,$lnY, $yOff); | |
$pdf->Line($lnX1, $lnY, $lnX2, $lnY); | |
for ($part=0; $part<=$yOff; $part++) { | |
$xPos = $lnX1 + ($part / $yOff) * $lineLength; | |
$pdf->Line($xPos, $lnY-1, $xPos, $lnY+1); | |
if ($part == 0 || $part == $yOff) { | |
$pdf->SetFont('Arial','',10); | |
$pdf->Text($xPos-1, $lnY-3, $part / $yOff); | |
continue; | |
} | |
// Bruch | |
$pdf->SetFont('Arial','',9); | |
$pdf->Text($xPos-($part>9?2:1), $lnY-6, "$part"); | |
$pdf->Line($xPos-2, $lnY-5, $xPos+2, $lnY-5); | |
$pdf->Text($xPos-($yOff>9?2:1), $lnY-2, "$yOff"); | |
// Dezimal | |
$pdf->SetFont('Arial','',8); | |
$pdf->Text($xPos-3.5, $lnY+4, sprintf("%.3f", $part / $yOff)); | |
} | |
} | |
$pdf = new FPDF('P','mm','A4'); | |
$pdf->AddPage(); | |
for ($i=1; $i<21; $i++) { | |
BruchZahlenStrahl($pdf, $i); | |
} | |
$pdf->Output('F', 'zahlenstrahl.pdf'); |
Author
schnoddelbotz
commented
Nov 9, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment