對于這個草圖,我想讓星星的顏色略有不同,以模擬實際的星星不僅僅是純白光。我嘗試了幾種不同的方法來做到這一點,但沒有任何成功。你將如何做到這一點?
希望修改第一個fill(255)以從一組中以不同的顏色繪制每顆星。我嘗試使用大約 4 種顏色的陣列并訪問索引。我嘗試使用random()遠離 255 的幾個數字選擇 rgb 值。我對此很陌生,所以請原諒我缺乏適當的術語。我想我可能只是沒有將回圈通過陣列放在正確的位置。
完整代碼在這里。提前致謝!
function starsMoon() { //create star cluster and moon
randomSeed(300);
translate(-width * 2, -height * 2);
noStroke();
fill(255);
for (let i = 0; i < 300; i ) { // stars
// this is where I initially put the fill(colorSet[i])
ellipse(random(0,width * 4) i, random(0,height * 4) i, 2, 2);
}
fill(255);
ellipse(width * 1.25, height * 2, 100, 100); // moon
}
uj5u.com熱心網友回復:
是的,其中任何一個都可以!
隨機偏移:
function starsMoon() { //create star cluster and moon
randomSeed(300);
translate(-width * 2, -height * 2);
noStroke();
for (let i = 0; i < 300; i ) { // stars
fill(250 ((random() - 0.5) * 2 * 5)) // random fill between 245 - 255
ellipse(random(0,width * 4) i, random(0,height * 4) i, 2, 2);
}
fill(255);
ellipse(width * 1.25, height * 2, 100, 100); // moon
}
要從串列中旋轉顏色,您只需要使用索引 mod 顏色的數量:
function starsMoon() { //create star cluster and moon
randomSeed(300);
translate(-width * 2, -height * 2);
noStroke();
let colors = [
color(210, 180, 170),
color(40, 100, 29),
color(100, 100, 110),
color(102, 210, 12)
]
for (let i = 0; i < 300; i ) { // stars
fill(colors[i % colors.length]) // loop through colors
ellipse(random(0,width * 4) i, random(0,height * 4) i, 2, 2);
}
fill(255);
ellipse(width * 1.25, height * 2, 100, 100); // moon
}
順便說一句很酷的專案!
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/463682.html
上一篇:使用python從文本/javascript中提取資料
下一篇:SpringMvc集成測驗失敗
