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