สีที่กำหนดเอง#

การแนะนำ#

หุ่นยนต์เขียนโค้ด VEX AIM รองรับการใช้สีแบบกำหนดเองสำหรับการวาดภาพ การแสดงผล และไฟ LED สามารถสร้างสีแบบกำหนดเองได้โดยใช้ค่า RGB รหัสเลขฐานสิบหก หรือค่าคงที่ที่กำหนดไว้ล่วงหน้า ฟังก์ชันสีแบบกำหนดเองประกอบด้วยวิธีการทั้งการสร้างและการอัปเดตวัตถุสี

ด้านล่างนี้คือรายการวิธีการทั้งหมด:

ตัวสร้าง – สร้างวัตถุใหม่ที่มีสี Color

  • Color(value) – รับค่าคงที่ที่กำหนดไว้ล่วงหน้า สตริงเลขฐานสิบหก หรือจำนวนเต็มเลขฐานสิบหก

  • Color(r, g, b) – สร้างสีโดยใช้ค่าสีแดง สีเขียว และสีน้ำเงิน

ตัวแก้ไข – อัปเดตวัตถุที่มีอยู่ซึ่งมีสี Color

  • rgb – อัปเดตสีโดยใช้ค่า RGB ใหม่

  • hsv – อัปเดตสีโดยใช้เฉดสี ความอิ่มตัว และความสว่าง

  • web – อัปเดตสีโดยใช้สตริงสีเลขฐานสิบหกของเว็บ

การสร้างสีแบบกำหนดเอง#

หากต้องการใช้สีที่กำหนดเอง คุณต้องสร้างอ็อบเจ็กต์ Color ก่อน โดยใช้ตัวสร้างอย่างใดอย่างหนึ่งต่อไปนี้:

Hexadecimal Integer#

สร้างสีโดยใช้เลขฐานสิบหกหกหลัก

Usage:
Color(value)

พารามิเตอร์

คำอธิบาย

value

ตัวเลขจำนวนเต็มหกหลักในรูปแบบเลขฐานสิบหก (เช่น 0xFFF700 สำหรับสีเหลือง)

# Construct a yellow Color "yellow" using a
# hexadecimal value
yellow = Color(0xFFF700)

robot.screen.set_pen_color(yellow)
robot.screen.print("My Yellow")

RGB#

สร้างสีโดยใช้ค่าสีแดง สีเขียว และสีน้ำเงินแยกกัน

Usage:
Color(r, g, b)

พารามิเตอร์

คำอธิบาย

r

จำนวนเต็มตั้งแต่ 0 ถึง 255 ซึ่งแทนส่วนประกอบสีแดง

g

จำนวนเต็มตั้งแต่ 0 ถึง 255 ซึ่งแทนส่วนประกอบสีเขียว

b

จำนวนเต็มตั้งแต่ 0 ถึง 255 ซึ่งแทนส่วนประกอบสีน้ำเงิน

# Construct a yellow Color "yellow" using
# RGB values
yellow = Color(255, 247, 0)

robot.screen.set_pen_color(yellow)
robot.screen.print("My Yellow")

Web Color#

สร้างสีโดยใช้สตริงสีเว็บ (รหัสเลขฐานสิบหก)

Usage:
Color(value)

พารามิเตอร์

คำอธิบาย

value

รหัสสีเว็บในรูปแบบสตริง (รหัสเลขฐานสิบหก) (เช่น “#FFF700”)

# Construct a yellow Color "yellow" using a
# web string
yellow = Color("#FFF700")

robot.screen.set_pen_color(yellow)
robot.screen.print("My Yellow")

Predefined Color#

สร้างสีโดยใช้ค่าคงที่ Color ที่กำหนดไว้ล่วงหน้า

Usage:
Color(value)

พารามิเตอร์

คำอธิบาย

value

ค่าสีคงที่ในตัว:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
# Construct a yellow Color "yellow" using a
# predefined Color constant
yellow = Color(YELLOW)

robot.screen.set_pen_color(yellow)
robot.screen.print("My Yellow")

ตัวกลายพันธุ์#

These methods update the color of an existing Color object. To use them, assign a Color to a variable when creating it, then call the method on that variable to change its color.

rgb#

rgb อัปเดตสีของวัตถุ Color ที่มีอยู่โดยใช้ค่า RGB

Usage:
variable_name.rgb(r, g, b)

พารามิเตอร์

คำอธิบาย

r

จำนวนเต็มตั้งแต่ 0 ถึง 255 ซึ่งแสดงถึงส่วนประกอบสีแดงของสีนั้น

g

จำนวนเต็มตั้งแต่ 0 ถึง 255 ซึ่งแสดงถึงส่วนประกอบสีเขียวของสีนั้น

b

จำนวนเต็มตั้งแต่ 0 ถึง 255 ซึ่งแสดงถึงส่วนประกอบสีน้ำเงินของสีนั้น

# Create a custom teal color and set it as the pen color
robot_color = Color(50, 200, 180)
robot.screen.set_pen_color(robot_color)

# Draw a rectangle with the teal outline
robot.screen.draw_rectangle(30, 70, 80, 50)

# Draw another rectangle with a magenta outline
robot_color.rgb(170, 40, 150)
robot.screen.set_pen_color(robot_color)
robot.screen.draw_rectangle(130, 70, 80, 50)

hsv#

hsv อัปเดตสีของวัตถุ Color ที่มีอยู่โดยใช้ค่า HSV

หมายเหตุ: hsv สามารถใช้เพื่อเปลี่ยนวัตถุ Color ที่สร้างไว้แล้วเท่านั้น ไม่สามารถใช้เพื่อสร้างวัตถุ Color ใหม่ได้

Usage:
variable_name.hsv(h, s, v)

พารามิเตอร์

คำอธิบาย

h

จำนวนเต็มตั้งแต่ 0 ถึง 359 ที่แสดงถึงเฉดสี

s

ค่าทศนิยมตั้งแต่ 0.0 ถึง 1.0 แสดงถึงความอิ่มตัวของสี

v

ค่าทศนิยมตั้งแต่ 0.0 ถึง 1.0 แสดงถึงความสว่างของสี

# Create a custom teal color using RGB (HSV can't be used)
robot_color = Color(50, 200, 180)
robot.screen.set_pen_color(robot_color)

# Draw a rectangle with the teal outline
robot.screen.draw_rectangle(30, 70, 80, 50)

# Draw another rectangle with a magenta outline
robot_color.hsv(300, 0.75, 0.78)
robot.screen.set_pen_color(robot_color)
robot.screen.draw_rectangle(130, 70, 80, 50)

web#

web อัปเดตสีของวัตถุ Color ที่มีอยู่โดยใช้สีเว็บ (รหัสเลขฐานสิบหก)

Usage:
variable_name.web(value)

พารามิเตอร์

คำอธิบาย

value

รหัสสีเว็บในรูปแบบสตริง (รหัสเลขฐานสิบหก) (เช่น “#FFF700”)

# Create a custom teal color and set it as the pen color
robot_color = Color("#32C8B6")
robot.screen.set_pen_color(robot_color)

# Draw a rectangle with the teal outline
robot.screen.draw_rectangle(30, 70, 80, 50)

# Draw another rectangle with the new magenta outline
robot_color.web("#AA2896")
robot.screen.set_pen_color(robot_color)
robot.screen.draw_rectangle(130, 70, 80, 50)