鳕鱼天空

This is Mr Wang's Tech Blog.

Js中 Math ceil()、floor()、round()的用法

原文转载自:http://blog.csdn.net/xiaxiaorui2003/article/details/6481034
 

Math.floor()

功能: 对一个数进行下取整。

语法: Math.floor(x)

参数:

  • x:一个数值。

返回值: 返回小于或等于 x ,并且与之最接近的整数。

注: 如果 x 是正数,则把小数 “ 舍 ” ;如果 x 是负数,则把小数 “ 入 ” 。

例:

<script type="text/javascript">
document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) );
</script>

输出结果为:

document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) ); 1, 1, -2, -2

Math.round()

功能: 四舍五入取整。

语法: Math.round(x)

参数:

  • x:一个数值。

返回值: 与 x 最接近的整数。

例:

<script type="text/javascript">
document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );
</script>

输出结果为:

document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );  1, 2, -1, -2

Math.ceil()

功能: 对一个数进行上取整。

语法: Math.ceil(x)

参数:

  • x:一个数值。

返回值: 返回大于或等于 x ,并且与之最接近的整数。

注: 如果 x 是正数,则把小数 “ 入 ” ;如果 x 是负数,则把小数 “ 舍 ” 。

例:

<script type="text/javascript">
document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );
</script>

输出结果为:

document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );  2, 2, -1, -1

c# 图片围绕圆心旋转

public Image RotateImg(Image b, int angle)
        {
            //原图的宽和高
            int w = b.Width;
            int h = b.Height;
 
            int squartWidth = Math.Max(w, h) * 3;//目标图边长
            int radius = (squartWidth - 1) / 2;//圆半径
            //目标位图
            Bitmap dsImage = new Bitmap(squartWidth, squartWidth);
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dsImage);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Pen pen = new Pen(Color.Black,1)   ;
            g.DrawEllipse(pen, 0, 0, squartWidth - 1, squartWidth - 1);//画个圆圈用于确认功能是否正确
            
            angle = angle % 360;
            g.TranslateTransform(radius, radius);
            g.RotateTransform(360 - angle);
            g.TranslateTransform(-radius, -radius);
            g.DrawImage(b, radius - w / 2, radius - h * 2);//平面几何这个算不来了,所以直接写死了
 
            ////重至绘图的所有变换
            g.ResetTransform();
            g.Save();
            g.Dispose();
 
            ////保存旋转后的图片
            b.Dispose();
            return dsImage;
 
        }
 
        int number = 0;
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            var img = this.RotateImg(Resources._1, 10 * (number++));
            this.pictureBox1.Image = img;
        }

asp.net 网站调用python执行返回信息Demo

首先需要引入IronPython,可以通过NuGet搜索获得,基于4.5以上框架集

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
public partial class python : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        RunPythonShell();
    }
    /// <summary>
    /// 调用Python
    /// </summary>
    private void RunPythonShell()
    {
        ScriptRuntime pyRuntime = Python.CreateRuntime();
        //python文件绝对路径
        string path = string.Format(@"{0}1.py", Server.MapPath("./"));
        dynamic py = pyRuntime.UseFile(path);
        //调用Python 的函数run()
        Response.Write(py.show());
    }

}

 

cocos 通过碰撞边缘判断非常规多边形按钮

     // 不规则形状通过碰撞边缘检测是否在有效区域内
            let target = this.node;
            let pos = target.convertToNodeSpaceAR(e.getLocation())
            var polygonCollider = target.getComponent(cc.PolygonCollider);
            //pos.x -= target.getContentSize().width / 2;   // 原始示例中由减去宽度和高度的设定,实测不需要
            //pos.y -= target.getContentSize().height / 2;
            if (!cc.Intersection.pointInPolygon(pos, polygonCollider.points)) {
                return;
            }

以上是多边形按钮


var Global = require("Global");

cc.Class({
    extends: cc.Component,

    properties: {
        touched: false,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.touchStart.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMove.bind(this));
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEnd.bind(this));
    },

    onDestory() {

    },

    touchStart(e) {

        // 不规则形状通过碰撞边缘检测是否在有效区域内
        let target = this.node;
        let pos = target.convertToNodeSpaceAR(e.getLocation())
        var polygonCollider = target.getComponent(cc.PolygonCollider);
        //pos.x -= target.getContentSize().width / 2;   // 原始示例中由减去宽度和高度的设定,实测不需要
        //pos.y -= target.getContentSize().height / 2;
        if (!cc.Intersection.pointInPolygon(pos, polygonCollider.points)) {
            return;
        }
        this.touched = true;
        // 切换选中状态
        if (Global.selectedBoard != undefined && this.node != Global.selectedBoard) {
            Global.selectedBoard.opacity = 255;
        }
        Global.selectedBoard = this.node;
        this.node.opacity = 180;    // 选中状态半透明
        this.node.zIndex = 1;   // 最前
    },
    touchMove(e) {
        if (this.touched) {
            // 开始移动
            let delta = e.getDelta();
            this.node.x += delta.x;
            this.node.y += delta.y;
        }
    },
    touchEnd(e) {
        this.touched = false;
        this.node.zIndex = 0;
    },
});

以上是不规则图形按住拖动

sqlsever获取表结构

SELECT (case when a.colorder=1 then d.name else null end) 表名,  
a.colorder 字段序号,a.name 字段名,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识, 
(case when (SELECT count(*) FROM sysobjects  
WHERE (name in (SELECT name FROM sysindexes  
WHERE (id = a.id) AND (indid in  
(SELECT indid FROM sysindexkeys  
WHERE (id = a.id) AND (colid in  
(SELECT colid FROM syscolumns WHERE (id = a.id) AND (name = a.name)))))))  
AND (xtype = 'PK'))>0 then '√' else '' end) 主键,b.name 类型,a.length 占用字节数,  
COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,  
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,(case when a.isnullable=1 then '√'else '' end) 允许空,  
isnull(e.text,'') 默认值,isnull(g.[value], ' ') AS [说明]
FROM  syscolumns a 
left join systypes b on a.xtype=b.xusertype  
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties' 
left join syscomments e on a.cdefault=e.id  
left join sys.extended_properties g on a.id=g.major_id AND a.colid=g.minor_id
left join sys.extended_properties f on d.id=f.class and f.minor_id=0
--where b.name is not null
WHERE d.name='splits' --如果只查询指定表,加上此条件
order by a.id,a.colorder