利用ShapeRenderer可进行矩形进度条的绘制,多变形的填充等操作。

这是根据角度获取矩形坐标的函数。

     public Vector2 GetPoint( float x, float y, float w, float h, float angle ){
Vector2 point = new Vector2();
while( angle >= 360 ){
angle -= 360;
}
while( angle < 0 ){
angle += 360;
} System.out.println( GetAtan( h/w ) ); if( angle>=0 && angle<GetAtan( h/w ) || angle>=360-GetAtan( h/w ) && angle<360 ){
point.x = x+w;
point.y = y+w*Change( angle );
}
else if( angle>=GetAtan( h/w ) && angle<180-GetAtan( h/w ) ){
point.x = x+h*Change( 90-angle );
point.y = y+h;
}
else if( angle>=180-GetAtan( h/w ) && angle<180+GetAtan( h/w ) ){
point.x = x-w;
point.y = y-w*Change( angle );
}
else if( angle>=180+GetAtan( h/w ) && angle<360-GetAtan( h/w ) ){
point.x = x-h*Change( 90-angle );
point.y = y-h;
} return point;
}

画部分矩形

     public void FillPartRect( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color  )
{
rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled ); for( int i=0; i<angle-1; i++ ){
Vector2 point1 = GetPoint( x, y, w, h, start+i );
Vector2 point2 = GetPoint( x, y, w, h, start+i+1 );
rend.triangle( x, y, point1.x, point1.y, point2.x, point2.y );
}
rend.end();
}

全部代码如下:

 package com.fxb.newtest;

 import sun.security.provider.certpath.Vertex;

 import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2; public class Lib012_CdDraw extends ApplicationAdapter{ ShapeRenderer rend; float[] vertexs; Pixmap pixmap;
float angle = 0; @Override
public void create() {
// TODO Auto-generated method stub
rend = new ShapeRenderer(); vertexs = new float[]{ 100, 100, 250, 100, 200, 200, 100, 250 }; } public void FillPolygon( float[] vertexs, ShapeRenderer rend, Color color ){
if( vertexs.length%2 != 0 ){
return;
}
rend.begin( ShapeType.Filled );
rend.setColor( color );
for( int i=2; i<=vertexs.length-4; i+=2 ){
rend.triangle( vertexs[0], vertexs[1], vertexs[i], vertexs[i+1], vertexs[i+2], vertexs[i+3] );
}
rend.end();
} public float Change( float angle0 ){
return (float)Math.tan( angle0*(float)Math.PI/180 );
} public void FillRect( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color ){ rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled );
rend.setColor( color );
//angle = angle*(float)Math.PI/180; if( angle <= 45 ){
rend.triangle( x, y, x+w, y, x+w, y+w*(float)Math.tan( angle*(float)Math.PI/180 ) );
}
else if( angle <= 135 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+h*(float)Math.tan( (90-angle)*(float)Math.PI/180 ), y+h );
}
else if( angle <= 135+90 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x-w, y-w*Change( angle ) );
}
else if( angle <= 135+180 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-h*Change( 270-angle ), y-h );
}
else if( angle <= 360 ){
rend.triangle( x, y, x+w, y, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x+w, y+w*Change(angle) );
} rend.end();
} public float GetAtan( float angle ){
return (float)( 180*Math.atan( angle )/Math.PI );
} public Vector2 GetPoint( float x, float y, float w, float h, float angle ){
Vector2 point = new Vector2();
while( angle >= 360 ){
angle -= 360;
}
while( angle < 0 ){
angle += 360;
} System.out.println( GetAtan( h/w ) ); if( angle>=0 && angle<GetAtan( h/w ) || angle>=360-GetAtan( h/w ) && angle<360 ){
point.x = x+w;
point.y = y+w*Change( angle );
}
else if( angle>=GetAtan( h/w ) && angle<180-GetAtan( h/w ) ){
point.x = x+h*Change( 90-angle );
point.y = y+h;
}
else if( angle>=180-GetAtan( h/w ) && angle<180+GetAtan( h/w ) ){
point.x = x-w;
point.y = y-w*Change( angle );
}
else if( angle>=180+GetAtan( h/w ) && angle<360-GetAtan( h/w ) ){
point.x = x-h*Change( 90-angle );
point.y = y-h;
} return point;
} public void FillRect1( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color ){ rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled );
rend.setColor( color );
//angle = angle*(float)Math.PI/180; if( angle <= 45 ){
rend.triangle( x, y, x, y+h, x+h*Change( angle ), y+h );
}
else if( angle <= 135 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y+w*Change( 90-angle ) );
}
else if( angle <= 135+90 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-h*Change( angle ), y-h );
}
else if( angle <= 135+180 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y-w*Change( 270-angle ) );
}
else if( angle <= 360 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x+h*Change( angle ), y+h );
} rend.end();
} public void FillRect2( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color ){ rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled );
rend.setColor( color );
//angle = angle*(float)Math.PI/180;
rend.rect( x-w, y-h, 2*w, 2*h ); //rend.setColor( color.mul( 0.5f ) ); if( angle <= 45 ){
rend.triangle( x, y, x, y+h, x+h*Change( angle ), y+h );
}
else if( angle <= 135 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y+w*Change( 90-angle ) );
}
else if( angle <= 135+90 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-h*Change( angle ), y-h );
}
else if( angle <= 135+180 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y-w*Change( 270-angle ) );
}
else if( angle <= 360 ){
rend.triangle( x, y, x, y+h, x+w, y+w );
rend.triangle( x, y, x+w, y+h, x+w, y-h );
rend.triangle( x, y, x+w, y-h, x-w, y-h );
rend.triangle( x, y, x-w, y-h, x-w, y+h );
rend.triangle( x, y, x-w, y+h, x+h*Change( angle ), y+h );
} rend.end();
} public void FillPartRect( float x, float y, float w, float h, float start, float angle, ShapeRenderer rend, Color color )
{
rend.begin( ShapeType.Line );
rend.setColor( color );
rend.rect( x-w, y-h, 2*w, 2*h );
rend.end(); rend.begin( ShapeType.Filled ); for( int i=0; i<angle-1; i++ ){
Vector2 point1 = GetPoint( x, y, w, h, start+i );
Vector2 point2 = GetPoint( x, y, w, h, start+i+1 );
rend.triangle( x, y, point1.x, point1.y, point2.x, point2.y );
}
rend.end();
} public void FillCircle( ){ } @Override
public void render() {
// TODO Auto-generated method stub
Gdx.gl.glClearColor( 0, 1, 1, 1 );
Gdx.gl.glClear( GL10.GL_COLOR_BUFFER_BIT ); Gdx.gl.glEnable( GL10.GL_BLEND );
Gdx.gl.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA ); /* rend.begin( ShapeType.Filled );
rend.setColor( Color.BLUE );
//rend.polyline( vertexs );
//rend.line( 100, 100, 200, 200 );
//rend.triangle( 100, 100, 200, 100, 100, 200 ); rend.arc( 100, 100, 100, 0, 60 );
rend.circle( 300, 300, 100 );
rend.end();*/ //FillPolygon( vertexs, rend, Color.BLUE ); angle += 0.5f;
/* if( angle > 360 ){
angle -= 360;
}*/ //angle =
//FillRect( 300, 300, 100, 100, 0, angle, rend, Color.BLUE ); //FillRect1( 300, 300, 100, 100, 0, angle, rend, new Color( 1f, 0.7f, 0.7f, 0.5f ));
//FillRect( 300, 300, 100, 100, 0, 90, rend, new Color( 1, 1, 1, 0 ) );
//FillRect2( 300, 300, 100, 100, 0, angle, rend, Color.BLUE); FillPartRect( 300, 300, 100, 100, 90, 360-angle, rend, Color.BLUE);
} @Override
public void dispose() {
// TODO Auto-generated method stub
rend.dispose();
super.dispose();
} }

运行结果:

libgdx学习记录13——矩形CD进度条绘制的更多相关文章

  1. jQuery ajax 标准写法及进度条绘制

    jQuery ajax 标准写法及进度条绘制 $.ajax({ url: "http://www.microsoft.com", //请求的url地址 dataType: &quo ...

  2. ProgressBar学习笔记,自定义横向进度条的样式(包含ActionBar上面的进度条)

     点显示进度条后→   android:max="100" 进度条的最大值 android:progress  进度条已经完成的进度值 android:progressDrawab ...

  3. 【Flutter学习】基本组件之进度条(LinearProgressIndicator, CircularProgressIndicator)

    一,概述 基本有两种类型: 条形进度条(LinearProgressIndicator) new LinearProgressIndicator( backgroundColor: Colors.bl ...

  4. libgdx学习记录12——圆角矩形CircleRect

    libgdx提供了ShapeRenderer这个工具,用它可以画点.画线.画圆.画矩形.画椭圆.画扇形,但是没有提供画圆角矩形的方法. 刚开始自己尝试分成8端,4端画直线,4端画扇形,发现多了半径几部 ...

  5. libgdx学习记录24——九宫格NinePatch

    NinePatch用于图片纹理拉伸显示.当图片拉伸时,4个角不会拉伸,而只有中间的部分会拉伸,适合做圆角矩形类的Button. 简单示例: package com.fxb.newtest; impor ...

  6. libgdx学习记录16——资源加载器AssetManager

    AssetManager用于对游戏中的资源进行加载.当游戏中资源(图片.背景音乐等)较大时,加载时会需要较长时间,可能会阻塞渲染线程,使用AssetManager可以解决此类问题. 主要优点: 1. ...

  7. libgdx学习记录2——文字显示BitmapFont

    libgdx对中文支持不是太好,主要通过Hireo和ttf字库两种方式实现.本文简单介绍最基本的bitmapfont的用法. 代码如下: package com.fxb.newtest; import ...

  8. libgdx学习记录3——动画Animation

    libgdx动画采用Animation实现,即通过帧动画实现. 代码如下: package com.fxb.newtest; import com.badlogic.gdx.ApplicationAd ...

  9. libgdx学习记录27——线段与线段相交检测

    给定p1, p2, p3, p4四个点,p1,p2为一条线段,p3,p4为一条线段,检测其是否有交点. 可分为三种情况: 1. L2与x轴平行 2. L2与y轴平行 3. L2与坐标轴不平行. (L1 ...

随机推荐

  1. Charles 模拟服务器挂掉Rewrite tools

    1.点击相应请求 2.选择Rewrite 工具 3. 4. 5.保存 6.接下来就是重新发送请求了

  2. 测试笔试单选题(持续更新ing)

    1.在GB/T17544中,软件包质量要求包括三部分,即产品描述要求._____.程 序和数据要求.( A ) A.用户文档要求 B.系统功能要求 C.设计要求说明 D.软件配置要求 2.软件的六大质 ...

  3. innodb_locks_unsafe_for_binlog分析

    mysql数据库中默认的隔离级别为repeat-read. innodb默认使用了next-gap算法,这种算法结合了index-row锁和gap锁.正因为这样的锁算法,innodb在可重复读这样的默 ...

  4. C语言short int

    因为C语言中short int占2个字节,有16个二进制位,共可表示2^16种状态.因为它用来表示有符号数,而0也要占用一个状态.所以,16位的原码可以表示的数是-32767~+32767,它的0可以 ...

  5. 搭建企业级NFS网络文件共享服务

    NFS服务简介 NFS是Network  File System(网络文件系统).主要功能是通过网络让不同的服务器之间可以共享文件或者目录.NFS客户端一般是应用服务器(比如web,负载均衡等),可以 ...

  6. MSSQL · 最佳实践 · 利用文件组实现冷热数据隔离备份方案

    文件组的基本知识点介绍完毕后,根据场景引入中的内容,我们将利用SQL Server文件组技术来实现冷热数据隔离备份的方案设计介绍如下. 设计分析 由于payment数据库过大,超过10TB,单次全量备 ...

  7. apk静态注射[转]-未实践

    原文:http://free0coding.iteye.com/blog/1684263 1.将需要注入的代码块打包成jar1,释放一个公共类的静态方法a  2.反编译apk得到smali文件,在适当 ...

  8. 关于军训的模拟赛-R2

    终于我也参加了一场有R1 && R2的比赛呢. 点击此处查看R1 因为种种原因,老师认为上次的考试没有体现我们的真实水平,于是举办了毒瘤R2,其实也不是非常毒瘤,还是一贯的风格. T1 ...

  9. Guava 的EventBus示例代码(简单笔记,后期补充)

    package guavademo.event.bus; import com.google.common.eventbus.EventBus; import com.google.common.ev ...

  10. PSR规范0-4整理

    PSR规范 psr规范 引言: PSR 是 PHP Standard Recommendations 的简写,由 PHP FIG 组织制定的 PHP 规范,是 PHP 开发的实践标准.这些规范的目的是 ...