Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6069677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:50:53+00:00 2026-05-23T09:50:53+00:00

I’m trying to draw a static graph based on an Array of Numbers. This

  • 0

I’m trying to draw a static graph based on an Array of Numbers. This graph should be nice smooth sinus-like. The bottom values should be always zero, the upper values are specified in an Array of Numbers.

sample

I’ve been trying to achieve this effect with curveTo(), but without any luck.

EDIT: Values are like: 10, 15, 40, 28, 5, 2, 27 etc.

Can anyone help please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:50:53+00:00Added an answer on May 23, 2026 at 9:50 am

    curveTo() draws only quadratic Bezier curves, which essentially are parabolas segments. Hence, you have to conceive some tricky algorithm if you want to draw a sine with variable amplitude.

    I suggest that you should draw your curve with straight line segments. It will require quite a lot of iterations in a loop, but is a very simple approach one can code in just few minutes. Do you really need something more elaborate?

    Alternatively, have a look at http://code.google.com/p/bezier/ : their demo is cool.

    If you want to create something that can not be easily defined with a single equation, you may want to look at Lagrange approximation: it interpolates given points into a smooth function.

    EDIT Lagrange approximation example

    The code below draws the following:

    enter image description here

    package
    {
        import flash.display.Graphics;
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.geom.Rectangle;
    
        import org.noregret.math.LagrangeApproximator;
    
        [SWF(fps="31",width="600",height="600",backgroundColor="0xFFFFFF")]    
        public class LagrangeTest extends Sprite
        {
            private const plot:Sprite = new Sprite();
            private const approx:LagrangeApproximator = new LagrangeApproximator();
    
            public function LagrangeTest()
            {
                super();
                initialize();
            }
    
            private function initialize():void
            {
                stage.scaleMode = StageScaleMode.NO_SCALE;
                stage.align = StageAlign.TOP_LEFT;
                stage.addEventListener(Event.RESIZE, onResize);
                onResize();
    
                addChild(plot);
    
                // ADDING CONTROL POINTS (just took them at random)
                approx.addValue(0, 0);
                approx.addValue(50, -10);
                approx.addValue(100, 10);
                approx.addValue(150, -20);
                approx.addValue(200, -10);
                approx.addValue(250, -20);
                approx.addValue(300, -10);
                approx.addValue(350, 10);
                approx.addValue(400, -30);
                approx.addValue(450, 50);
                approx.addValue(500, 100);
                approx.addValue(550, 30);
                approx.addValue(600, 0);
    
                drawCurve(plot, 5, 0, 600);
            }
    
            private function drawCurve(target:Sprite, step:uint, fromArg:int, toArg:int):void 
            {
                var gfx:Graphics = target.graphics;
                gfx.clear();
    
                gfx.lineStyle(0, 0xCCCCCC, 1);
                gfx.moveTo(-50, 0);
                gfx.lineTo(50, 0);
                gfx.moveTo(0, -50);
                gfx.lineTo(0, 50);
    
                gfx.lineStyle(2, 0, 1);
    
                var minArg:int = Math.min(fromArg, toArg);
                var maxArg:int = Math.max(fromArg, toArg);
    
                if (step == 0) {
                    step = 1;
                }
    
                var value:Number;
                for (var i:Number = minArg; i<=maxArg; i+=step) {
                    value = approx.getApproximationValue(i);
                    if (i) {
                        gfx.lineTo(i, value);
                    } else {
                        gfx.moveTo(i, value);
                    }
                }
            }
    
            private function onResize(event:Event = null):void
            {
                plot.x = 10;
                plot.y = stage.stageHeight/2;
            }
        }
    }
    

    Approximator class

    package org.noregret.math 
    {
        import flash.geom.Point;
        import flash.utils.Dictionary;
    
        /**
         * @author Michael "Nox Noctis" Antipin (http://noregret.org)
         */
        public class LagrangeApproximator {
    
            private const points:Vector.<Point> = new Vector.<Point>();
            private const pointByArg:Dictionary = new Dictionary();
    
            private var isSorted:Boolean;
    
            public function LagrangeApproximator()
            {
            }
    
            public function addValue(argument:Number, value:Number):void
            {
                var point:Point;
                if (pointByArg[argument] != null) {
                    trace("LagrangeApproximator.addValue("+arguments+"): ERROR duplicate function argument!");
                    point = pointByArg[argument];
                } else {
                    point = new Point();
                    points.push(point);
                    pointByArg[argument] = point;
                }
                point.x = argument;
                point.y = value;
                isSorted = false;
            }
    
            public function getApproximationValue(argument:Number):Number
            {
                if (!isSorted) {
                    isSorted = true;
                    points.sort(sortByArgument);
                }
                var listLength:uint = points.length;
                var point1:Point, point2:Point;
                var result:Number = 0;
                var coefficient:Number;
                for(var i:uint =0; i<listLength; i++) {
                    coefficient = 1;
                    point1 = points[i];
                    for(var j:uint = 0; j<listLength; j++) {
                        if (i != j) {
                            point2 = points[j];
                            coefficient *= (argument-point2.x) / (point1.x-point2.x);
                        }
                    }        
                    result += point1.y * coefficient;
                }
                return result;
            }
    
            private function sortByArgument(a:Point, b:Point):int
            {
                if (a.x < b.x) {
                    return -1;
                }
                if (a.x > b.x) {
                    return 1;
                }            
                return 0;
            }
    
            public function get length():int
            {
                return points.length;            
            }
    
            public function clear():void
            {
                points.length = 0;
                var key:*;
                for (key in pointByArg) {
                    delete pointByArg[key];
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.