canvas

Make moving Rect more smooth

穿精又带淫゛_ 提交于 2020-01-11 08:36:08
问题 I want to make "animation" of my Rect more smooth. Currently it's really clunky. I know the reason for it. One of the coordinates becomes wanted value before the other. For example if I'm currently at (0,0) and I need to go to (150,75) and I increment each one equally every second , y-cord will come much sooner than x-cord. var canvas = document.getElementById('canvas'); var ctx = document.getElementById('canvas').getContext('2d'); var aniTimer; var x; var y; var tx = tx || 0; var ty = ty ||

Make a javascript canvas rectangle clickable

一世执手 提交于 2020-01-11 07:56:09
问题 I am creating a simple calculator. Here it is. I am almost done with the basic design but I am confused on how to make the buttons clickable? One trick could be to make a div for each button but I think there has to be a simple way. Please guide. Thanks <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="300" height="400" style="border:2px solid ;"> Your browser does not support the HTML5 canvas tag.</canvas> <script> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"

ColorPicker implementation using JavaScript and Canvas

时间秒杀一切 提交于 2020-01-11 07:47:29
问题 I'm trying to implement ColorPicker using Canvas just for fun. But i seem lost. as my browser is freezing for a while when it loads due to all these for loops. I'm adding the screenshot of the result of this script: window.onload = function(){ colorPicker(); } function colorPicker(){ var canvas = document.getElementById("colDisp"), frame = canvas.getContext("2d"); var r=0, g=0, b= 0; function drawColor(){ for(r=0;r<255;r++){ for(g=0;g<255;g++){ for(b=0;b<255;b++){ frame.fillStyle="rgb("+r+","

JavaFX resize canvas in fxml

女生的网名这么多〃 提交于 2020-01-11 06:47:46
问题 I'm trying to resize a canvas in Javafx. I am using scene builder and fxml. So far, when the user clicks on the canvas the canvas turns black, and when I resize the screen and click on the canvas only the original size of the canvas turns black (canvas is not being resized). I'm not sure how to solve this. Any ideas or solutions would help alot. Code: Controller: public class MainFXMLController implements Initializable { @FXML private Canvas mainCanvas; @FXML public GraphicsContext gc; public

Javascript Canvas : Apply zoom at given coordinates

非 Y 不嫁゛ 提交于 2020-01-11 04:58:07
问题 I'm struggling with an implementation of canvas zooming (on mouse wheel), using Vanilla Javascript, without success. The zoom must be applied on the coordinates of the mouse, when the wheel is rolled. It's been asked here before, but my situation is quite different, considering I can't use canvasContext.translate , and the values of offsetX and offsetY must be kept in its absolute representation (not scaled) I would really appreciate some light. In the following snippet, I provide my current

H5 中html 页面存为图片并长按 保存

℡╲_俬逩灬. 提交于 2020-01-11 04:48:56
最近接到的一个新需求:页面一个静态H5,中间有一页是输入信息,然后跳转到最后一页,自动将页面生成图片,用户可以长按图片保存到手机上。 展示一下最后一页的样子: 刚拿到这个需求,在网上看了很多文章,最普遍的是使用 html2canvas + canvas2image 来实现。于是,跟着前人的脚步,踏上了一个不断采坑采坑采坑的旅程。 下面直接描述我在做这个需求过程中遇到的问题以及解决办法吧: 1.html2canvas 图片跨域: 这个问题网上很多解决办法: 这个是最常用的, 刚开始我只是加了红色框里面的这一句,但是并没有任何作用,依旧报错。后来看到有人说,加上前面那一句,所以果断在加进去。 这两句其实表达的是同一个意思:允许图片跨域。 当然,也有网友说,直接给一个空值就可以,我当时试了一下,并不ok~~~~. 2.多次使用canvas drawImage 方法图片展示问题 2.1 图片加载顺序问题 在我这个需求里面,肯定是文字描述以及二维码是展示在图片上面的,刚开始我是 1. drawImage 文字, 2. drawImage 二维码 3. drawImage 背景大图 然而,结果让我大吃一惊,只有背景图加载渲染出来了。然后,通过无所不能的网络才知道:drawImage 的顺序应该是: 图片最底下的需要最先加载渲染。 2.2 图片显示不完整 在2.1 问题出现的同时还遇到了这个问题

HTML5 Multiplayer Game Security Solutions

亡梦爱人 提交于 2020-01-10 10:36:19
问题 Now that there are a couple of neat canvas demo's of both classic platform and even 3D fps games in HTML5, the next step might be to try developing a multiplayer HTML5 game. HTML5 socket support makes this relatively straight-forward, but with client-side source being viewable by anyone in the browser, what are some solutions for basic game security features for a HTML5-frontend multiuser game -- such as being able to prevent a faked high-score submit ? 回答1: The simple answer is: You can't

canvas 简介

孤街醉人 提交于 2020-01-10 09:51:23
Canvas的概述 定义 <canvas> 是H5新增的标签 canvas提供给了 javascript 绘图接口 canvas绘图建立在坐标系上 应用领域 炫酷特效、banner 可视化数据(图表) 游戏 大型应用(地图) 在线系统 (在线PS ) canvas标签 属性 width 属性 height 方法 getContext() 可选的参数 "2d" / "webgl" 返回上下文环境 绘图环境 该对象提供API,让JavaScript来绘制图形 绘图基础 路径的开启和闭合 beginPath() 开启路径 closePath() 关闭路径 (把路径闭合) 设置起点 moveTo(x, y) 画线 lineTo(x , y) 绘制直线 描边 lineWidth 属性 设置描边线的粗细 strokeStyle 属性 设置描边颜色 stroke() 绘制 填充 fillStyle 属性 填充颜色 fill() 执行填充 快速矩形 rect(x, y, width, height) 绘制矩形路径 strokeRect(x, y, width, height) 描边矩形 fillStroke(x, y, width, height) 填充矩形 clearRect(x, y, width. height) 清除矩形 (可以用来清除屏幕) 圆弧 arc(x, y, radius,

[Canvas前端游戏开发]——FlappyBird详解

断了今生、忘了曾经 提交于 2020-01-10 09:49:50
一直想自己做点小东西,直到最近看了本《 HTML5游戏开发 》,才了解游戏开发中的一点点入门知识。 本篇就针对学习的几个样例,自己动手实践,做了个FlappyBird, 源码共享在度盘 ;也可以参考 github ,里面有更多的游戏样例。 游戏截图 HTML5之Canvas Canvas是Html5中用于绘图的元素,它可以绘制各种图形,比如长方形,多边形,圆形等等。如果想要了解Canvas的使用可以参考: http://www.w3school.com.cn/tags/html_ref_canvas.asp //如果想要使用canvas,首先需要获得上下文对象: ctx = document.getElementById('canvas').getContext('2d'); //然后使用这个ctx绘制图形 在cavas每个绘制都是独立的操作。比如下图的两个绘制图形,第二个会以覆盖的形式绘制,因此 绘制图形的顺序 就显得十分重要了。 canvas之drawImage() 本篇的游戏开发中,主要使用的是依据图片绘制的api: drawImage() ,它有两个基本的使用方法: ctx.drawImage(image,this.bx,this.by,this.bwidth,this.bheight); ctx.drawImage(image,x,y,width,height,this

Calculate exact character\string height in javascript

梦想的初衷 提交于 2020-01-10 06:11:26
问题 I'm working with canvases and i can't think of any solution, or find answer on line to my problem. I have a font that contains symbols\characters from varies sizes - heights and width. I want to draw some characters (Symbols) from the font and some on top\down of the symbol. The problem is that I can't figure out a way to have the exact height in pixels of the character that i'm drawing, and it's causes unwanted spaces between the center symbol to the one on top\down (for getting the width of