-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai.svgdraw.cpp
39 lines (31 loc) · 1.5 KB
/
ai.svgdraw.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <fstream>
#include <cstdlib>
#include <ctime>
int main() {
// Initialize random number generator.
std::srand(std::time(0));
// Generate random coordinates.
int x1 = std::rand() % 100;
int y1 = std::rand() % 100;
int x2 = std::rand() % 100;
int y2 = std::rand() % 100;
// Open SVG file.
std::ofstream file("output.svg");
// Write SVG header.
file << "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"100\" height=\"100\">\n";
// Write line element with random coordinates.
file << "<line x1=\"" << x1 << "\" y1=\"" << y1 << "\" x2=\"" << x2 << "\" y2=\"" << y2
<< "\" style=\"stroke:rgb(0,0,0);stroke-width:2\" />\n";
// Write SVG footer.
file << "</svg>\n";
// Close SVG file.
file.close();
return 0;
}
/*
This program generates random coordinates for the line and writes an SVG file with a line element that uses these coordinates. The SVG file can then be included in an HTML page using the <img> tag:
HTML
<img src="output.svg" alt="Random line">
*/
// Also, please note that this program does not check if the SVG file was opened successfully.
// Please note that this program does not get entropy from the host system peripherals like mouse, keyboard, trackpad or joysticks. Accessing these peripherals directly from a C++ program is not straightforward and typically requires platform-specific code or third-party libraries. Also, using these peripherals as a source of entropy might not be reliable or secure.