Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Reading a Point's Color

    2D Blocks
    1
    1
    234
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

      Introduction

      When you click on the color input, you can use the color picker tool to get the exact color value at any point you click.

       
      You can actually do this using a block, which would allow your program to “scan” the stage automatically.

       
       

      Description

      To read the color value at any position on the stage, you can use this block:

      beeccd56-1c24-47cd-ae57-b27f9ed249a0-image.png

       

       

      X and Y Positions

      The first 2 inputs are the X and Y positions of the point you would like to read. For example, if you want to know the color at the center point of the stage, then you should input 0 for both inputs.

       
       

      Output Variables

      Each type of color is actually represented by 4 numbers: color, brightness, saturation and transparency. Before you use this block, you need to first define 4 variables, and then select them in the 4 dropdowns of this block.

      After you run this block, these 4 variables will contain the 4 numbers that represent a color.

       
       

      Demo

      As shown, we first manually read the brown color at the center of the stage using the color picker tool, which gives us these values: color = 9, saturation = 81, brightness = 60, transparency = 0.

      Next, we use the “read color” block, which will store the same 4 numbers into the 4 variables: color = 9, saturation = 81, brightness = 60, transparency = 0.

       
       

      Color Reader

      Here is another demo project that reads the color of the point clicked by the mouse, and uses that color to draw a rectangle and print the color’s code.

       
      color.gif

      Here is the project link:

      https://play.creaticode.com/projects/65309f2a0fdce080a447a916

      1 Reply Last reply Reply Quote 0
      • First post
        Last post