项目作者: ubermanu

项目描述 :
🎨 HTML5 Canvas renderer for 2D projects (experimental)
高级语言: TypeScript
项目地址: git://github.com/ubermanu/cc.js.git
创建时间: 2016-01-19T09:22:44Z
项目社区:https://github.com/ubermanu/cc.js

开源协议:MIT License

下载


Canevas

A small HTML Canvas 2D framework without any dependency.

Check out the docs for more information.

  1. import {
  2. BasicMaterial, BoxShape, Camera, Canvas, Mesh, Scene
  3. } from 'https://cdn.skypack.dev/canevas';
  4. let canvas, scene, camera;
  5. let shape, material, mesh;
  6. init();
  7. animate();
  8. function init() {
  9. // Main renderer
  10. canvas = new Canvas();
  11. canvas.setSize(window.innerWidth, window.innerHeight);
  12. // Contains all the meshes to render
  13. scene = new Scene();
  14. // Will move into the scene
  15. camera = new Camera();
  16. camera.position.set(window.innerWidth / 2, window.innerHeight / 2);
  17. // Mesh properties
  18. material = new BasicMaterial({ wireframe: true, color: 0xff0000 });
  19. shape = new BoxShape({ width: 80, height: 80 });
  20. // Add mesh to the scene
  21. mesh = new Mesh(shape, material);
  22. scene.add(mesh);
  23. // Append canvas to the body
  24. document.body.appendChild(canvas.element);
  25. }
  26. function animate() {
  27. requestAnimationFrame(animate);
  28. mesh.rotation += 0.02;
  29. canvas.render(scene, camera);
  30. }