1- import { WebglPlot , WebglPlotConfig } from "../src/webglplot" ;
1+ import { WebglPlot } from "../src/webglplot" ;
22import { WbglPolygonPlot , PolygonConfig } from "../src/WbglPolygonPlot" ;
33import { WebglLinePlot , LineConfig } from "../src/WbglLinePlot" ; // Corrected import name
44
@@ -10,17 +10,10 @@ document.addEventListener("DOMContentLoaded", () => {
1010 }
1111 // canvas.width and canvas.height are now controlled by CSS via .canvas class
1212
13- const webglPlotConfig : WebglPlotConfig = {
14- antialias : true ,
15- transparent : false , // Keep canvas opaque for main drawing area
16- powerPerformance : "default" ,
17- preserveDrawing : false ,
18- } ;
19-
20- const wglp = new WebglPlot ( canvas , webglPlotConfig ) ;
13+ const wglp = new WebglPlot ( canvas ) ;
2114
2215 // Initialize WbglPolygonPlot
23- const polygonPlot = new WbglPolygonPlot ( wglp , 100 ) ;
16+ const polygonPlot = new WbglPolygonPlot ( wglp ) ;
2417
2518 // Initialize WbglLinePlot
2619 const linePlot = new WebglLinePlot ( wglp , 2 ) ; // Corrected class name
@@ -29,93 +22,117 @@ document.addEventListener("DOMContentLoaded", () => {
2922 const polygonConfigs : PolygonConfig [ ] = [ ] ;
3023
3124 // Triangle examples
32- polygonConfigs . push ( WbglPolygonPlot . createTriangle ( {
33- center : [ - 0.8 , 0.7 ] ,
34- radius : 0.1 ,
35- fillColor : [ 1 , 0 , 0 , 0.5 ] , // Red, semi-transparent
36- isFilled : true ,
37- isStroked : true ,
38- strokeColor : [ 0 , 0 , 0 , 1 ] ,
39- strokeWeight : 2 ,
40- } ) ) ;
41-
42- polygonConfigs . push ( WbglPolygonPlot . createTriangle ( {
43- center : [ - 0.6 , 0.7 ] ,
44- radius : 0.08 ,
45- rotation : Math . PI / 4 , // 45 degrees
46- fillColor : [ 1 , 0.5 , 0 , 0.7 ] , // Orange
47- isFilled : true ,
48- isStroked : false ,
49- offset : [ 0 , 0.1 ] // Shifted up slightly
50- } ) ) ;
25+ polygonConfigs . push (
26+ WbglPolygonPlot . createTriangle ( {
27+ center : [ - 0.8 , 0.7 ] ,
28+ radius : 0.1 ,
29+ fillColor : [ 1 , 0 , 0 , 0.5 ] , // Red, semi-transparent
30+ isFilled : true ,
31+ isStroked : true ,
32+ strokeColor : [ 0 , 0 , 0 , 1 ] ,
33+ strokeWeight : 2 ,
34+ } )
35+ ) ;
36+
37+ polygonConfigs . push (
38+ WbglPolygonPlot . createTriangle ( {
39+ center : [ - 0.6 , 0.7 ] ,
40+ radius : 0.08 ,
41+ rotation : Math . PI / 4 , // 45 degrees
42+ fillColor : [ 1 , 0.5 , 0 , 0.7 ] , // Orange
43+ isFilled : true ,
44+ isStroked : false ,
45+ offset : [ 0 , 0.1 ] , // Shifted up slightly
46+ } )
47+ ) ;
5148
5249 // Square examples
53- polygonConfigs . push ( WbglPolygonPlot . createSquare ( {
54- center : [ - 0.2 , 0.5 ] ,
55- size : 0.2 ,
56- fillColor : [ 0 , 1 , 0 , 0.6 ] , // Green
57- isFilled : true ,
58- strokeColor : [ 0.1 , 0.1 , 0.1 , 1 ] ,
59- strokeWeight : 3 ,
60- isStroked : true ,
61- } ) ) ;
62-
63- polygonConfigs . push ( WbglPolygonPlot . createSquare ( {
64- center : [ 0.1 , 0.5 ] ,
65- size : 0.15 ,
66- rotation : Math . PI / 6 , // 30 degrees
67- isFilled : false , // Stroke only
68- isStroked : true ,
69- strokeColor : [ 0 , 0 , 1 , 1 ] , // Blue
70- strokeWeight : 4 ,
71- scale : [ 1.5 , 1 ] // Stretched horizontally
72- } ) ) ;
50+ polygonConfigs . push (
51+ WbglPolygonPlot . createSquare ( {
52+ center : [ - 0.2 , 0.5 ] ,
53+ size : 0.2 ,
54+ fillColor : [ 0 , 1 , 0 , 0.6 ] , // Green
55+ isFilled : true ,
56+ strokeColor : [ 0.1 , 0.1 , 0.1 , 1 ] ,
57+ strokeWeight : 3 ,
58+ isStroked : true ,
59+ } )
60+ ) ;
61+
62+ polygonConfigs . push (
63+ WbglPolygonPlot . createSquare ( {
64+ center : [ 0.1 , 0.5 ] ,
65+ size : 0.15 ,
66+ rotation : Math . PI / 6 , // 30 degrees
67+ isFilled : false , // Stroke only
68+ isStroked : true ,
69+ strokeColor : [ 0 , 0 , 1 , 1 ] , // Blue
70+ strokeWeight : 4 ,
71+ scale : [ 1.5 , 1 ] , // Stretched horizontally
72+ } )
73+ ) ;
7374
7475 // Circle examples
75- polygonConfigs . push ( WbglPolygonPlot . createCircle ( {
76- center : [ 0.5 , 0.6 ] ,
77- radius : 0.1 ,
78- fillColor : [ 1 , 0 , 1 , 0.7 ] , // Magenta
79- isFilled : true ,
80- isStroked : true ,
81- strokeColor : [ 0.2 , 0.2 , 0.2 , 1 ] ,
82- strokeWeight : 1 ,
83- } ) ) ;
84-
85- polygonConfigs . push ( WbglPolygonPlot . createCircle ( {
86- center : [ 0.8 , 0.6 ] ,
87- radius : 0.07 ,
88- segments : 8 , // Octagon
89- fillColor : [ 0.5 , 0.5 , 1 , 0.8 ] , // Light blue
90- isFilled : true ,
91- isStroked : false ,
92- offset : [ 0 , - 0.1 ] ,
93- enabled : true ,
94- } ) ) ;
76+ polygonConfigs . push (
77+ WbglPolygonPlot . createCircle ( {
78+ center : [ 0.5 , 0.6 ] ,
79+ radius : 0.1 ,
80+ fillColor : [ 1 , 0 , 1 , 0.7 ] , // Magenta
81+ isFilled : true ,
82+ isStroked : true ,
83+ strokeColor : [ 0.2 , 0.2 , 0.2 , 1 ] ,
84+ strokeWeight : 1 ,
85+ } )
86+ ) ;
87+
88+ polygonConfigs . push (
89+ WbglPolygonPlot . createCircle ( {
90+ center : [ 0.8 , 0.6 ] ,
91+ radius : 0.07 ,
92+ segments : 8 , // Octagon
93+ fillColor : [ 0.5 , 0.5 , 1 , 0.8 ] , // Light blue
94+ isFilled : true ,
95+ isStroked : false ,
96+ offset : [ 0 , - 0.1 ] ,
97+ enabled : true ,
98+ } )
99+ ) ;
95100
96101 // A larger, more complex polygon (e.g., a star or custom shape)
97- const starPoints = new Float32Array ( [
98- 0.0 , 0.3 , // Top point
99- 0.07 , 0.1 ,
100- 0.25 , 0.1 ,
101- 0.1 , - 0.05 ,
102- 0.15 , - 0.25 ,
103- 0.0 , - 0.15 ,
104- - 0.15 , - 0.25 ,
105- - 0.1 , - 0.05 ,
106- - 0.25 , 0.1 ,
107- - 0.07 , 0.1 ,
108- ] . map ( p => p * 0.7 ) ) ; // Scaled down a bit
102+ const starPoints = new Float32Array (
103+ [
104+ 0.0 ,
105+ 0.3 , // Top point
106+ 0.07 ,
107+ 0.1 ,
108+ 0.25 ,
109+ 0.1 ,
110+ 0.1 ,
111+ - 0.05 ,
112+ 0.15 ,
113+ - 0.25 ,
114+ 0.0 ,
115+ - 0.15 ,
116+ - 0.15 ,
117+ - 0.25 ,
118+ - 0.1 ,
119+ - 0.05 ,
120+ - 0.25 ,
121+ 0.1 ,
122+ - 0.07 ,
123+ 0.1 ,
124+ ] . map ( ( p ) => p * 0.7 )
125+ ) ; // Scaled down a bit
109126
110127 polygonConfigs . push ( {
111- points : starPoints ,
112- fillColor : [ 1 , 1 , 0 , 0.7 ] , // Yellow
113- isFilled : true ,
114- strokeColor : [ 0.5 , 0.5 , 0 , 1 ] ,
115- strokeWeight : 2 ,
116- isStroked : true ,
117- offset : [ - 0.5 , - 0.4 ] , // Adjusted Y-offset for star
118- scale : [ 1 , 1 ]
128+ points : starPoints ,
129+ fillColor : [ 1 , 1 , 0 , 0.7 ] , // Yellow
130+ isFilled : true ,
131+ strokeColor : [ 0.5 , 0.5 , 0 , 1 ] ,
132+ strokeWeight : 2 ,
133+ isStroked : true ,
134+ offset : [ - 0.5 , - 0.4 ] , // Adjusted Y-offset for star
135+ scale : [ 1 , 1 ] ,
119136 } ) ;
120137
121138 // Initialize Polygons in WbglPolygonPlot
@@ -125,7 +142,7 @@ document.addEventListener("DOMContentLoaded", () => {
125142 const numPoints = 200 ;
126143 const sineWavePoints = new Float32Array ( numPoints * 2 ) ;
127144 for ( let i = 0 ; i < numPoints ; i ++ ) {
128- const x = - 0.9 + ( i / ( numPoints - 1 ) ) * 1.8 ; // X range from -0.9 to 0.9
145+ const x = - 0.9 + ( i / ( numPoints - 1 ) ) * 1.8 ; // X range from -0.9 to 0.9
129146 const y = Math . sin ( x * Math . PI * 2 ) * 0.2 - 0.7 ; // Sine wave, scaled and positioned lower
130147 sineWavePoints [ i * 2 ] = x ;
131148 sineWavePoints [ i * 2 + 1 ] = y ;
@@ -160,11 +177,16 @@ document.addEventListener("DOMContentLoaded", () => {
160177 setTimeout ( ( ) => {
161178 if ( polygonConfigs . length > 0 ) {
162179 polygonPlot . updatePolygonStyle ( 0 , { fillColor : [ 0 , 1 , 1 , 0.7 ] } ) ; // Change first polygon's fill to cyan
163- polygonPlot . updatePolygonTransform ( 1 , [ 1.5 , 1.5 ] , polygonConfigs [ 1 ] . offset || [ 0 , 0 ] ) ;
180+ polygonPlot . updatePolygonTransform (
181+ 1 ,
182+ [ 1.5 , 1.5 ] ,
183+ polygonConfigs [ 1 ] . offset || [ 0 , 0 ]
184+ ) ;
164185 // polygonConfigs[1].scale = [1.5,1.5]; // also update the source array if we re-init later
165186
166- console . log ( "Updated first polygon style and second polygon transform after 2 seconds." ) ;
187+ console . log (
188+ "Updated first polygon style and second polygon transform after 2 seconds."
189+ ) ;
167190 }
168191 } , 2000 ) ;
169-
170192} ) ;
0 commit comments