From: giersch Date: Thu, 8 Nov 2007 12:13:42 +0000 (+0000) Subject: . X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/commitdiff_plain/9484593b069d6b2fd81b364537706d2295410099 . --- diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/exemple.cpp b/exemple.cpp new file mode 100644 index 0000000..ce402e5 --- /dev/null +++ b/exemple.cpp @@ -0,0 +1,104 @@ +/* + * Pour compiler + * ============= + * + * 1. Créer le fichier hello.pro : + * +------------------------------------------------------------+ + * |TARGET = hello | + * |CONFIG += qt debug | + * |SOURCES += hello.cc | + * +------------------------------------------------------------+ + * + * 2. Créer le fichier Makefile avec la commande : + * $ qmake -makefile hello.pro + * ou tout simplement : + * $ qmake -makefile + * + * 3. Compiler avec la commande : + * $ make hello + * ou tou simplement : + * $ make + */ + + +#include +#include +#include +#include + +float frand() +{ + return rand() / (float )RAND_MAX; +} + +void exemple1(DrawingWindow &w) +{ + const int cx = w.width / 2; + const int cy = w.height / 2; + const int delta = 5; + for (int x = 0; x < w.width; x += delta) { + w.drawLine(cx, cy, x, 0); + w.drawLine(cx, cy, w.width - 1 - x, w.height - 1); + } + for (int y = 0; y < w.height; y += delta) { + w.drawLine(cx, cy, 0, w.height - 1 - y); + w.drawLine(cx, cy, w.width - 1, y); + } +} + +void exemple2(DrawingWindow &w) +{ + int width = std::min(w.width, w.height) / 2; + for (int z = 0; z <= width; z++) { + float r, g, b; + float s = 3.0 * z / width; + if (z <= width / 3.0) { + r = 1.0 - s; + g = s; + b = 0.0; + } else if (z <= 2.0 * width / 3.0) { + s -= 1.0; + r = 0.0; + g = 1.0 - s; + b = s; + } else { + s -= 2.0; + r = s; + g = 0.0; + b = 1.0 - s; + } + w.setColor(r, g, b); + w.drawRect(z, z, w.width - 1 - z, w.height - 1 - z); + } +} + +void exemple3(DrawingWindow &w) +{ + while (1) { + int x1 = rand() % w.width; + int y1 = rand() % w.height; + int x2 = rand() % w.width; + int y2 = rand() % w.height; + w.setColor(frand(), frand(), frand()); + w.drawLine(x1, y1, x2, y2); + w.sync(); + } +} + +int main(int argc, char *argv[]) +{ + QApplication application(argc, argv); + DrawingWindow window1(exemple1, 640, 480); + DrawingWindow window2(exemple2, 640, 480); + DrawingWindow window3(exemple3, 640, 480); + + window1.setWindowTitle("Exemple 1"); + window2.setWindowTitle("Exemple 2"); + window3.setWindowTitle("Exemple 3"); + + window1.show(); + window2.show(); + window3.show(); + + return application.exec(); +} diff --git a/exemple.pro b/exemple.pro new file mode 100644 index 0000000..cdcca93 --- /dev/null +++ b/exemple.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = exemple + +CONFIG += qt +CONFIG += debug + +HEADERS += DrawingWindow.h +SOURCES += DrawingWindow.cpp + +SOURCES += exemple.cpp