我很想获得 https://coolors.co 的调色板的值产生。不幸的是,他们没有 API。
有没有一种方法,最好是使用 Javascript 在每次事件发生或我发送某种 GET 请求时获取颜色。
我没有服务器,只有 codepen 中的 P5js 草图。
有没有办法伪造一个 api 调用,这样我就可以在每次发生事情时得到一个数组或对象,并生成一个新的调色板。
在我在 codepen 中的草图中,每次在 mouseClicked 函数上单击 Canvas 时,我都想获得一个随机调色板。
笔:https://codepen.io/giorgiomartini/pen/aypWOB?editors=0010
function mouseClicked(){
background(color('hsl(185, 30%, 74%)'))
translate(width/2, height/2)
////////////////////////////////////////////////////////////////// amt initial range
const arrayOfRandomNumsOfFirstProbStepX = createArrayOfRandomNums(amtOfSpotsInFirstProb,startProbStep,firstProbStepX)
const arrayOfRandomNumsOfFirstProbStepY = createArrayOfRandomNums(amtOfSpotsInFirstProb,startProbStep,firstProbStepY)
const arrayOfRandomNumsOfSecondProbStepX = createArrayOfRandomNums(amtOfSpotsInSecondProb,startProbStep,secondProbStepX)
const arrayOfRandomNumsOfSecondProbStepY = createArrayOfRandomNums(amtOfSpotsInSecondProb,startProbStep,secondProbStepY)
//args => element, arrayOfRandomNumsOfProbStepX, arrayOfRandomNumsOfProbStepY, elmntSizeMin, elmntSizeMax, hue, sat, lightness
drawElmntsOnSomeProbabilityStep('ellipse', 3 ,arrayOfRandomNumsOfFirstProbStepX, arrayOfRandomNumsOfFirstProbStepY , 10, 80, 45, 68, 85, true)
drawElmntsOnSomeProbabilityStep('rect', 3 ,arrayOfRandomNumsOfSecondProbStepX, arrayOfRandomNumsOfSecondProbStepY, 5, 30, 212, 39, 90, true)
//linea(100,45)
}
谢谢
最佳答案
尝试创建代码来抓取 coolors.co 的内容并不容易,而且尝试这样做可能违反版权服务条款。
您可以联系 coolors.co 团队并直接询问他们。也许他们有您可以使用的 API,只是他们没有公开。
或者您可以找到另一个执行相同操作的 API。谷歌搜索“color palette generator api”会返回大量结果。
或者您可以自己编写。创建随机颜色非常容易,然后基于第一种颜色创建其他颜色。尝试使用您自己的程序,看看是否可以正常工作。
关于javascript - 如何在没有 API 的情况下获取 coolors 的值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45531756/