| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 547 人关注过本帖, 1 人收藏
标题:vfp如何用渐进色作图
只看楼主 加入收藏
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:790
专家分:1170
注 册:2021-10-13
结帖率:96.72%
收藏(1)
已结贴  问题点数:20 回复次数:15 
vfp如何用渐进色作图
记得windowsAPI里有专门的函数可以在矩形和三角形里作渐进色图,但是我一直没搞懂那几个API函数的参数的结构(vfp里怎么调用),如果有人知道的,可以说明一下,谢谢!最好给个示例~~~

作为回馈,我把纯用foxpro代码的渐进色作图代码奉上,作为抛砖引玉!

程序代码:
PARAMETERS ndirection

IF PARAMETERS()=0
    ndirection=4 &&这个值1-5,会有不同效果
ENDIF

CLEAR
ncurrentcolor=_screen.ForeColor

_screen.Box(100,100,500,500)
*!*    * 渐变颜色计算
*!*    设定起始颜色
ocolor_begin=NEWOBJECT("color","myclass")
ncolor_begin=GETCOLOR()
ocolor_begin.set(ncolor_begin)

ocolor_end=NEWOBJECT("color","myclass")
ncolor_end=GETCOLOR()
ocolor_end.set(ncolor_end)

nStepRed = (ocolor_end.r - ocolor_begin.r) / 400
nStepGreen = (ocolor_end.g - ocolor_begin.g) / 400
nStepBlue = (ocolor_end.b - ocolor_begin.b) / 400

* 绘制色彩渐变

FOR nX = 100 TO 500
    nRed = ocolor_begin.r + (nX - 100) * nStepRed
    nGreen = ocolor_begin.g + (nX - 100) * nStepGreen
    nBlue = ocolor_begin.b + (nX - 100) * nStepBlue
    _screen.forecolor=RGB(nRed, nGreen, nBlue)
    DO CASE 
        CASE ndirection=1 &&水平渐进
            _screen.LINE (nx,100,nx,500)
        CASE ndirection=2 &&垂直渐进
            _screen.LINE (100,nx,500,nx)
        CASE ndirection=3 &&往中间渐变        
            _screen.LINE (100,600-nx , nx, 500)
            _screen.LINE (600-nx,100,500,nx)
        CASE ndirection=4 &&左下到右上对角渐变
            _screen.Line(IIF(nx<=300,100,(nx-300)*2+99),IIF(nx<=300,(300-nx)*2+99,100),;
                        IIF(nx<=300,(nx-100)*2+101,500),IIF(nx<=300,500,500-(nx-300)*2+1))

            _screen.Line(IIF(nx<=300,100,(nx-300)*2+100),IIF(nx<=300,(300-nx)*2+100,100),;
                        IIF(nx<=300,(nx-100)*2+100,500),IIF(nx<=300,500,500-(nx-300)*2))                
        CASE ndirection=5 &&水波渐变
            _screen.LINE (nx,100,nx,500)
            _screen.LINE (100,nx,500,nx)
    ENDCASE 
ENDFOR

_screen.ForeColor=ncurrentcolor

搜索更多相关主题的帖子: 作图 vfp LINE CASE 渐变 
2024-08-18 20:57
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:790
专家分:1170
注 册:2021-10-13
收藏
得分:0 
漏了2个重要的类,否则运行不了。。。

struct 类:
程序代码:
**************************************************
*-- 类:           struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- 父类:  custom
*-- 基类:    custom
*-- 时间戳:   08/14/24 08:01:09 PM
*
DEFINE CLASS struct AS custom


    *-- 用以储存或设置结构体数据
    struct = ""
    Name = "struct"


    *-- 设置结构体
    PROCEDURE set
        RETURN .t.
    ENDPROC


    *-- 获得结构体数据。
    PROCEDURE getstruct
    ENDPROC


ENDDEFINE
*
*-- EndDefine: struct
**************************************************
2024-08-18 21:01
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:790
专家分:1170
注 册:2021-10-13
收藏
得分:0 
漏了2个重要的类,否则运行不了。。。

color 类:

**************************************************
*-- 类:           color (d:\documents\visual foxpro 项目\myclass.vcx)
*-- 父类:  struct (d:\documents\visual foxpro 项目\myclass.vcx)
*-- 基类:    custom
*-- 时间戳:   08/14/24 06:23:09 PM
*
DEFINE CLASS color AS struct


    *-- 红色
    r = .F.

    *-- 绿色
    g = .F.

    *-- 蓝色
    b = .F.

    *-- alpha透明度
    a = .F.

    *-- 颜色值
    value = .F.


    PROCEDURE getstruct
        this.value=RGB(this.r,this.g,this.b)
        this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(this.a)
        RETURN this.struct
    ENDPROC


    PROCEDURE set
        PARAMETERS nred,ngreen,nblue,nalpha
        DO CASE
            CASE PARAMETERS()=0
                this.value=RGB(this.r,this.g,this.b)
        *!*            this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(0)
            CASE PARAMETERS()=1 &&只有一个参数,要么是颜色结构要么是颜色值
                IF VARTYPE(nred)="N" &&颜色值
                    this.value=nred
                    this.r=MOD(this.value,0x100)
                    this.b=INT(this.value/0x10000)
                    this.g=INT((this.value-this.r-this.b*0x10000)/0x100)
                ELSE
                    IF VARTYPE(nred)="C" AND LEN(nred)=4 &&颜色结构
                        this.struct=nred
                        this.b=ASC(SUBSTR(this.struct,1,1))
                        this.g=ASC(SUBSTR(this.struct,2,1))
                        this.r=ASC(SUBSTR(this.struct,3,1))
                        this.a=ASC(SUBSTR(this.struct,4,1))
                        this.value=RGB(this.r,this.g,this.b)
                    ELSE
                        RETURN .f.
                    ENDIF
                ENDIF
            CASE PARAMETERS()=3
                this.r=nred
                this.g=ngreen
                this.b=nblue
                this.a=0
                this.value=RGB(this.r,this.g,this.b)
        *!*            this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(this.a)
            CASE PARAMETERS()=4
                this.r=nred
                this.g=ngreen
                this.b=nblue
                this.a=nalpha
                this.value=RGB(this.r,this.g,this.b)
        *!*            this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(this.a)
            OTHERWISE
                RETURN .f.
        ENDCASE


    ENDPROC


ENDDEFINE
*
*-- EndDefine: color
**************************************************
2024-08-18 21:02
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1744
专家分:3333
注 册:2012-2-29
收藏
得分:5 
谢谢分享!
2024-08-19 06:42
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:5 
楼主你好,你的作品我下载后运行,程序提示找不到类
myclass.vcx
不知道这个类在什么地方?
2024-08-19 14:36
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:317
专家分:448
注 册:2019-10-11
收藏
得分:5 
PARAMETERS ndirection

IF PARAMETERS()=0
    ndirection=4 &&这个值1-5,会有不同效果
ENDIF

CLEAR
ncurrentcolor=_screen.ForeColor

_screen.Box(100,100,500,500)
*!*    * 渐变颜色计算
*!*    设定起始颜色
ocolor_begin=NEWOBJECT("color")
ncolor_begin=GETCOLOR()
ocolor_begin.set(ncolor_begin)

ocolor_end=NEWOBJECT("color")
ncolor_end=GETCOLOR()
ocolor_end.set(ncolor_end)

nStepRed = (ocolor_end.r - ocolor_begin.r) / 400
nStepGreen = (ocolor_end.g - ocolor_begin.g) / 400
nStepBlue = (ocolor_end.b - ocolor_begin.b) / 400

* 绘制色彩渐变

FOR nX = 100 TO 500
    nRed = ocolor_begin.r + (nX - 100) * nStepRed
    nGreen = ocolor_begin.g + (nX - 100) * nStepGreen
    nBlue = ocolor_begin.b + (nX - 100) * nStepBlue
    _screen.forecolor=RGB(nRed, nGreen, nBlue)
    DO CASE
        CASE ndirection=1 &&水平渐进
            _screen.LINE (nx,100,nx,500)
        CASE ndirection=2 &&垂直渐进
            _screen.LINE (100,nx,500,nx)
        CASE ndirection=3 &&往中间渐变        
            _screen.LINE (100,600-nx , nx, 500)
            _screen.LINE (600-nx,100,500,nx)
        CASE ndirection=4 &&左下到右上对角渐变
            _screen.Line(IIF(nx<=300,100,(nx-300)*2+99),IIF(nx<=300,(300-nx)*2+99,100),;
                        IIF(nx<=300,(nx-100)*2+101,500),IIF(nx<=300,500,500-(nx-300)*2+1))

            _screen.Line(IIF(nx<=300,100,(nx-300)*2+100),IIF(nx<=300,(300-nx)*2+100,100),;
                        IIF(nx<=300,(nx-100)*2+100,500),IIF(nx<=300,500,500-(nx-300)*2))               
        CASE ndirection=5 &&水波渐变
            _screen.LINE (nx,100,nx,500)
            _screen.LINE (100,nx,500,nx)
    ENDCASE
ENDFOR

_screen.ForeColor=ncurrentcolor


DEFINE CLASS color AS custom

struct=""

    *-- 红色
    r = .F.

    *-- 绿色
    g = .F.

    *-- 蓝色
    b = .F.

    *-- alpha透明度
    a = .F.

    *-- 颜色值
    value = .F.


    PROCEDURE getstruct
        this.value=RGB(this.r,this.g,this.b)
        this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(this.a)
        RETURN this.struct
    ENDPROC


    PROCEDURE set
        PARAMETERS nred,ngreen,nblue,nalpha
        DO CASE
            CASE PARAMETERS()=0
                this.value=RGB(this.r,this.g,this.b)
        *!*            this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(0)
            CASE PARAMETERS()=1 &&只有一个参数,要么是颜色结构要么是颜色值
                IF VARTYPE(nred)="N" &&颜色值
                    this.value=nred
                    this.r=MOD(this.value,0x100)
                    this.b=INT(this.value/0x10000)
                    this.g=INT((this.value-this.r-this.b*0x10000)/0x100)
                ELSE
                    IF VARTYPE(nred)="C" AND LEN(nred)=4 &&颜色结构
                        this.struct=nred
                        this.b=ASC(SUBSTR(this.struct,1,1))
                        this.g=ASC(SUBSTR(this.struct,2,1))
                        this.r=ASC(SUBSTR(this.struct,3,1))
                        this.a=ASC(SUBSTR(this.struct,4,1))
                        this.value=RGB(this.r,this.g,this.b)
                    ELSE
                        RETURN .f.
                    ENDIF
                ENDIF
            CASE PARAMETERS()=3
                this.r=nred
                this.g=ngreen
                this.b=nblue
                this.a=0
                this.value=RGB(this.r,this.g,this.b)
        *!*            this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(this.a)
            CASE PARAMETERS()=4
                this.r=nred
                this.g=ngreen
                this.b=nblue
                this.a=nalpha
                this.value=RGB(this.r,this.g,this.b)
        *!*            this.struct=CHR(this.b)+CHR(this.g)+CHR(this.r)+CHR(this.a)
            OTHERWISE
                RETURN .f.
        ENDCASE


    ENDPROC


ENDDEFINE
楼上的代码稍加修改
2024-08-19 15:12
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:790
专家分:1170
注 册:2021-10-13
收藏
得分:0 
回复 5楼 gs2536785678
哈哈,六楼替我回答了。

你也可以自建一个myclass的类,然后加入这连个类。
2024-08-19 16:36
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:0 
非常感谢,这个作品有意思
图片附件: 游客没有浏览图片的权限,请 登录注册
2024-08-19 19:12
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1744
专家分:3333
注 册:2012-2-29
收藏
得分:0 
非常好!
2024-08-20 07:04
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:0 
增加了二种渐变方式
    CASE ndirection=6 &&水平往中间渐变
        _SCREEN.LINE (100+INT((nx-100)/2),100 , 100+INT((nx-100)/2), 500)
        _SCREEN.LINE (500-INT((nx-100)/2),100 , 500-INT((nx-100)/2), 500)        
    CASE ndirection=7 &&垂直往中间渐变
        _SCREEN.LINE (100 , 100+INT((nx-100)/2),500, 100+INT((nx-100)/2))
        _SCREEN.LINE (100 ,500-INT((nx-100)/2), 500, 500-INT((nx-100)/2))        
2024-08-20 08:55
快速回复:vfp如何用渐进色作图
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021380 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved