Random Python Script

by G.G.Otto, Apr 1, 2020, 10:50 PM

I made a few Python scripts for generating random asymptote. They is probably a way to do this with just Asymptote, but I like it when people wonder how I made it.

Random Line

Random Dots

Random Circles and Colors

Comment

6 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Wow. :) That is amazing!

by sonone, Apr 1, 2020, 11:04 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Can you make one that generates a random codes, like the ones with the little squares? Here is what you can randomize:
fill(shift(i,j)*unitsquare);


Here is what I tried (copied from your code above) but there is an undesirable result. Can you fix it?
  1. import random
  2. def random_code(n,i,j):
  3. asy = '[asy]'
  4. for i in range(1,n):
  5. asy += 'fill(shift('+str(random.randint(1,i))+','+str(random.randint(1,j))+')*unitsquare); '
  6. asy += '[/asy]'
  7. print(asy)
  8. random_code(10,10, 10)

[asy]fill(shift(1,6)*unitsquare); fill(shift(2,3)*unitsquare); fill(shift(2,6)*unitsquare); fill(shift(4,2)*unitsquare); fill(shift(1,5)*unitsquare); fill(shift(6,6)*unitsquare); fill(shift(4,9)*unitsquare); fill(shift(8,8)*unitsquare); fill(shift(1,10)*unitsquare); [/asy]
This post has been edited 1 time. Last edited by sonone, Apr 2, 2020, 12:19 AM

by sonone, Apr 2, 2020, 12:04 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
I don't see anything wrong. Do you mean the size?

by G.G.Otto, Apr 2, 2020, 5:18 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
If all the inputs for the function are equal, you get something like this:
[asy]fill(shift(1,9)*unitsquare); fill(shift(2,5)*unitsquare); fill(shift(1,5)*unitsquare); fill(shift(3,8)*unitsquare); fill(shift(5,9)*unitsquare); fill(shift(2,5)*unitsquare); fill(shift(6,10)*unitsquare); fill(shift(7,3)*unitsquare); fill(shift(6,6)*unitsquare); [/asy]
If the first input is bigger, you get this:
[asy]fill(shift(1,1)*unitsquare); fill(shift(2,7)*unitsquare); fill(shift(2,7)*unitsquare); fill(shift(3,2)*unitsquare); fill(shift(1,8)*unitsquare); fill(shift(1,7)*unitsquare); fill(shift(5,5)*unitsquare); fill(shift(5,1)*unitsquare); fill(shift(5,2)*unitsquare); fill(shift(5,5)*unitsquare); fill(shift(4,2)*unitsquare); fill(shift(1,2)*unitsquare); fill(shift(11,2)*unitsquare); fill(shift(14,2)*unitsquare); fill(shift(11,10)*unitsquare); fill(shift(5,10)*unitsquare); fill(shift(2,7)*unitsquare); fill(shift(6,7)*unitsquare); fill(shift(19,5)*unitsquare); fill(shift(16,10)*unitsquare); fill(shift(17,4)*unitsquare); fill(shift(22,2)*unitsquare); fill(shift(22,3)*unitsquare); fill(shift(24,1)*unitsquare); fill(shift(18,7)*unitsquare); fill(shift(16,2)*unitsquare); fill(shift(25,4)*unitsquare); fill(shift(11,8)*unitsquare); fill(shift(25,1)*unitsquare); fill(shift(6,4)*unitsquare); fill(shift(22,3)*unitsquare); fill(shift(10,7)*unitsquare); fill(shift(23,6)*unitsquare); fill(shift(1,5)*unitsquare); fill(shift(30,2)*unitsquare); fill(shift(20,1)*unitsquare); fill(shift(12,9)*unitsquare); fill(shift(38,4)*unitsquare); fill(shift(26,1)*unitsquare); fill(shift(36,8)*unitsquare); fill(shift(25,4)*unitsquare); fill(shift(11,3)*unitsquare); fill(shift(7,3)*unitsquare); fill(shift(32,3)*unitsquare); fill(shift(9,2)*unitsquare); fill(shift(6,8)*unitsquare); fill(shift(32,4)*unitsquare); fill(shift(33,7)*unitsquare); fill(shift(30,10)*unitsquare); [/asy]

by sonone, Apr 2, 2020, 10:44 AM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
I see two problems with your code.

First: notice that your function random_code(n,i,j) contains the same variable as your loop. This means that "i" does not equal 10, but actually equals whatever number the loops happens to be on. This is what produces the undesirable result in your code.

Second: (this a minor error) your code only produces n-1 squares. This because your loop starts from 1 and ends at n-1. To fix this, change your loop to range(n). This will make it start at 0 and end at n-1, producing n squares. You could also change your loop to range(1,n+1).

:)

by G.G.Otto, Apr 3, 2020, 8:00 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
[asy]dot((116,104)); dot((283,272)); dot((239,150)); dot((86,132)); dot((215,231)); dot((176,158)); dot((127,77)); dot((6,120)); dot((168,275)); dot((102,142)); dot((123,243)); dot((174,38)); dot((225,12)); dot((246,86)); dot((154,294)); dot((71,121)); dot((226,249)); dot((181,50)); dot((83,273)); dot((124,24)); dot((125,44)); dot((203,103)); dot((286,199)); dot((79,41)); dot((31,299)); dot((57,4)); dot((300,72)); dot((239,232)); dot((28,262)); dot((143,209)); dot((205,109)); dot((280,243)); dot((79,4)); dot((279,177)); dot((146,13)); dot((194,23)); dot((93,65)); dot((197,174)); dot((66,56)); dot((236,278)); dot((196,9)); dot((177,265)); dot((261,193)); dot((11,72)); dot((297,109)); dot((64,202)); dot((71,299)); dot((25,263)); dot((262,202)); dot((212,290)); dot((86,171)); dot((108,245)); dot((124,148)); dot((75,103)); dot((152,127)); dot((54,165)); dot((128,128)); dot((233,33)); dot((69,225)); dot((163,97)); dot((149,252)); dot((155,88)); dot((282,201)); dot((164,11)); dot((193,261)); dot((82,64)); dot((83,112)); dot((258,25)); dot((125,297)); dot((44,211)); dot((220,93)); dot((285,157)); dot((95,44)); dot((224,205)); dot((32,1)); dot((289,118)); dot((239,288)); dot((276,271)); dot((67,109)); dot((70,150)); dot((163,261)); dot((36,114)); dot((259,233)); dot((135,161)); dot((162,13)); dot((134,243)); dot((87,277)); dot((48,159)); dot((208,282)); dot((105,191)); dot((22,237)); dot((36,93)); dot((288,71)); dot((79,81)); dot((178,151)); dot((258,31)); dot((100,51)); dot((37,40)); dot((80,1)); dot((39,271)); dot((48,56)); dot((251,299)); dot((174,259)); dot((86,49)); dot((220,256)); dot((229,246)); dot((59,126)); dot((298,75)); dot((121,111)); dot((102,109)); dot((24,251)); dot((25,257)); dot((115,18)); dot((59,146)); dot((252,68)); dot((40,56)); dot((247,298)); dot((11,50)); dot((87,99)); dot((174,223)); dot((195,74)); dot((78,222)); dot((194,279)); dot((257,290)); dot((155,167)); dot((227,36)); dot((250,119)); dot((76,147)); dot((84,110)); dot((234,105)); dot((194,101)); dot((147,201)); dot((198,31)); dot((158,61)); dot((251,48)); dot((14,78)); dot((10,215)); dot((27,24)); dot((76,188)); dot((201,81)); dot((27,249)); dot((181,94)); dot((236,240)); dot((24,240)); dot((239,191)); dot((50,60)); dot((47,44)); dot((288,293)); dot((88,223)); dot((75,161)); dot((223,299)); dot((259,229)); dot((17,11)); dot((29,93)); dot((67,196)); dot((109,35)); dot((43,66)); dot((135,31)); dot((87,206)); dot((153,85)); dot((139,289)); dot((11,122)); dot((176,211)); dot((27,265)); dot((184,214)); dot((197,152)); dot((187,231)); dot((191,170)); dot((130,268)); dot((272,22)); dot((8,238)); dot((203,129)); dot((234,38)); dot((286,56)); dot((223,267)); dot((256,298)); dot((53,259)); dot((275,3)); dot((232,206)); dot((112,169)); dot((67,32)); dot((250,76)); dot((90,13)); dot((281,141)); dot((277,135)); dot((4,9)); dot((282,200)); dot((284,212)); dot((296,211)); dot((12,31)); dot((95,298)); dot((96,183)); dot((176,85)); dot((293,59)); dot((286,204)); dot((123,84)); dot((77,140)); dot((235,220)); dot((233,248)); dot((128,8)); dot((202,48)); dot((109,263)); dot((84,28)); dot((137,203)); dot((60,203)); dot((225,299)); dot((51,68)); dot((16,16)); dot((135,167)); dot((219,5)); dot((126,109)); dot((2,242)); dot((199,46)); dot((81,95)); dot((23,197)); dot((47,180)); dot((189,170)); dot((257,142)); dot((87,241)); dot((4,190)); dot((7,69)); dot((155,265)); dot((130,97)); dot((76,189)); dot((113,92)); dot((173,145)); dot((7,66)); dot((61,165)); dot((31,183)); dot((63,239)); dot((211,263)); dot((261,286)); dot((285,37)); dot((166,114)); dot((101,32)); dot((77,55)); dot((4,76)); dot((43,273)); dot((55,293)); dot((151,61)); dot((132,290)); dot((224,169)); dot((244,70)); dot((162,64)); dot((259,43)); dot((236,34)); dot((138,292)); dot((111,161)); dot((176,101)); dot((118,113)); dot((38,47)); dot((158,160)); dot((275,162)); dot((300,235)); dot((74,229)); dot((208,235)); dot((153,167)); dot((283,166)); dot((186,10)); dot((20,63)); dot((87,271)); dot((155,232)); dot((286,249)); dot((243,235)); dot((194,235)); dot((95,215)); dot((111,48)); dot((212,68)); dot((87,16)); dot((142,217)); dot((254,150)); dot((63,42)); dot((205,20)); dot((170,179)); dot((89,217)); dot((130,65)); dot((23,46)); dot((210,163)); dot((297,94)); dot((183,261)); dot((216,186)); dot((154,208)); dot((232,98)); dot((58,74)); dot((47,137)); dot((27,175)); dot((26,127)); dot((250,56)); dot((70,153)); dot((110,138)); dot((99,100)); dot((108,139)); dot((64,146)); dot((285,34)); dot((32,12)); dot((114,50)); dot((288,281)); dot((259,72)); dot((115,159)); dot((297,193)); draw((208,109)); [/asy]

by Major_Monogram, Mar 18, 2025, 9:41 PM

Old material is mostly Asymptote, new material is calculator programming

avatar

sonone
Archives
+ April 2023
+ August 2022
+ April 2021
+ August 2020
Shouts
Submit
  • I still exist as well.

    by G.G.Otto, Aug 11, 2023, 2:44 AM

  • hello I'm still here lol

    by player01, Aug 6, 2022, 6:24 PM

  • [REVIVAL] I will start posting more calculator relating posts very soon. Even though school has been busy, I have been programming my calculators a decent amount, so I have a lot to share...

    by sonone, Feb 18, 2022, 10:29 PM

  • wow its been like 2.5 years since geo class

    by pieMax2713, Feb 4, 2022, 8:38 PM

  • @violin21, I've been very busy with school lately and haven't been able to add another lesson. I will when i get a free moment

    by sonone, Aug 19, 2021, 12:45 AM

  • ORZ CODER

    by samrocksnature, Aug 9, 2021, 9:57 PM

  • Could you make more Asymptote lessons on your "How to do Asymptote" blog?

    by violin21, Aug 9, 2021, 7:26 PM

  • You can take it, just C&P the CSS into your CSS area

    by sonone, Apr 17, 2021, 10:08 PM

  • how can we take the CSS if we have permission to not take it?

    by GoogleNebula, Apr 17, 2021, 5:22 PM

  • That is awesome!

    by sonone, Apr 15, 2021, 10:09 PM

  • I modified your dodecahedron and got:
    [asy]
    import three;
    import solids;
    size(300);
    currentprojection=orthographic(0,1.3,1.2);
    light(0,5,10);

    real phi=(sqrt(6)+1)/3;
    real g=(phi-1)/2;
    real s=1/2;
    real a=sqrt(1-phi*phi/4-g*g)+phi/2;

    triple[] d;
    d[0]=(phi

    by Andrew2019, Mar 26, 2021, 12:15 AM

  • Not too many, just changing the color here and there. I really like your CSS!

    by sonone, Feb 2, 2021, 10:35 AM

  • Nice!

    I see you're making changes to the CSS. :)

    by G.G.Otto, Feb 1, 2021, 9:26 PM

  • I'm learning Java now!

    by sonone, Feb 1, 2021, 5:56 PM

  • And I took part of it from CaptainFlint and then added a ton of modifications. ;)

    by G.G.Otto, Dec 1, 2020, 8:56 AM

98 shouts
Tags
About Owner
  • Posts: 2106
  • Joined: Aug 20, 2016
Blog Stats
  • Blog created: Mar 28, 2020
  • Total entries: 61
  • Total visits: 4966
  • Total comments: 146
Search Blog
a