Warning, /utilities/kweather/src/qml/backgrounds/components/Snow.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 import QtQuick 0008 import QtQuick.Layouts 0009 Canvas { 0010 id: mycanvas 0011 0012 property var particles: [] 0013 0014 renderStrategy: Canvas.Threaded 0015 onPaint: { 0016 var ctx = getContext("2d"); 0017 ctx.strokeStyle = 'rgba(255,255,255,0.5)'; 0018 ctx.lineWidth = 3; 0019 ctx.lineCap = 'round'; 0020 ctx.clearRect(0, 0, width, height); 0021 0022 function draw() { 0023 for (var c = 0; c < particles.length; c++) { 0024 var p = particles[c]; 0025 ctx.beginPath(); 0026 context.arc(p.x, p.y + p.ys, p.l, 0, 2 * Math.PI, false); 0027 context.fillStyle = Qt.rgba(255,255,255,p.a); 0028 context.fill(); 0029 } 0030 move(); 0031 } 0032 0033 function move() { 0034 for (var b = 0; b < particles.length; b++) { 0035 var p = particles[b]; 0036 p.y += p.ys; 0037 if (p.x < 1 || p.x > width || p.y > height) { 0038 p.x = Math.random() * width; 0039 p.y = -20; 0040 } 0041 } 0042 } 0043 draw(); 0044 } 0045 Timer { 0046 id: animationTimer 0047 interval: 16 0048 running: true 0049 repeat: true 0050 onTriggered: parent.requestPaint() 0051 } 0052 0053 Component.onCompleted: { 0054 var init = []; 0055 var maxParts = 80; 0056 0057 for (var a = 0; a < maxParts; a++) { 0058 init.push({ 0059 x: Math.random() * width, 0060 y: Math.random() * height, 0061 l: 5 + Math.random() * 10, 0062 ys: Math.random(), 0063 a: 0.4 + Math.random() * 0.6 0064 }) 0065 } 0066 0067 particles = []; 0068 for (var b = 0; b < maxParts; b++) { 0069 particles[b] = init[b]; 0070 } 0071 } 0072 }