Category: Code stuffs

Code for drawing a line using Bresenham algorithm in Javascript

Here is the snippet for drawing a line in javascript. function drawline(xa,ya,xb,yb){    var dx=Math.abs(xa-xb);    var dy=Math.abs(ya-yb);    var p=2*dy-dx;    var twody=2*dy;    var twodydx=2*(dy-dx);    var x,y,xend;     if(xa>xb)    {        x=xb;        y=yb;        xend=xa;    }    else    {        x=xa;        y=yb;        xend=xb;    }    drawpix(x,y);    while(x<xend)    {        x++;        if(p<0)        {            p+=twody;        }        else        {            y++;            p+=twodydx;        }        drawpix(x,y);    }} As in previous […]

Continue Reading

Drawing a single pixel on Javascript

well after a long procedure and searching for a whole day to draw a single pixel on a HTML5 canvas, this code as I wrote worked out to draw a single pixel. function drawpix(x,y){    var c1 = document.getElementById(“mainCanvas”);   var rContext = c1.getContext(“2d”);   rContext.beginPath();   rContext.moveTo(x,y);   rContext.lineTo(x+1,y+1);   rContext.closePath();   rContext.strokeStyle= ‘white’;   rContext.stroke();   } drawpix(10,10);

Continue Reading

Hello world in C#

// A Hello World! program in C#using System;namespace HelloWorld{    class Hello     {        static void Main()         {            System.Console.WriteLine(“Hello World!”);             // Keep the console window open in debug mode.            System.Console.WriteLine(“Press any key to exit.”);            System.Console.ReadKey();        }    }} Here the first line starts with the // sign which indicates that the line is comment and […]

Continue Reading