简体   繁体   English

HTML5 Canvas可调整大小的多边形

[英]HTML5 Canvas Resizable Polygon

I need a diagonal polygon color fill that resizes based on screen width / height. 我需要一个对角多边形颜色填充,根据屏幕宽度/高度调整大小。 The green background fill here: http://rhiwifi.co/bus is a prototype which uses a rotated DIV. 绿色背景填写在这里: http//rhiwifi.co/bus是一个使用旋转DIV的原型。 That DIV is 200% of the screen, so it stretches past the bounds of the mobile interface and doesn't fill in the bottom of the screen correctly. DIV是屏幕的200%,因此它会超出移动界面的范围,并且无法正确填充屏幕底部。

How can I draw a resizable polygon that is diagonal on the top, and rectangular on the bottom? 如何绘制一个可调整大小的多边形,其顶部是对角线,底部是矩形? Or is there an easier way? 或者有更简单的方法吗?

I'd just store the o-ordinates as proportion values, rather than as absolute pixels. 我只是将o坐标存储为比例值,而不是绝对像素。

That is to say, I'd use numbers in the range [0..1] to define a point. 也就是说,我会使用[0..1]范围内的数字来定义一个点。 Then you just multiply this by your canvas dimensions to get the pixel dimensions. 然后,您只需将其乘以画布尺寸即可获得像素尺寸。

Eg you want to draw a rect that occupies the top-left 1/4 of the canvas, define it thusly: "0,0,0.5,0.5" - you can then split into an array based on commas. 例如,你想绘制一个占据画布左上角1/4的矩形,然后定义它:“0,0,0.5,0.5” - 然后你可以根据逗号分割成一个数组。 You can then multiply each element in the array by the canvas size to give you the final coordinates. 然后,您可以将数组中的每个元素乘以画布大小,以获得最终坐标。

The 2d OpenGL viewport, for instance uses normalized co-ords, where 0,0 is the center of the screen, -1,-1 the top left, 1,1 is the bottom right. 例如,2d OpenGL视口使用标准化的co-ords,其中0,0是屏幕的中心,-1,-1是左上角,1,1是右下角。 This way, openGL just multiplies out by window size to get pixel values. 这样,openGL只是乘以窗口大小来获取像素值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM