“2024.12.25” by ty
https://openprocessing.org/sketch/2496385
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
CC Attribution NonCommercial ShareAlike
2024.12.25
xxxxxxxxxx
let layers; // 樹層數量
let gifts = [];
let message;
let messages = [
"Merry Christmas! 🎄",
"Wishing you joy and peace! 🎅",
"Have a magical holiday season! ✨",
"Let it snow, let it glow! ❄️",
"Ho Ho Ho, Happy Holidays! 🎁"
];
let lights = []; // 燈泡位置與顏色
let heightIncrement = 50;
function setup() {
createCanvas(400, 450);
frameRate(60); // 設定每秒60幀
layers = int(random(1, 6)); // 隨機樹層數
message = random(messages); // 隨機祝福語
noStroke(); // 預設無邊框
// 初始化禮物
gifts = [];
let numGifts = int(random(3, 15));
for (let i = 0; i < numGifts; i++) {
let giftX;
// 隨機選擇左側或右側放置禮物
if (random(1) < 0.5) {
giftX = random(0, 180); // 樹幹左側
} else {
giftX = random(220, 400); // 樹幹右側
}
gifts.push({
x: giftX,
y: random(350, 370),
color: color(random(255), random(255), random(255)) // 隨機顏色
});
}
// 初始化燈泡,數量與樹層數相關
lights = [];
for (let i = 0; i < layers; i++) {
let layerLights = int(random(5, 10)); // 每層 5 到 10 顆燈
let baseY = 350 - (i + 1) * heightIncrement; // 每層的底部 Y
let topY = 350 - (i + 2) * heightIncrement; // 每層的頂部 Y
let leftX = 200 - (i + 1) * 40; // 每層的左邊界 X
let rightX = 200 + (i + 1) * 40; // 每層的右邊界 X
for (let j = 0; j < layerLights; j++) {
lights.push({
x: random(leftX, rightX), // 燈泡在該層範圍內的隨機 X
y: random(topY, baseY) // 燈泡在該層範圍內的隨機 Y
});
}
}
}
function draw() {
background(0); // black色背景
// 畫樹層(最上層最小,最下層最大)
fill(34, 139, 34);
for (let i = 0; i < layers; i++) {
let baseY = 350 - (i + 1) * heightIncrement;
let topY = 350 - (i + 2) * heightIncrement;
let leftX = 200 - (i + 1) * 40;
let rightX = 200 + (i + 1) * 40;
triangle(200, topY, leftX, baseY, rightX, baseY);
}
// 畫樹幹
fill(139, 69, 19);
rect(180, 300, 40, 100);
// 畫燈泡(帶毛邊)
for (let light of lights) {
fill(
255 * abs(sin(frameCount * 0.1 + light.x)), // R
255 * abs(sin(frameCount * 0.1 + light.y)), // G
255 * abs(sin(frameCount * 0.1)) // B
);
ellipse(light.x, light.y, 10, 10);
fill(255, 255, 255, 100); // 毛邊效果
ellipse(light.x, light.y, 15, 15);
}
// 畫禮物(帶框線)
for (let gift of gifts) {
stroke(0); // 黑色框線
strokeWeight(1);
fill(gift.color);
rect(gift.x, gift.y, 30, 20); // 主體
noStroke();
fill(255); // 裝飾條
rect(gift.x + 12, gift.y, 6, 20); // 垂直裝飾
rect(gift.x, gift.y + 8, 30, 4); // 水平裝飾
fill(255, 215, 0); // 禮物上的小蝴蝶結
ellipse(gift.x + 15, gift.y, 10, 10);
}
// 顯示祝福語
fill(0); // 黑色字體
textAlign(CENTER);
textSize(16);
textFont("Courier"); // 使用 Courier 字體
text(message, width / 2, height - 10);
}
See More Shortcuts