javascript - 如何在没有 API 的情况下获取 coolors 的值(value)

标签 javascript api p5.js

我很想获得 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/

相关文章:

javascript - Sails.js REST Api 验证

web-services - REST 数组操作最佳实践

api - Magento API 中 msrp_display_actual_price_type 的可能值

javascript - 如何在 p5.js 中旋转图像

javascript - Angular js ng-repeat 和过滤器

javascript - 如何倾斜 div 的一侧,然后复制它并倾斜另一侧?

javascript - 通过属性获取MongoDB中存储的数组

api - Instagram API - 用户照片

javascript - p5.j​​s 中的碰撞处理

javascript - 在闭包 JavaScript 中分配变量