fix: pre commit issues

This commit is contained in:
Jannat Patel
2022-11-04 11:47:09 +05:30
parent cda26ab248
commit 603eddf878
210 changed files with 10725 additions and 6733 deletions

View File

@@ -1,13 +1,12 @@
function getLiveCodeOptions() {
var START = `
var START = `
import sketch
code = open("main.py").read()
env = dict(sketch.__dict__)
exec(code, env)
`
`;
var SKETCH = `
var SKETCH = `
import json
def sendmsg(msgtype, function, args):
@@ -50,57 +49,57 @@ def clear():
# clear the canvas on start
clear()
`
const CANVAS_FUNCTIONS = {
circle: function(ctx, args) {
ctx.beginPath();
ctx.arc(args.x, args.y, args.d/2, 0, 2*Math.PI);
ctx.stroke();
},
line: function(ctx, args) {
ctx.beginPath();
ctx.moveTo(args.x1, args.y1);
ctx.lineTo(args.x2, args.y2);
ctx.stroke();
},
rect: function(ctx, args) {
ctx.beginPath();
ctx.rect(args.x, args.y, args.w, args.h);
ctx.stroke();
},
clear: function(ctx, args) {
var width = 300;
var height = 300;
ctx.clearRect(0, 0, width, height);
`;
const CANVAS_FUNCTIONS = {
circle: function (ctx, args) {
ctx.beginPath();
ctx.arc(args.x, args.y, args.d / 2, 0, 2 * Math.PI);
ctx.stroke();
},
line: function (ctx, args) {
ctx.beginPath();
ctx.moveTo(args.x1, args.y1);
ctx.lineTo(args.x2, args.y2);
ctx.stroke();
},
rect: function (ctx, args) {
ctx.beginPath();
ctx.rect(args.x, args.y, args.w, args.h);
ctx.stroke();
},
clear: function (ctx, args) {
var width = 300;
var height = 300;
ctx.clearRect(0, 0, width, height);
},
};
function drawOnCanvas(canvasElement, funcName, args) {
var ctx = canvasElement.getContext("2d");
var func = CANVAS_FUNCTIONS[funcName];
var scalex = canvasElement.width / 300;
var scaley = canvasElement.height / 300;
ctx.save();
ctx.scale(scalex, scaley);
func(ctx, args);
ctx.restore();
}
}
function drawOnCanvas(canvasElement, funcName, args) {
var ctx = canvasElement.getContext('2d');
var func = CANVAS_FUNCTIONS[funcName];
var scalex = canvasElement.width/300;
var scaley = canvasElement.height/300;
ctx.save();
ctx.scale(scalex, scaley);
func(ctx, args);
ctx.restore();
}
return {
runtime: "python",
files: [
{filename: "start.py", contents: START},
{filename: "sketch.py", contents: SKETCH},
],
command: ["python", "start.py"],
codemirror: true,
onMessage: {
draw: function(editor, msg) {
const canvasElement = editor.parent.querySelector("canvas");
drawOnCanvas(canvasElement, msg.function, msg.args);
}
}
}
return {
runtime: "python",
files: [
{ filename: "start.py", contents: START },
{ filename: "sketch.py", contents: SKETCH },
],
command: ["python", "start.py"],
codemirror: true,
onMessage: {
draw: function (editor, msg) {
const canvasElement = editor.parent.querySelector("canvas");
drawOnCanvas(canvasElement, msg.function, msg.args);
},
},
};
}