Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.qml
- import QtQuick 2.9
- import QtQuick.Window 2.2
- Window {
- id: mainwindow
- visible: true
- width: 1200
- height: 1000
- title: qsTr("Hello World")
- property variant punkty: [];
- Component.onCompleted: {
- spirala()
- }
- function isPrime(n) {
- var sn = Math.sqrt(n);
- for (var i = 2; i <= sn; i++) {
- if (!(n%i)) return false;
- }
- return true;
- }
- function liczbaPol(n) {
- var res = 9;
- var tmp = 16;
- for (var i = 2; i <= n; i++) {
- res += tmp;
- tmp += 8;
- }
- return res;
- }
- function spirala() {
- var x = 590;
- var y = 490;
- var ds = 20;
- var dx = 1;
- var dy = -1;
- var mx = true;
- var su = 0;
- var m = 1;
- var kl = 2, ki = 0, km = 0;
- var suma = 1;
- var lp = liczbaPol(20);
- var cp = 1, clp = 0;
- for (var j = 1, k = 0; j <= lp; j++) {
- punkty.push(Qt.createQmlObject('Rect { x: ' + x + '; y: ' + y + '; number: ' + j + ' }', mainwindow));
- if (ki >= kl) {
- cp++;
- if (isPrime(j)) {
- punkty[j-1].textColor = "red";
- clp++;
- }
- suma += j;
- ki = 0;
- km++;
- }
- ki++;
- if (km >= 4) {
- kl += 2;
- km = 0;
- }
- if (mx) x += dx*ds;
- else y += dy*ds;
- k++;
- if (k == m) {
- mx = !mx;
- su++;
- k = 0;
- }
- if (su == 2) {
- m++;
- dx *= -1;
- dy *= -1;
- su = 0;
- }
- }
- console.log(clp, '/', cp, ' ', Math.round((clp/cp)*100), '%');
- }
- }
- // Rect.qml
- import QtQuick 2.0
- Rectangle {
- id: root
- property int number
- property color borderColor: "transparent"
- property color textColor: "black"
- property int size: 20
- width: size;
- height: size;
- border.width: 1;
- border.color: borderColor;
- color: "transparent";
- Text {
- font.pointSize: 5
- color: textColor
- x: root.width/2 - width/2
- y: root.height/2 - height/2
- text: number
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement