Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok The long detailed BS that began this all is below the long line. The resulting answer is here.</p> <p>Your static points are x,y coordinates with the x values and y values placed in seperate arrays (coorArrx and coorArrY respectively) make sure to never use a value = imgx or imy.</p> <pre><code># Random Bezier Curve using De Casteljau's algorithm # http://en.wikipedia.org/wiki/Bezier_curve # http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm # FB - 201111244 import random from PIL import Image, ImageDraw imgx = 500 imgy = 500 image = Image.new("RGB", (imgx, imgy)) draw = ImageDraw.Draw(image) def B(coorArr, i, j, t): if j == 0: return coorArr[i] return B(coorArr, i, j - 1, t) * (1 - t) + B(coorArr, i + 1, j - 1, t) * t # n = random.randint(3, 6) # number of control points n=4 #coorArrX = [] #coorArrY = [] #for k in range(n): # x = random.randint(0, imgx - 1) # y = random.randint(0, imgy - 1) # coorArrX.append(x) # coorArrY.append(y) coorArrX=[3,129,12,77] coorArrY=[128,52,12,491] # plot the curve numSteps = 10000 for k in range(numSteps): t = float(k) / (numSteps - 1) x = int(B(coorArrX, 0, n - 1, t)) y = int(B(coorArrY, 0, n - 1, t)) try: image.putpixel((x, y), (0, 255, 0)) except: pass # plot the control points cr = 3 # circle radius for k in range(n): x = coorArrX[k] y = coorArrY[k] try: draw.ellipse((x - cr, y - cr, x + cr, y + cr), (255, 0, 0)) except: pass image.show() </code></pre> <p>=.........................................................................................= I am also something of a newcommer to all of this, and I REFUSE to look this up as I see it like you do...a learning experiencee.</p> <p>But as I look at this code I see something strange</p> <pre><code>for k in range(n): x = (0, imgx - 1) y = (0, imgy - 1) coorArrX.append(x) coorArrY.append(y) </code></pre> <p>Are you sure this part is correct? imgx is defined as 500 elsewhere, and n is 4. so this could read as </p> <pre><code>for k in range(4): x = (0, 500 - 1) y = (0, 500 - 1) </code></pre> <p>which (since these values never change at all in this code) means:</p> <pre><code>x = (0, 499) y = (0, 499) </code></pre> <p>on every pass. So each time they get to :</p> <pre><code>coorArrX.append(x) coorArrY.append(y) </code></pre> <p>They simply keep adding new copies of the same data to the array, so when it is done the array looks like this (internally)</p> <pre><code>[(0, 499), (0, 499), (0, 499), (0,499)] </code></pre> <p>What makes this more confusing, is that coorArrX and coorArrY are A) Identical, and B) identical in their basic parts(that is each element is identical). Therefore, when you get to this part of the code:</p> <pre><code># plot the control points cr = 3 # circle radius for k in range(n): x = coorArrX[k] y = coorArrY[k] try: draw.ellipse((x - cr, y - cr, x + cr, y + cr), (255, 0, 0)) except: pass </code></pre> <p>and you substitute in the values in the arrays, you get:</p> <pre><code># plot the control points cr = 3 # circle radius for k in range(n): x = coorArrX[k] y = coorArrY[k] try: draw.ellipse(((0, 499) - 3, (0, 499) - 3, (0, 499) + 3, (0, 499) + 3), (255, 0, 0)) except: pass </code></pre> <p>Now this is the part that controls the drawing of the curved segments for the plot, but I do not see how centering an elispe on those impossible coordinate sets can draw anything?!</p> <p>Broke down and did a copy paste test run. <strike>This code is purely bogus, either placed to dupe people into wasting time, or placed where OP found it for same reason.</strike></p> <p>But it was fun trying!!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload