Monday, February 15, 2010

Give curves random color, just for fun

A few days ago, I drew some curves on a same plot. And now I want to randomize the curve color.

Because the color syntax can be expressed as letters such as k, g, b etc. and also as a three element row, which indicate the RBG mode, such as [1, 0, 1], [0.1,0.7, 0.4] and so on.

So here I wrote a M-file to randomize the color and plot 10 curves in each subplot.

%this code produce a three element row
%which can be used to specify a random color
%created on 02/15/2010
function rndclr=f()
rndclr=[rand, rand, rand];
%this code draws some curves
%of random color
clf
t=0:0.01:100*pi;
for j=1:9
for i=1:10
hold all;
x=(i+2)*cos(t/i)+cos((i-1)*t);
y=i*sin(t/i)+sin((i-3)*t);
subplot (3,3,j);
plot(x,y,'color',rndclr)
axis('equal')
axis off
end
end

And here is the figure:

6 comments:

  1. actually really helped me, just needed to use [rand,rand,rand] when trying to make a plot with n differently coloured graphs

    ReplyDelete
  2. I'm very glad to hear that!
    Thanks for commenting, Meredith.

    ReplyDelete
  3. Thanks! This is just what I needed, quick and helpful :)

    ReplyDelete
  4. I am glad to hear that, Dear Anonymous person :)

    ReplyDelete
  5. Thanks.. it helped me too..

    ReplyDelete
  6. The [rand rand rand] was helpful for me too, thanks for that.

    ReplyDelete

Any comments?

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...