Here’s a simplish, non-optimized drawing of the curve just to demostrate the parts. For a thicker curve line you may need to offset by half the thickness, at least on mac lines aren’t centered on the coordinates. And it’s plotting a line for every X pixel which makes lots of very short lines that don’t anti-alias well overall. Not sure of the best way to fix that and/or it depends on OS.
Also this isn’t doing any mouse work, I worked up a quick handling of that in this project in MainWindow1.
http://home.comcast.net/~trochoid/code/exp.zip
Setup: Add a Canvas named display locked on all sides. Add a Slider named YSlider on the left or right of the Canvas, locked top, bottom and the side its on with LiveScroll=true, Minimum = 1, Maximum = 999 and Value = 500. Then add these events…
[code]//YSlider
Sub ValueChanged()
display.Invalidate
End Sub
//display
Sub Paint(g As Graphics, areas() As REALbasic.Rect)
g.ForeColor = &c1D1D1D
g.FillRect 0, 0, g.Width, g.Height
//set defining x, y and calculate exponent so that x^exponent=y
dim x, y, exponent As double
x = 0.5
y = YSlider.Value / 1000
exponent = log(y) / log(x)
//calculate scalings for pixel x into [0, 1] and y in [0, 1] to pixel y
dim lastx, lasty As integer, xscaler, yscaler As double
lastx = g.Width - 1
lasty = g.Height - 1
xscaler = 1 / lastx //scaling down so lastx * xscaler = 1
yscaler = lasty //scaling up so 1 * yscaler = lasty
//plot curve
dim x0, y0, x1, y1 As double
x0 = 0 //set first line coord outside of loop, always bottom left
y0 = lasty
for pixX As integer = 1 to lastx
x = pixX * xscaler //calc <x, y> in curve coordinates
y = x ^ exponent
x1 = pixX //scale to pixel coordinates
y1 = lasty - y * yscaler
g.ForeColor = &c393939 //draw fill drop line
g.DrawLine x1, y1, x1, lasty
g.ForeColor = &cC1861A //draw curve line
g.DrawLine x0, y0, x1, y1
x0 = x1 //roll coords for next line
y0 = y1
next
//draw handle
y = 0.5 ^ exponent
g.ForeColor = &cFEFFB5
g.FillOval lastx * 0.5 - 5, lasty - y * yscaler - 5, 11, 11
End Sub[/code]
And here’s a class for drawing N-point bezier curves with an optional dash pattern
http://home.comcast.net/~trochoid/Bezo/Bezo_0.xojo_binary_project.zip
In the demo you can drag points around or context-click in empty space to add a new control point to the end. Or context-click on a point to delete that point.
Possibly beziers can be used to draw nicer anti-aliased approximations of the exponential curve but I’m not sure how to set the inner control points since they don’t actually lie on the curve. If there is a way and you’re on a mac then NSBezierPath will give the nicest rendering, I think that’s part of MacOSLib now.