Warning, /utilities/kweather/src/qml/backgrounds/components/Rain.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 ctx.moveTo(p.x, p.y); 0027 ctx.lineTo(p.x, p.y + p.l * p.ys); 0028 ctx.stroke(); 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 for (var a = 0; a < maxParts; a++) { 0057 init.push({ 0058 x: Math.random() * width, 0059 y: Math.random() * height, 0060 l: 2 + Math.random() * 4, 0061 ys: Math.random() * 10 + 10 0062 }) 0063 } 0064 0065 particles = []; 0066 for (var b = 0; b < maxParts; b++) { 0067 particles[b] = init[b]; 0068 } 0069 } 0070 }