美文网首页
2018-12-01

2018-12-01

作者: MarkZJUNLICT | 来源:发表于2018-12-01 18:10 被阅读0次
WIDTH = 22440
WALL = [            \
    (+6400+150,+200),   \
    (+1100,+150),   \
    (+3127,+150),   \
    (+4438,+150),   \
    (+2594,+104),   \
    (+2145,+104),   \
    ]
CHECK = []
WINDOW_LENGTH_MIN = 800 # 1000-infinite
WINDOW_LENGTH_MAX = 1100
WINDOW_SEP_MIN = 10
WINDOW_SEP_MAX = 2000
WINDOW_SIDE_MIN = 0
WINDOW_SIDE_MAX = 2000
WINDOW_COUNT_MIN = 5 # 7-10 
WINDOW_COUNT_MAX = 20
WINDOW_SIDE_LENGTH = 0

STEP = 10

x = 0
for a in WALL:
    sep,length = a
    start = sep + x
    x = end = start + length
    CHECK.append(start)
    CHECK.append(end)

print(CHECK)

# l  : window length
# se : window seperate length
# si : window side length
# c  : window count 
def groupGen():

    l = WINDOW_LENGTH_MIN
    while l < WINDOW_LENGTH_MAX:
        l += STEP
        se = WINDOW_SEP_MIN
        while se < WINDOW_SEP_MAX:
            se += STEP
            c = WINDOW_COUNT_MIN - 1
            while c <= WINDOW_COUNT_MAX:
                c += 1
                si = (WIDTH - (c*l+(c-1)*se))/2;
                if si > WINDOW_SIDE_MIN and si < WINDOW_SIDE_MAX:
                    yield l,se,c,si
    return 'done'

for l,se,c,si in groupGen():
    # print(l,se,c,si)
    check = True
    start = si
    end = start + l
    for i in range(c):
        start = si + (l+se)*i
        end = start + l
        for checkPoint in CHECK:
            if checkPoint > start and checkPoint < end :
                check = False
                break
        if not check:
            break
    if check:
        print(l,se,c,si)
import QtQuick 2.9
import QtQuick.Window 2.2

Window {
    id : r
    visible: true
    width: 1920
    height: 480
    title: qsTr("Hello World")
    property int ratio         : 12
    property int window_length : 973    / r.ratio;
    property int window_sep    : 1598   / r.ratio;
    property int window_side   : 1735   / r.ratio;
    property int window_count  : 8

    property int window_length2 : 970    / r.ratio;
    property int window_sep2    : 1600   / r.ratio;
    property int window_side2   : 1740   / r.ratio;
    property int window_count2  : 8
    Repeater{
        model : [6550, 6750, 7850, 8000, 11127, 11277, 15715, 15865, 18459, 18563, 20708, 20812]
        Rectangle{
            y : 0
            x : modelData/r.ratio;
            width:1;
            height:300;
            color:"red";
        }
    }
    Repeater{
        model:r.window_count;
        Rectangle{
            y : 200;
            x : r.window_side + (r.window_length+r.window_sep)*index;
            height : 10;
            width:r.window_length;
            color:"green";
        }
    }
    Repeater{
        model:r.window_count2;
        Rectangle{
            y : 250;
            x : r.window_side2 + (r.window_length2+r.window_sep2)*index;
            height : 10;
            width:r.window_length2;
            color:"green";
        }
    }
}

import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.3
Window {
    id : r
    visible: true
    width: 1920
    height: 1060
    title: qsTr("Hello World")
    property int total_width   : 22440
    property int ratio         : 12
    property int window_length : windowLength.value    / r.ratio;
    property int window_sep    : windowSep.value   / r.ratio;
    property int window_side   : (total_width - (windowCount.value*windowLength.value+(windowCount.value-1)*windowSep.value))/2   / r.ratio;
    property int window_count  : windowCount.value

    property int window_length2 : 970    / r.ratio;
    property int window_sep2    : 1600   / r.ratio;
    property int window_side2   : 1740   / r.ratio;
    property int window_count2  : 8
    Rectangle{
        width:total_width/r.ratio;
        height:300;
        color:'grey';
        opacity: 0.2;
    }

    Repeater{
        model : [6550, 6750, 7850, 8000, 11127, 11277, 15715, 15865, 18459, 18563, 20708, 20812]
        Rectangle{
            y : 0
            x : modelData/r.ratio;
            width:1;
            height:300;
            color:"yellow";
        }
    }
    Repeater{
        model:r.window_count;
        Rectangle{
            y : 200;
            x : r.window_side + (r.window_length+r.window_sep)*index;
            height : 10;
            width:r.window_length;
            color:"green";
            onWidthChanged: {
                var array = [6550, 6750, 7850, 8000, 11127, 11277, 15715, 15865, 18459, 18563, 20708, 20812]
                var red = false
                color='green'
                for(var i=0;i<array.length;i++){
                    var value = array[i]/r.ratio;
                    if(x < value && x+width > value){
                        red = true;
                        break;
                    }
                }
                color=red?'red':'green';
            }
            onXChanged: {
                var array = [6550, 6750, 7850, 8000, 11127, 11277, 15715, 15865, 18459, 18563, 20708, 20812]
                var red = false
                color='green'
                for(var i=0;i<array.length;i++){
                    var value = array[i]/r.ratio;
                    if(x < value && x+width > value){
                        red = true;
                        break;
                    }
                }
                color=red?'red':'green';
            }
        }
    }
//    Repeater{
//        model:r.window_count2;
//        Rectangle{
//            y : 250;
//            x : r.window_side2 + (r.window_length2+r.window_sep2)*index;
//            height : 10;
//            width:r.window_length2;
//            color:"green";
//        }
//    }
    Grid{
        y:320;
        width:600;
        height:400;
        columns:2;
        columnSpacing: 0;
        property int itemWidth : width/columns;
        Button{
            text:"Window Length : " + parseInt(windowLength.value);
            width:parent.itemWidth;
        }
        Slider{
            id:windowLength;
            width:parent.itemWidth;
            from:500;
            to:2000;
        }
        Button{
            text:"Window Sep   : " + parseInt(windowSep.value);
            width:parent.itemWidth;
        }
        Slider{
            id:windowSep;
            width:parent.itemWidth;
            from:800;
            to:2000;
        }
        Button{
            text:"Window Count"
            width:parent.itemWidth;
        }
        SpinBox{
            id:windowCount;
            width:parent.itemWidth;
            from:8;
            to:20;
        }
    }
}

> python [filename.py]
> qmlscene [filename.qml]

相关文章

网友评论

      本文标题:2018-12-01

      本文链接:https://www.haomeiwen.com/subject/layrcqtx.html