OpenCores
URL https://opencores.org/ocsvn/pdp1/pdp1/trunk

Subversion Repositories pdp1

[/] [pdp1/] [trunk/] [sw/] [xyplot-nogl.js] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 yannv
/*
2
  Canvas 2D version of an XY oscilloscope (real time scatterplot).
3
  Goal performance: 5µs point processing time at 60Hz.
4
  That's about 3.3k points per frame.
5
 
6
  Next steps: Measure performance drawing 3400 random points.
7
  Make it read from a pipe of some sort (websocket?).
8
  Make a translator that we can pipe into.
9
  Why am I not doing this sort of thing in puredata?
10
 
11
 
12
*/
13
 
14
var width=1024, height=1024;
15
var imageData, ctx, frame=0;
16
 
17
function renderonce(event) {
18
    requestAnimationFrame( render );
19
}
20
var lastCalledTime, fps;
21
function renderloop(now) {
22
    if (render(now))  // Let render() decide if we finished.
23
        requestAnimationFrame( renderloop );
24
}
25
 
26
function render(now) {
27
    //    var now = Date.now()
28
    var delta;
29
    if(!lastCalledTime) {
30
        lastCalledTime = now;
31
        fps = 0;
32
        delta = 1e6;
33
    } else {
34
        delta = (now - lastCalledTime)/1000;
35
        lastCalledTime = now;
36
        fps = /*frame*/1/delta;
37
    }
38
 
39
    // Decay hack
40
    // This isn't nearly as good as an age based exponential falloff.
41
    // It produces the faint trace effect of digital emulated
42
    // phosphorous. Still, might be good enough for the moment.
43
    var alpha = 1-Math.exp(-5*delta);
44
    ctx.fillStyle = 'rgba(0,0,0,'+alpha+')';
45
    ctx.fillRect(0,0,width,height);
46
 
47
    // Plot colour
48
    ctx.fillStyle = 'rgba(255,255,255,1)';
49
    for (var i=0; i<5400; i++) {
50
        var x = Math.floor(Math.random()*width);
51
        var y = Math.floor(Math.random()*height);
52
        ctx.fillRect(x,y,1,1);
53
        /*
54
        var s = Math.floor(Math.sin(x/100)*height/2+height/2);
55
        var miny = Math.max(s-5,0), maxy=Math.min(s+5,height);
56
        for (var y=miny; y<maxy; y++) {
57
            var pi = (y*width+x)*4;
58
            imageData.data.fill(255, pi+0, pi+3);
59
            //imageData.data[pi+3] = 0;
60
        }
61
        */
62
    }
63
    //    ctx.putImageData(imageData, 0, 0);
64
 
65
    if (++frame==width) {
66
        frame=0;
67
        ctx.font = "48px serif";
68
        ctx.fillText(fps, width/3, height/3);
69
        return false;
70
    }
71
    return true;
72
}
73
 
74
function startrenderloop(event) {
75
    requestAnimationFrame( renderloop );
76
}
77
 
78
function start(canvasid) {
79
    canvas = document.getElementById(canvasid);
80
    if (!canvas.getContext) {
81
        alert("Canvas doesn't support contexts?");
82
        return;
83
    }
84
    canvas.onclick = startrenderloop;
85
    ctx = canvas.getContext("2d");
86
    /*
87
    imageData = ctx.createImageData(width,height);
88
 
89
    // TODO: Generate new points per frame
90
 
91
    imageData.data.fill(0);
92
    for (var pi = 3; pi < width*height*4; pi+=4)
93
        imageData.data[pi]=255;  // opaque
94
    ctx.putImageData(imageData, 0, 0);
95
    */
96
 
97
//    renderloop();
98
}
99
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.