-
Jun 22nd, 2022, 03:17 PM
#1
Thread Starter
Hyperactive Member
Convert TypeScript to VB.NET
Hello,
I want to convert these TS codes to VB.NET. Ive tried many compilers and converters, but I was unable to do that. Thanks.
Sorry for throwing a lot of code...
Code:
import Vector = require("./Vector");
class Triangle {
private _v1:Vector;
private _v2:Vector;
private _v3:Vector;
constructor(v1:Vector, v2:Vector, v3:Vector) {
this._v1 = v1;
this._v2 = v2;
this._v3 = v3;
}
public get v1() {
return this._v1;
}
public get v2() {
return this._v2;
}
public get v3() {
return this._v3;
}
}
export = Triangle;
Code:
import SceneRunner = require("../scene/SceneRunner");
import Triangle = require("./Triangle");
import Vector = require("./Vector");
/**
* Scene that draws triangles on a canvas
*/
class TrianglesScene extends SceneRunner {
private _canvas:HTMLCanvasElement;
private _counter:number = 0;
private _triangle:Triangle;
constructor(canvas:HTMLCanvasElement) {
super();
this._canvas = canvas;
}
public run():void {
this._counter++;
var angle:number = this._counter / 100.0;
this._triangle = TrianglesScene.createTriangle(angle);
}
public draw():void {
// clear canvas
TrianglesScene.clearCanvas(this._canvas);
// draw the triange multiple times
var w:number = 30;
var h:number = 30;
var cw:number = this._canvas.width;
var ch:number = this._canvas.height;
var context:CanvasRenderingContext2D = this._canvas.getContext("2d");
for (var x:number=0; x<w; x++) {
for (var y:number=0; y<h; y++ ) {
var offsetX:number = x/w * cw;
var offsetY:number = y/h * ch;
TrianglesScene.fillTriangle(context,
this._triangle.v1.x+offsetX, this._triangle.v1.y+offsetY,
this._triangle.v2.x+offsetX, this._triangle.v2.y+offsetY,
this._triangle.v3.x+offsetX, this._triangle.v3.y+offsetY,
Math.round(x/w * 255), Math.round(y/h * 255), 0);
}
}
}
// =======
static createTriangle(angle:number):Triangle {
var center:Vector = new Vector(25, 25);
var v1:Vector = Vector.rotate(new Vector(0, 0), center, angle);
var v2:Vector = Vector.rotate(new Vector(50, 0), center, angle);
var v3:Vector = Vector.rotate(new Vector(50, 50), center, angle);
return new Triangle(v1, v2, v3);
}
static clearCanvas(canvas:HTMLCanvasElement):void {
canvas.width = canvas.width;
}
static fillTriangle(context:CanvasRenderingContext2D, x1:number, y1:number, x2:number, y2:number, x3:number, y3:number, red:number, green:number, blue:number) {
context.fillStyle='rgb('+red+','+green+','+blue+')';
context.beginPath();
context.moveTo(x1,y1);
context.lineTo(x2,y2);
context.lineTo(x3,y3);
context.closePath();
context.fill();
}
}
export = TrianglesScene;
Code:
class Vector {
private _x:number;
private _y:number;
constructor(x:number,y:number) {
this._x = x;
this._y = y;
}
public get x() {
return this._x;
}
public get y() {
return this._y;
}
public static rotate(v:Vector, center:Vector, angle:number):Vector {
var dx:number = v.x - center.x;
var dy:number = v.y - center.y;
return new Vector(
(dx * Math.cos(angle) - dy * Math.sin(angle)) + center.x,
(dx * Math.sin(angle) + dy * Math.cos(angle)) + center.y);
}
}
export = Vector;
Last edited by VB.NET Developer; Jun 23rd, 2022 at 06:08 AM.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jun 22nd, 2022, 04:28 PM
#2
Re: Convert TypeScript to VB.NET
The triangle and vector classes could be converted easily enough, but that middle block may not have any true conversion. That's about rendering to a screen in a web page. You wouldn't be using VB.NET to render to a screen in a web page. You might be using Razor or Blazor, and you might be using ASP.NET, but not necessarily. It all depends on what you are actually trying to achieve. If you are rendering to a web page, then why not stick with the TypeScript. If you are trying to do something similar, but in Windows Forms, then you'd do it totally differently depending on what your goal was.
So, what's the objective?
My usual boring signature: Nothing
-
Jun 22nd, 2022, 04:58 PM
#3
Thread Starter
Hyperactive Member
Re: Convert TypeScript to VB.NET
Yeah, Ive noticed that before. I want to convert some random TS files.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jun 22nd, 2022, 05:34 PM
#4
Re: Convert TypeScript to VB.NET
TS is used in a place where VB.NET is not used: Web pages. Therefore, some things will convert well, other things won't convert well at all.
My usual boring signature: Nothing
-
Jun 23rd, 2022, 03:48 AM
#5
Re: Convert TypeScript to VB.NET
Originally Posted by VB.NET Developer
Yeah, Ive noticed that before. I want to convert some random TS files.
Random TS files?
I assume you have a need for the parts you want to convert?
-
Jun 23rd, 2022, 05:52 AM
#6
Thread Starter
Hyperactive Member
Re: Convert TypeScript to VB.NET
Originally Posted by Arnoutdv
Random TS files?
I assume you have a need for the parts you want to convert?
Sure, but I was wrong.
I want to convert .TS files from random projects.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jun 23rd, 2022, 08:13 AM
#7
Re: Convert TypeScript to VB.NET
Why not just rewrite / transcode the parts you need?
-
Jun 23rd, 2022, 08:20 AM
#8
Re: Convert TypeScript to VB.NET
-
Jun 23rd, 2022, 12:29 PM
#9
Thread Starter
Hyperactive Member
Re: Convert TypeScript to VB.NET
Originally Posted by Arnoutdv
Why not just rewrite / transcode the parts you need?
Sure, I thought about this, but conversion looks like this:
Code:
Class Vector
End Class
publicstaticrotate(v:= Vector, center:= Vector, angle:= number)
:Vector
{Dim dx
:number = (v.x - center.x)
Dim dy
:number = (v.y - center.y)
Return New Vector((((dx * Math.cos(angle)) _
- (dy * Math.sin(angle))) _
+ center.x), (((dx * Math.sin(angle)) _
+ (dy * Math.cos(angle))) _
+ center.y))
UnknownUnknownexport = Vector
Public Function x() As get
Return Me._x
End Function
Public Function y() As get
Return Me._y
End Function
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|