# Generating a hairy circle

**URL:** https://discourse.processing.org/t/generating-a-hairy-circle/25481
**Category:** Coding Questions
**Tags:** homework
**Created:** [November 17, 2020, 10:49am UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481 "2020-11-17T10:49:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![fiveyearplan](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fiveyearplan](https://discourse.processing.org/u/fiveyearplan)
#### Post date: [November 17, 2020, 10:49am UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481/1 "2020-11-17T10:49:30Z")

</div>

My assignment is to generate a hair-like/fur-like texture. For this case, I’m creating a circle of this texture and I would like some advice on how to improve it.

```auto
PGraphics create_fur_circle(int colour, int radius) {
	PGraphics pg = createGraphics(radius*2, radius*2);
	int x,y,v_x,v_y, v_x_0, v_y_0;
	int v_norm=10;
	int alpha=200;
	float thickness=0.1;
	int N_lines=1000; 
	int l_line=100;
	float alpha_max=3.14/3; // Angle between old vector v_0 and new vector v
	pg.beginDraw();
	pg.stroke(colour, alpha);
	pg.strokeWeight(thickness);
	for (int i=0; i<N_lines; i+=1) {
		// Finding x,y in circle
		do {
			x = int(random(width));
			y = int(random(height));
		} while(dist(width/2,height/2,x,y) > radius); 
		
		// Finding v with certain |v|
		do {
			v_x = int(random(-v_norm,v_norm));
			v_y = int(random(-v_norm,v_norm));
		} while(dist(0,0,v_x,v_y)>v_norm);
		
		for (int j=0; j<l_line; j+=1) {
			if (dist(width/2,height/2,x,y) > radius) break;
	
			// Drawing line
			pg.line(x, y, x+v_x, y+v_y);

			// Moving x, y
			x+=v_x;
			y+=v_y;

			// Store old vector coordinates
			v_x_0=v_x;
			v_y_0=v_y;
			do {
				v_x = int(random(-v_norm,v_norm));
				v_y = int(random(-v_norm,v_norm));
			// We need two conditions:
			// 1- The norm v_x,v_y is not greater than d
			// 2- The angle between v_x_0,v_y_0 (preceding vector) and v_x,v_y is not greater than alpha_max
			} while(dist(0,0,v_x,v_y)>v_norm && acos((v_x_0*v_x+v_y_0*v_y)/(v_norm*v_norm))>alpha_max);

		}
	}
	pg.endDraw();
	return pg;
}

```

Here is the result:

 ![toile](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/5ea789a9bbb6a72d56b3382b5448bc0aadb7f895.png)

Thanks.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 17, 2020, 12:08pm UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481/2 "2020-11-17T12:08:13Z")

</div>

Hello,

this looks great!

you could go 3D, make a sphere and place hair on the surface on the sphere

especially, on the head, above the ears and eyes, the hairs go upwards

on the side sideways

then the beard to the side and downwards

and make eyes

Warm regards,

Chrisir

---

<div class="post-metadata">

### Author: ![fiveyearplan](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fiveyearplan](https://discourse.processing.org/u/fiveyearplan)
#### Post date: [November 17, 2020, 12:31pm UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481/3 "2020-11-17T12:31:27Z")

</div>

I’m only working on 2D textures. Also, I think the texture looks like strands of hair randomly placed on the floor rather than hair on living skin, which is what I’m aiming for.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [November 17, 2020, 12:45pm UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481/4 "2020-11-17T12:45:55Z")

</div>

Hello,

Vary the shades (color) of the hairs.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/75180eda57ab9f0929719878f515d143660c2e21.jpeg)

Reminds me that I am overdue for a haircut.

`:)`

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 17, 2020, 12:50pm UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481/5 "2020-11-17T12:50:20Z")

</div>

> [@fiveyearplan](#):
>
> the texture looks like strands of hair randomly placed on the floor

even in 2D

- on the head, above the ears and eyes, the hairs go upwards

- on the side sideways

- then the beard to the side and downwards

- and make eyes

try a brown / black sphere instead of white

---

<div class="post-metadata">

### Author: ![fiveyearplan](https://avatars.discourse-cdn.com/v4/letter/f/db5fbb/32.png) [@fiveyearplan](https://discourse.processing.org/u/fiveyearplan)
#### Post date: [November 18, 2020, 4:05pm UTC](https://discourse.processing.org/t/generating-a-hairy-circle/25481/6 "2020-11-18T16:05:20Z")

</div>

Unfortunately this doesn’t help. I need a 2D texture that looks like hair on skin, something like this:

 ![projet2020-004](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/155335d09de02afc7f356e2d88c027c68bde1b9d.jpeg)

In essence, a hair texture that is suitable to be pasted over a silhouette.
