SDL2 example
[mirrors/Programs.git] / php / skripty / lomena.php
1 <?php
2 //This will draw the ASCII neverending sinus curve.
3 //Writen by (c) Harvie in 2oo6
4 //This is script for PHP CLI (Not WebPage).
5 //You can port it to web by replacing "/n" by "<br>/n"
6
7 //Settings:
8 $start = -3; //0 //First X
9 $zero = 0; //Zero line
10 $stop = 0.5; //Last X
11 $step = 0.1; //0.1 //Increase X on every line by this number
12 $reset = "0"; //When X >= reset, then it will be reseted to $resetto (use "" to disable reset).
13 $resetto = "0.1"; //$resetto
14 $zoom = 1; //1 //This will repeat every line few times
15 $sleep = "15000"; //15000 - Wait between lines in microseconds
16 $line = (" "); // " " // ":" //chr ( 176 ) //This is the string, that will be repeated from display start to the curve (curve inlay).
17 $endline = ("+\n"); // "#\n" // ".\n" //chr ( 219 )."\n" //This is the string, that will be printed at end of every line (curve outline).
18
19 //Function:
20 //You can specify your function here:
21 function func($x) {
22
23 $offset = 20; //1.1 //1 //0 -> Zero offset will draw only half of sin curve.
24 $width = 1; //20 //35 //40 //This will stretch every line.
25
26 $y = ( ( (3 / $x) + $offset) * $width );
27 //echo("Debug: ".$x." ".$y." "); //Debug
28 return ($y);
29
30 }
31
32 //Code:
33 echo ("[SinusCurve]-[c][Harvie][2oo6]\n\n");
34 echo (" | y\n");
35 echo ("-|--------------------------------------------->\n");
36 echo ("x|\n");
37 echo (" V\n\n");
38
39 sleep(2);
40
41 //Set x to $start:
42 $pos = $start;
43
44 //Drawing:
45 while(1) {
46
47 //usleep($sleep); //Wait in microseconds
48
49 $znaku = func($pos);
50
51 $zoom2 = $zoom;
52 while ($zoom2 > 0) {
53
54 $znaku2 = round($znaku); //It looks better after round ;)
55 while ($znaku2 > 0) {
56 echo $line;
57 $znaku2 = ($znaku2 - 1);
58 }
59 //echo(" ".$pos); //Debug
60 echo ($endline);
61
62 $zoom2 = ($zoom2 - 1);
63 }
64
65 //Draw: Y axis:
66 //echo(" ".$pos."\n"); //Debug
67 if ($pos == $zero) {
68 echo("-+------------------------------------------------------------>\n");
69 }
70
71 //Increase X:
72 $pos = ($pos + $step);
73
74 //Reset (for neverending curves, etc...):
75 if ( ($pos >= $reset) && ($reset != "") ) {
76 $pos = $resetto;
77 }
78
79 //Stop if $stop is reached:
80 if ($pos > $stop) {
81 die();
82 }
83
84 }
85 ?>
This page took 0.286026 seconds and 4 git commands to generate.