Skip to content

Instantly share code, notes, and snippets.

@watanabeyu
Created December 4, 2018 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watanabeyu/e8638e2b115aaa05edac23a5554e6280 to your computer and use it in GitHub Desktop.
Save watanabeyu/e8638e2b115aaa05edac23a5554e6280 to your computer and use it in GitHub Desktop.
import { GLView } from 'expo';
import Expo2DContext from 'expo-2d-context';
import React from 'react';
import { View, Button } from 'react-native';
export default class App extends React.Component {
render() {
return [
<GLView
ref={ref => {
this.gl = ref;
}}
style={{ flex: 1 }}
onContextCreate={this._onGLContextCreate}
/>,
<Button title="hoge" onPress={this.snapshot} />,
];
}
snapshot = async () => {
const res = await this.gl.takeSnapshotAsync();
console.log(res);
};
_onGLContextCreate = gl => {
var ctx = new Expo2DContext(gl);
ctx.translate(50, 200);
ctx.scale(4, 4);
ctx.fillStyle = 'grey';
ctx.fillRect(20, 40, 100, 100);
ctx.fillStyle = 'white';
ctx.fillRect(30, 100, 20, 30);
ctx.fillRect(60, 100, 20, 30);
ctx.fillRect(90, 100, 20, 30);
ctx.beginPath();
ctx.arc(50, 70, 18, 0, 2 * Math.PI);
ctx.arc(90, 70, 18, 0, 2 * Math.PI);
ctx.fill();
ctx.fillStyle = 'grey';
ctx.beginPath();
ctx.arc(50, 70, 8, 0, 2 * Math.PI);
ctx.arc(90, 70, 8, 0, 2 * Math.PI);
ctx.fill();
ctx.strokeStyle = 'black';
ctx.beginPath();
ctx.moveTo(70, 40);
ctx.lineTo(70, 30);
ctx.arc(70, 20, 10, 0.5 * Math.PI, 2.5 * Math.PI);
ctx.stroke();
ctx.flush();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment