Download code/validation/JavaScript/0018918_Polygon.js from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 968 Bytes
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/JavaScript/0018918_Polygon.js
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/validation/JavaScript/0018918_Polygon.js
-
curl -L -o 0018918_Polygon.js https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/validation/JavaScript/0018918_Polygon.js
968 Bytes
| import Entity from './Entity'; | |
| export default class Polygon extends Entity { | |
| constructor(id, x, y, angle, center, color, strength, polys) { | |
| super(id, x, y, angle, center, color, strength); | |
| this.polys = polys; | |
| } | |
| draw(ctx, SCALE) { | |
| SCALE = SCALE || 30; | |
| ctx.save(); | |
| ctx.translate(this.x * SCALE, this.y * SCALE); | |
| ctx.rotate(this.angle); | |
| ctx.translate(-(this.x) * SCALE, -(this.y) * SCALE); | |
| ctx.fillStyle = this.getColor(); | |
| for (var i = 0; i < this.polys.length; i++) { | |
| var points = this.polys[i]; | |
| ctx.beginPath(); | |
| ctx.moveTo((this.x + points[0].x) * SCALE, (this.y + points[0].y) * SCALE); | |
| for (var j = 1; j < points.length; j++) { | |
| ctx.lineTo((points[j].x + this.x) * SCALE, (points[j].y + this.y) * SCALE); | |
| } | |
| ctx.lineTo((this.x + points[0].x) * SCALE, (this.y + points[0].y) * SCALE); | |
| ctx.closePath(); | |
| ctx.fill(); | |
| ctx.stroke(); | |
| } | |
| ctx.restore(); | |
| } | |
| } | |