Page 1 of 1

>Colores por cada letra de un texto

PostPosted: Sat Aug 09, 2014 4:03 pm
by Willi Quintana

Re: >Colores por cada letra de un texto

PostPosted: Wed Aug 13, 2014 2:42 am
by Willi Quintana
No es posible????

Re: >Colores por cada letra de un texto

PostPosted: Wed Aug 13, 2014 2:47 am
by Armando
Willi:

Me parece que no existe una función para tal efecto, se me ocurre que metas el texto en
un array y ahí asignarle el color a cada letra. Solo una idea.

Saludos

Re: >Colores por cada letra de un texto

PostPosted: Wed Aug 13, 2014 7:46 am
by pgfdz
Hola. A ver si esto te vale.
Un saludo


#include "fivewin.ch"


static oWnd

function main()

DEFINE WINDOW oWnd

ACTIVATE WINDOW oWnd ON PAINT Pinta( hDC )

return nil


function Pinta( hDC )

local nColor
local nLeft := 10
local cTexto := "En un lugar de la mancha de cuyo nombre no quiero acordarme"
local oFont
local hFont
local nLen := len( cTexto )
local cLetra, n

DEFINE FONT oFont NAME "Segoe UI Light" SIZE 0, -18


hFont := SelectObject( hDC, oFont:hFont )


for n := 1 to nLen

cLetra := substr( cTexto, n, 1 )

nColor := SetTextColor( hDC, nRandom( CLR_WHITE ) )

TextOut( hDC, 10, nLeft, cLetra )

SetTextColor( hDC, nColor )

nLeft += GetTextWidth( hDC, cLetra, oFont )

next

SelectObject( hDC, hFont )

oFont:ENd()

return nil

Re: >Colores por cada letra de un texto

PostPosted: Wed Aug 13, 2014 8:18 am
by Carles
Image

Re: >Colores por cada letra de un texto

PostPosted: Tue Mar 31, 2020 12:00 pm
by karinha
Very good Paco.

Code: Select all  Expand view

#Include "Fivewin.ch"

STATIC oWnd

FUNCTION Main()

   DEFINE WINDOW oWnd

   ACTIVATE WINDOW oWnd MAXIMIZED ON PAINT Pinta( hDC )

RETURN NIL

FUNCTION Pinta( hDC )

   LOCAL nColor
   LOCAL nLeft  := 80
   LOCAL nRight := 220
   LOCAL cTexto := "AMBIENTE PAISAGISMO"
   LOCAL oFont
   LOCAL hFont
   LOCAL nLen := len( cTexto )
   LOCAL cLetra, n

   LOCAL nResHoriz, nResVert

   nResHoriz := oWnd:nHorzRes()
   nResVert  := oWnd:nVertRes()

   // Necesito más sugerencias para resoluciones de video.
   // I need more suggestions for video resolutions.
   IF nResHoriz = 1366 .AND. nResVert = 768

      nLeft  := 260
      nRight := 230

   ELSEIF nResHoriz = 1360 .AND. nResVert = 768

      nLeft  := 210
      nRight := 250

   ELSEIF nResHoriz = 1280 .AND. nResVert = 768

      nLeft  := 210
      nRight := 250

   ELSEIF nResHoriz = 1280 .AND. nResVert = 720

      nLeft  := 200
      nRight := 200

   ELSEIF nResHoriz = 1024 .AND. nResVert = 768  // Minha Maquina

      nLeft  :=  80
      nRight := 220

   ELSE

      nLeft  :=  80
      nRight := 220

   ENDIF

   // DEFINE FONT oFont NAME "Segoe UI Light" SIZE 0, - 50
   DEFINE FONT oFont NAME "Segoe UI Symbol" SIZE 0, - 80

   hFont := SelectObject( hDC, oFont:hFont )

   FOR n := 1 TO nLen

      cLetra := substr( cTexto, n, 1 )

      nColor := SetTextColor( hDC, nRandom( CLR_HGREEN ) )  // COLORS.CH

      // TextOut( hDC, 10, nLeft, cLetra )
      TextOut( hDC, 325, nLeft, cLetra )

      SetTextColor( hDC, nColor )

      nLeft += GetTextWidth( hDC, cLetra, oFont )

   NEXT

   SelectObject( hDC, hFont )

   oFont:ENd()

RETURN NIL
 


Saludos.