color

def setup
  background(220)
  c = color(255, 204, 0)
  fill(c)
  noStroke
  rect(30, 20, 55, 55)
end
def setup
  background(220)
  c = color(255, 204, 0)
  fill(c)
  noStroke
  ellipse(25, 25, 80, 80)
  # Using only one value generates a grayscale value.
  c = color(65)
  fill(c)
  ellipse(75, 75, 80, 80)
end
def setup
  # You can use named SVG & CSS colors
  background(220)
  c = color('magenta')
  fill(c)
  noStroke
  rect(20, 20, 60, 60)
end
def setup
  # Example of hex color codes
  background(220)
  noStroke
  c = color('#0f0')
  fill(c)
  rect(0, 10, 45, 80)
  c = color('#00ff00')
  fill(c)
  rect(55, 10, 45, 80)
end
def setup
  background(220)
  noStroke
  c = color('rgb(0, 0, 255)')
  fill(c)
  rect(10, 10, 35, 35)
  c = color('rgb(0%, 0%, 100%)')
  fill(c)
  rect(55, 10, 35, 35)
  c = color('rgba(0, 0, 255, 1)')
  fill(c)
  rect(10, 55, 35, 35)
  c = color('rgba(0%, 0%, 100%, 1)')
  fill(c)
  rect(55, 55, 35, 35)
end
def setup
  # HSL color can also be specified by value
  background(220)
  c = color('hsl(160, 100%, 50%)')
  noStroke()
  fill(c)
  rect(0, 10, 45, 80)
  c = color('hsla(160, 100%, 50%, 0.5)')
  fill(c)
  rect(55, 10, 45, 80)
end
def setup
  # HSB color can also be specified
  background(220)
  c = color('hsb(160, 100%, 50%)')
  noStroke
  fill(c)
  rect(0, 10, 45, 80)
  c = color('hsba(160, 100%, 50%, 0.5)')
  fill(c)
  rect(55, 10, 45, 80)
end
def setup
  background(220)
  noStroke
  c = color(50, 55, 100)
  fill(c)
  rect(0, 10, 45, 80)
  colorMode(HSB, 100)
  c = color(50, 55, 100)
  fill(c)
  rect(55, 10, 45, 80)
end

p5.jsリファレンス(参考情報)

[p5.js] color

概要

色(カラー)オブジェクトを生成します。

書式

color(gray [, a])
color(v1, v2, v3 [, a])
color(values)
color(colorstring)
color(color)

引数

引数名内容備考オプションデフォルト値
grayグレースケール0~255
v1赤 または 色相0~255
colorModeの設定に依存
v2緑 または 彩度0~255
colorModeの設定に依存
v3青 または 明度0~255
colorModeの設定に依存
values配列[v1, v2, v3, 透明度]
colorModeの設定に依存
colorstring色文字列
colorp5.Colorオブジェクト
a透明度0~255
(0 : 完全な透明)
colorModeの設定に依存
RGBモード : 255
HSLモード/HSBモード : 1

戻値

p5.Colorオブジェクト

備考

関連

colorMode
色(カラー)