WaBis

walter.bislins.ch

JSG Test: Arc interaktiv

Code

<jscript>

function ArcModel() {
  this.Polygon = false;
  this.Segments = 8;
  this.Trans = 'window';
  this.YZoom = 1;
  this.InRect = false;
  this.InPath = false;
  this.Append = false;
  this.Close = false;
  this.Radius = 100;
  this.Start = 0;
  this.End = 270;
  this.Stroke = true;
  this.Fill = false;
  this.Width = 4;
  this.Cap = 'but';
}

var model = new ArcModel();

var jsg = NewGraph2D( { Width: 602, Height: 403, DrawFunc: Draw } );

function Draw( g ) {
  g.DisableNativeArc = model.Polygon;
  g.MaxCurveSegments = model.Segments;
  g.SetLineCap( model.Cap );
  g.SetWindowWH( 0, 0, g.VpInnerWidth, g.VpInnerHeight/model.YZoom );
  g.SelectTrans( model.Trans );
  g.SetAreaAttr( 'orange', 'blue', model.Width );
  var mode = 0;
  if (model.Stroke) mode += 1;
  if (model.Fill) mode += 2;
  if (model.Close) mode += 4;
  if (model.Append) mode += 8;
  if (model.InPath) {
    g.OpenPath();
  }
  if (model.InRect) g.Rect( 50, 50, 550, 350 );
  g.Arc( 300, 200, model.Radius, model.Start, model.End, mode );
  if (model.InPath) {
    g.Path( mode );
  }
  g.Polygon( [ 0, 0, 10 ], [ 10, 0, 0 ] );
}

function Update() {
  ControlPanels.Update();
  jsg.Redraw();
}

</jscript>

{{col|50}}

<jscript>

ControlPanels.NewSliderPanel( { ModelRef: 'model', OnModelChange: Update } 
).AddValueSliderField( { Name: 'Radius', Min: -300, Max: 300, Digits: 0 } 
).AddValueSliderField( { Name: 'Start', Min: -750, Max: 750, Digits: 0 } 
).AddValueSliderField( { Name: 'End', Min: -750, Max: 750, Digits: 0 } 
).AddValueSliderField( { Name: 'YZoom', Min: 0.95, Max: 1.05, Digits: 3 } 
).AddValueSliderField( { Name: 'Width', Min: 0, Max: 20, Digits: 1 } 
).Render();

</jscript>

{{col}}

<jscript>

ControlPanels.NewPanel( { ModelRef: 'model', OnModelChange: Update } 
).AddRadiobuttonField( {
  Name: 'Trans', 
  Items: [ 
    { Name: 'window' }, 
    { Name: 'viewport' },
    { Name: 'canvas' }
  ]
}).AddRadiobuttonField( {
  Name: 'Cap',
  Items: [
    { Name: 'but' },
    { Name: 'round' },
    { Name: 'square' }
  ]
}).AddRadiobuttonField( {
  Name: 'Segments',
  ValueType: 'int',
  Items: [
    { Name: '8', Value: '8' },
    { Name: '64', Value: '64' }
  ]
}).AddCheckboxField( {
  Name: 'Mode',
  Items: [
    { Name: 'Stroke' },
    { Name: 'Fill' },
    { Name: 'Close' },
    { Name: 'Append' }
  ]
}).AddCheckboxField( {
  Name: 'Path',
  Items: [
    { Name: 'InRect' },
    { Name: 'InPath' },
    { Name: 'Polygon' }
  ]
}).AddHtmlField( { Label: '-', Html: ControlPanels.SmallButton( 'Redraw', 'Update()' ) } 
).Render();

</jscript>

{{col|end}}

More Page Infos / Sitemap
Created Freitag, 12. Dezember 2014
Scroll to Top of Page
Changed Montag, 31. Oktober 2016