1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
| ;- Color v1.1 ;- 19.09.06 by Froggerprogger Enumeration ; do not change their order! #COLOR_RGB #COLOR_CMY #COLOR_HSV #COLOR_HSL EndEnumeration Structure Color StructureUnion r.f ; Red in RGB [0.0, 1.0] c.f ; Cyan in CMY [0.0, 1.0] h.f ; Hue in HSV/HSL [0.0, 360.0[ EndStructureUnion StructureUnion g.f ; Green in RGB [0.0, 1.0] m.f ; Magenta in CMY [0.0, 1.0] s.f ; Saturation in HSV/HSL [0.0, 1.0] EndStructureUnion StructureUnion b.f ; Blue in RGB [0.0, 1.0] y.f ; Yellow in CMY [0.0, 1.0] v.f ; Value in HSV [0.0, 1.0] l.f ; Lightness in HSL [0.0, 1.0] EndStructureUnion type.l ; gives the type. One of #COLOR_RGB, #COLOR_CMY, #COLOR_HSV, #COLOR_HSL EndStructure ;- some neccessary declares DeclareDLL.l Color2RGB(*c.Color) DeclareDLL.l Color2CMY(*c.Color) DeclareDLL.l Color2HSV(*c.Color) DeclareDLL.l Color2HSL(*c.Color) ;- some helper-proceudures Procedure.f Max3F(a.f, b.f, c.f) If a > b If a > c ProcedureReturn a Else ProcedureReturn c EndIf Else If b > c ProcedureReturn b Else ProcedureReturn c EndIf EndIf EndProcedure Procedure.f Min3F(a.f, b.f, c.f) If a < b If a < c ProcedureReturn a Else ProcedureReturn c EndIf Else If b < c ProcedureReturn b Else ProcedureReturn c EndIf EndIf EndProcedure ;- some global color-procedures ProcedureDLL.l IsColorValid(*c.Color) ; returns #True or #False whether *c specifies a valid color or not If *c\type < #COLOR_RGB Or *c\type > #COLOR_HSL ProcedureReturn #False EndIf ; check r, c in [0.0, 1.0] or h in [0.0, 360.0] If *c\type <= #COLOR_CMY If *c\r < 0 Or *c\r > 1.0 ProcedureReturn #False EndIf Else If *c\h < 0 Or *c\h >= 360.0 ProcedureReturn #False EndIf EndIf ; check g, m, s, b, y, v, l in [0.0, 1.0] If *c\g < 0 Or *c\g > 1.0 ProcedureReturn #False EndIf If *c\b < 0 Or *c\b > 1.0 ProcedureReturn #False EndIf ProcedureReturn #True EndProcedure ProcedureDLL.l ColorCopy(*c.Color) ; copies *c and returns *copy Protected *|/2/>out = AllocateMemory(SizeOf(Color)) CopyMemory(*c, *|/2/>out, SizeOf(Color)) ProcedureReturn *|/2/>out EndProcedure ProcedureDLL.l ColorComplement(*c.Color) ; complements *c and returns *c If *c\type <= #COLOR_CMY ; if #COLOR_RGB or #COLOR_CMY *c\r = 1.0 - *c\r *c\g = 1.0 - *c\g *c\b = 1.0 - *c\b Else ; if #COLOR_HSV or #COLOR_HSL If *c\h >= 180.0 *c\h - 180.0 Else *c\h + 180.0 EndIf EndIf EndProcedure ProcedureDLL.l ColorChangeType(*c.Color, type.l) ; changes the type of *c to the new type and returns *c. type = #COLOR_* Select type Case #COLOR_RGB : Color2RGB(*c) Case #COLOR_CMY : Color2CMY(*c) Case #COLOR_HSV : Color2HSV(*c) Case #COLOR_HSL : Color2HSL(*c) EndSelect EndProcedure ProcedureDLL.l IsSameColors(*c1.Color, *c2.Color, tolerance.f) ; compares the two colors (of any type) without modifiing them and returns #True if they describe the same color equal, #False otherwise Protected same.l ; compare in RGB to easy treat special cases in HSL, HSV *c1c.Color = ColorCopy(*c1) *c2c.Color = ColorCopy(*c2) Color2RGB(*c1c) Color2RGB(*c2c) If tolerance = 0 same = CompareMemory(*c1c, *c2c, SizeOf(Color)) Else same = #True If Abs(*c1c\r - *c2c\r) > tolerance same = #False EndIf If Abs(*c1c\g - *c2c\g) > tolerance same = #False EndIf If Abs(*c1c\b - *c2c\b) > tolerance same = #False EndIf EndIf FreeMemory(*c1c) FreeMemory(*c2c) ProcedureReturn same EndProcedure ProcedureDLL.s ColorToStr(*c.Color) Protected s.s Select *c\type Case #COLOR_RGB : s = "RGB" Case #COLOR_CMY : s = "CMY" Case #COLOR_HSV : s = "HSV" Case #COLOR_HSL : s = "HSL" EndSelect s + ": " + StrF(*c\r, 2) + ", " + StrF(*c\g, 2) + ", " + StrF(*c\b, 2) ProcedureReturn s EndProcedure ;- change color to RGB ProcedureDLL.l CMY2RGB(*c.Color) ; converts CMY-color *c to RGB and returns *c. No check if CMY is made! *c\r = 1.0 - *c\c *c\g = 1.0 - *c\m *c\b = 1.0 - *c\y *c\type = #COLOR_RGB ProcedureReturn *c EndProcedure ProcedureDLL.l HSV2RGB(*c.Color) ; converts HSV-color *c to RGB and returns *c. No check if HSV is made! Protected h.f, s.f, v.f Protected f.f, p.f, q.f, t.f, i.l h = *c\h s = *c\s v = *c\v If s = 0 ; it's a gray-tone *c\r = v *c\g = v *c\b = v Else h / 60.0 i = Round(h, 0) f = h-i p = v*(1.0-s) q = v*(1.0-s*f) t = v*(1.0-s*(1.0-f)) Select i Case 0 : *c\r = v : *c\g = t : *c\b = p Case 1 : *c\r = q : *c\g = v : *c\b = p Case 2 : *c\r = p : *c\g = v : *c\b = t Case 3 : *c\r = p : *c\g = q : *c\b = v Case 4 : *c\r = t : *c\g = p : *c\b = v Case 5 : *c\r = v : *c\g = p : *c\b = q EndSelect EndIf *c\type = #COLOR_RGB ProcedureReturn *c EndProcedure Procedure.f HSL2RGBHelper(q1.f, q2.f, h.f) If h >= 360.0 h - 360.0 ElseIf h < 0.0 h + 360.0 EndIf If h < 60.0 ProcedureReturn q1+(q2-q1)*h/60.0 ElseIf h < 180.0 ProcedureReturn q2 ElseIf h < 240.0 ProcedureReturn q1+(q2-q1)*(240.0-h)/60.0 Else ProcedureReturn q1 EndIf EndProcedure ProcedureDLL.l HSL2RGB(*c.Color) ; converts HSL-color *c to RGB and returns *c. No check if HSL is made! Protected h.f, l.f, s.f Protected f.f, p1.f, p2.f, t.f Protected i.l h = *c\h l = *c\l s = *c\s If l<=0.5 p2 = l*(1.0+s) Else p2 = l+s-l*s EndIf p1 = 2.0*l-p2 If s=0.0 ; it's a gray-tone *c\r = l *c\g = l *c\b = l Else *c\r = HSL2RGBHelper(p1, p2, h+120.0) *c\g = HSL2RGBHelper(p1, p2, h) *c\b = HSL2RGBHelper(p1, p2, h-120.0) EndIf *c\type = #COLOR_RGB ProcedureReturn *c EndProcedure ProcedureDLL.l Color2RGB(*c.Color) ; converts *c from any color-type to RGB and returns *c Select *c\type Case #COLOR_RGB : ProcedureReturn *c Case #COLOR_CMY : ProcedureReturn CMY2RGB(*c) Case #COLOR_HSV : ProcedureReturn HSV2RGB(*c) Case #COLOR_HSL : ProcedureReturn HSL2RGB(*c) EndSelect EndProcedure ProcedureDLL.l ColorSetRGB(*c.Color, r.f, g.f, b.f) ; sets *c to the RGB-color given by r,g,b, each in range [0.0, 1.0] (no check is made) and returns *c *c\r = r *c\g = g *c\b = b *c\type = #COLOR_RGB ProcedureReturn *c EndProcedure ;- change color to CMY ProcedureDLL.l RGB2CMY(*c.Color) ; converts RGB-color *c to CMY and returns *c. No check if RGB is made! *c\c = 1.0 - *c\r *c\m = 1.0 - *c\g *c\y = 1.0 - *c\b *c\type = #COLOR_CMY ProcedureReturn *c EndProcedure ProcedureDLL.l HSV2CMY(*c.Color) ; converts HSV-color *c to CMY and returns *c. No check if HSV is made! ; complement If *c\h >= 180.0 *c\h - 180.0 Else *c\h + 180.0 EndIf HSV2RGB(*c) ; HSV2RGB of complement *c\type = #COLOR_CMY ProcedureReturn *c EndProcedure ProcedureDLL.l HSL2CMY(*c.Color) ; converts HSL-color *c to CMY and returns *c. No check if HSL is made! ; complement If *c\h >= 180.0 *c\h - 180.0 Else *c\h + 180.0 EndIf HSL2RGB(*c) ; HSL2RGB of complement *c\type = #COLOR_CMY ProcedureReturn *c EndProcedure ProcedureDLL.l Color2CMY(*c.Color) ; converts *c from any color-type to CMY and returns *c Select *c\type Case #COLOR_RGB : ProcedureReturn RGB2CMY(*c) Case #COLOR_CMY : ProcedureReturn *c Case #COLOR_HSV : ProcedureReturn HSV2CMY(*c) Case #COLOR_HSL : ProcedureReturn HSL2CMY(*c) EndSelect EndProcedure ProcedureDLL.l ColorSetCMY(*c.Color, c.f, m.f, y.f) ; sets *c to the CMY-color given by c,m,y, each in range [0.0, 1.0] (no check is made) and returns *c *c\c = c *c\m = m *c\y = y *c\type = #COLOR_CMY ProcedureReturn *c EndProcedure ;- change color to HSV ProcedureDLL.l RGB2HSV(*c.Color) ; converts RGB-color *c to HSV and returns *c. No check if RGB is made! Protected r.f, g.f, b.f, max.f, min.f, delta.f r = *c\r g = *c\g b = *c\b max = Max3F(r,g,b) min = Min3F(r,g,b) ; get value *c\v = max If max <> 0.0 delta = max - min ; get saturation *c\s = delta/max ; get hue If delta <> 0.0 If r = max *c\h = (g-b)/delta ElseIf g = max *c\h = 2.0 + (b-r)/delta ElseIf b = max *c\h = 4.0 + (r-g)/delta EndIf *c\h * 60.0 If *c\h<0.0 *c\h + 360.0 EndIf Else ; it's a gray-tone *c\h = 0 ; *c\h is even undefined EndIf Else ; it's black *c\s = 0 *c\h = 0 ; *c\h is even undefined EndIf *c\type = #COLOR_HSV ProcedureReturn *c EndProcedure ProcedureDLL.l CMY2HSV(*c.Color) ; converts CMY-color *c to HSV and returns *c. No check if CMY is made! ; treat as RGB-color RGB2HSV(*c) ; complement If *c\h >= 180.0 *c\h - 180.0 Else *c\h + 180.0 EndIf ProcedureReturn *c EndProcedure ProcedureDLL.l HSL2HSV(*c.Color) ; converts HSL-color *c to HSV and returns *c. No check if HSL is made! ProcedureReturn RGB2HSV(HSL2RGB(*c)) ; it's the easiest, though not fastet way EndProcedure ProcedureDLL.l Color2HSV(*c.Color) ; converts *c from any color-type to HSV And returns *c Select *c\type Case #COLOR_RGB : ProcedureReturn RGB2HSV(*c) Case #COLOR_CMY : ProcedureReturn CMY2HSV(*c) Case #COLOR_HSV : ProcedureReturn *c Case #COLOR_HSL : ProcedureReturn HSL2HSV(*c) EndSelect EndProcedure ProcedureDLL.l ColorSetHSV(*c.Color, h.f, s.f, v.f) ; sets *c to the HSV-color given by h in range [0.0, 360.0] and s,v in range [0.0, 1.0] (no check is made) and returns *c If h = 360.0 h = 0 EndIf *c\h = h *c\s = s *c\v = v *c\type = #COLOR_HSV ProcedureReturn *c EndProcedure ;- change color to HSL ProcedureDLL.l RGB2HSL(*c.Color) ; converts RGB-color *c to HSL and returns *c. No check if RGB is made! Protected r.f, g.f, b.f, max.f, min.f, delta.f r = *c\r g = *c\g b = *c\b max = Max3F(r,g,b) min = Min3F(r,g,b) delta = max - min If delta <> 0.0 ; get lightness *c\l = (max + min) / 2.0 ; get saturation If *c\l <= 0.5 *c\s = delta/(max+min) Else *c\s = delta/(2-max-min) EndIf ; get hue If r = max *c\h = (g-b)/delta ElseIf g = max *c\h = 2.0 + (b-r)/delta ElseIf b = max *c\h = 4.0 + (r-g)/delta EndIf *c\h * 60.0 If *c\h<0.0 *c\h + 360.0 EndIf Else ; it's black *c\s = 0 *c\h = 0 ; *c\h is even undefined EndIf *c\type = #COLOR_HSL ProcedureReturn *c EndProcedure ProcedureDLL.l CMY2HSL(*c.Color) ; converts CMY-color *c to HSL and returns *c. No check if CMY is made! ; treat as RGB-color RGB2HSL(*c) ; complement If *c\h >= 180.0 *c\h - 180.0 Else *c\h + 180.0 EndIf ProcedureReturn *c EndProcedure ProcedureDLL.l HSV2HSL(*c.Color) ; converts HSV-color *c to HSL and returns *c. No check if HSV is made! ProcedureReturn RGB2HSL(HSV2RGB(*c)) ; it's the easiest, though not fastet way EndProcedure ProcedureDLL.l Color2HSL(*c.Color) ; converts *c from any color-type to HSL and returns *c Select *c\type Case #COLOR_RGB : ProcedureReturn RGB2HSL(*c) Case #COLOR_CMY : ProcedureReturn CMY2HSL(*c) Case #COLOR_HSV : ProcedureReturn HSV2HSL(*c) Case #COLOR_HSL : ProcedureReturn *c EndSelect EndProcedure ProcedureDLL.l ColorSetHSL(*c.Color, h.f, l.f, s.f) ; sets *c to the HSL-color given by h in range [0.0, 360.0[ and l,s in range [0.0, 1.0] (no check is made) and returns *c *c\h = h *c\l = l *c\s = s *c\type = #COLOR_HSL ProcedureReturn *c EndProcedure ;- change color to PureBasic's RGB ProcedureDLL.l ColorRGBFast(*c.Color) ; converts *c to RGB and returns a Purebasic-RGB-colorcode same as returned by PB's RGB() Color2RGB(*c) ProcedureReturn RGB(255 * *c\r, 255 * *c\g, 255 * *c\b) EndProcedure ProcedureDLL.l ColorRGB(*c.Color) ; converts an internal copy of *c to RGB and returns a Purebasic-RGB-colorcode same as returned by PB's RGB() Protected *cc.Color, rgb.l *cc = ColorCopy(*c) Color2RGB(*cc) rgb = RGB(255 * *cc\r, 255 * *cc\g, 255 * *cc\b) FreeMemory(*cc) ProcedureReturn rgb EndProcedure ;- ;- debug test functionality ;- Procedure.l DebugTestFunctionality() ; RGB <-> CMY For i=0 To 10000 ColorSetRGB(c.Color, Random(100)/100.0, Random(100)/100.0, Random(100)/100.0) *c2.Color = Color2RGB(Color2CMY(ColorCopy(c))) If IsSameColors(c, *c2, 0.1) = #False Debug "ERROR RGB <-> CMY" End EndIf FreeMemory(*c2) Next ; RGB <-> HSV For i=0 To 10000 ColorSetRGB(c.Color, Random(100)/100.0, Random(100)/100.0, Random(100)/100.0) *c2.Color = Color2RGB(Color2HSV(ColorCopy(c))) If IsSameColors(c, *c2, 0.1) = #False Debug "ERROR RGB <-> HSV" End EndIf FreeMemory(*c2) Next ; RGB <-> HSL For i=0 To 10000 ColorSetRGB(c.Color, Random(100)/100.0, Random(100)/100.0, Random(100)/100.0) *c2.Color = Color2RGB(Color2HSL(ColorCopy(c))) If IsSameColors(c, *c2, 0.1) = #False Debug "ERROR RGB <-> HSL" End EndIf FreeMemory(*c2) Next ; CMY <-> HSV For i=0 To 10000 ColorSetCMY(c.Color, Random(100)/100.0, Random(100)/100.0, Random(100)/100.0) *c2.Color = Color2CMY(Color2HSV(ColorCopy(c))) If IsSameColors(c, *c2, 0.1) = #False Debug "ERROR CMY <-> HSV" End EndIf FreeMemory(*c2) Next ; CMY <-> HSL For i=0 To 10000 ColorSetCMY(c.Color, Random(100)/100.0, Random(100)/100.0, Random(100)/100.0) *c2.Color = Color2CMY(Color2HSL(ColorCopy(c))) If IsSameColors(c, *c2, 0.1) = #False Debug "ERROR CMY <-> HSL" End EndIf FreeMemory(*c2) Next ; HSV <-> HSL For i=0 To 10000 ColorSetHSV(c.Color, Random(360)/100.0, Random(100)/100.0, Random(100)/100.0) *c2.Color = Color2HSV(Color2HSL(ColorCopy(c))) If IsSameColors(c, *c2, 0.1) = #False Debug "ERROR HSV <-> HSL" End EndIf FreeMemory(*c2) Next Debug "All Tests done." EndProcedure ;Goto example3 ;- ;- example 1 ;- example1: ColorSetRGB(rgbCol.Color, 0.0, 0.0, 1.0) ; full blue s.s = "Create blue, decrease its saturation towards gray and move it" + #CRLF$ s.s + "slightly towards green without changing it's intensity" + #CRLF$ + #CRLF$ s.s + "Original color: " + ColorToStr(rgbCol) + #CRLF$ ; we dont' like this green, we want to make it a little bit darker and remove it's saturation Color2HSL(rgbCol) s.s + "Original color: " + ColorToStr(rgbCol) + #CRLF$ rgbCol\h - 30 ; be careful to stay in range [0, 360[. Here we know h is 240 rgbCol\s = 0.5 s.s + "Modified color: " + ColorToStr(rgbCol) + #CRLF$ Color2RGB(rgbCol) s.s + "Modified color: " + ColorToStr(rgbCol) + #CRLF$ MessageRequester("Color example 1/3:", s) ; MessageRequester("Color example 2/3:", "Click OK to run a HSL-demonstration in fullscreen.") ; ;- ; ;- example 2 ; ;- ; example2: ; ; InitSprite() ; InitKeyboard() ; ; OpenScreen(1024, 768, 32, "Color-example") ; ; framecounter = 0 ; fps = 0 ; lastFrametimer = 0 ; ; Repeat ; ; fps-calculation ; framecounter+1 ; If ElapsedMilliseconds() - lastFrametimer > 1000 ; fps = framecounter ; framecounter = 0 ; lastFrametimer = ElapsedMilliseconds() ; EndIf ; ; ; draw the colorbars ; ClearScreen(RGB(0, 0, 50)) ; StartDrawing(ScreenOutput()) ; FrontColor(RGB(255,255,255)) ; DrawingMode(1) ; DrawText(10,10, "HSL-colors for 1.440.000 individual colored pixels at " + Str(fps) + " fps. Press ESC to exit.") ; ; ; create 1.440.000 combinations of hue, sat and lightness and display them ; sat.f = 0.05 ; While sat <= 1.0 ; lig.f = 0 ; While lig <= 1.0 ; hue.f = 0 ; While hue < 360.0 ; ; create a new hsl-colored pixel (you might fill your structure manually, too) ; ColorSetHSL(HSLCol.Color, hue, sat, lig) ; ; ; draw it on the screen after converting to PB's RGB ; Plot(152 + 2*hue, 180 + 20*lig + 400*sat, ColorRGBFast(HSLCol)) ; ; hue + 0.5 ; Wend ; lig + 0.05 ; Wend ; sat + 0.1 ; Wend ; StopDrawing() ; FlipBuffers() ; ; Delay(10) ; ; ExamineKeyboard() ; Until KeyboardPushed(#PB_Key_Escape) ; CloseScreen() ; ; ;- ; ;- example 3 ; ;- example3: Procedure.l GetContrastedPBColor(red.l, green.l, blue.l) Protected col.Color ColorSetRGB(col.Color, red/255.0, green/255.0, blue/255.0) Color2HSV(col) ColorComplement(col) ; build the normal complement ; modify saturation and value ; you might experiment with those to achieve other results col\s + 0.5 If col\s > 1.0 col\s - 1.0 EndIf col\v + 0.5 If col\v > 1.0 col\v - 1.0 EndIf Color2RGB(col) ProcedureReturn RGB(col\r*255, col\g*255, col\b*255) EndProcedure CreateImage(0, 500, 500) For i=0 To 9 Select i Case 0 : col.l = $000000 Case 1 : col.l = $FFFFFF Case 2 : col.l = $7F7F7F Case 3 : col.l = $660000 Case 4 : col.l = $00FF00 Case 5 : col.l = $000033 Case 6 : col.l = $FF9900 Case 7 : col.l = $FF33FF Case 8 : col.l = $3754A9 Case 9 : col.l = $9F3F20 EndSelect contrCol = GetContrastedPBColor(Red(col), Green(col), Blue(col)) StartDrawing(ImageOutput(0)) Box(0, i*50, 500, 50, col) DrawingMode(#PB_2DDrawing_Transparent) DrawText(10, i*50 + 20, "This is just an example-text in a color contrasted to the background", contrCol) StopDrawing() Next OpenWindow(0, 0, 0, 500, 500, "Color example 3/3:") ImageGadget(0, 0, 0, 500, 500, ImageID(0)) Repeat Until WaitWindowEvent() = #PB_Event_CloseWindow |