Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PC Fan Element - adds to storyboard #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ export { MicrosdCardElement } from './microsd-card-element';
export { DipSwitch8Element } from './dip-switch-8-element';
export { StepperMotorElement } from './stepper-motor-element';
export { HX711Element } from './hx711-element';
export { PcFanElement } from './pc-fan-element';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be PCFanElement

40 changes: 40 additions & 0 deletions src/pc-fan-element.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { html } from 'lit';
import { forceReRender } from '@storybook/web-components';
import './pc-fan-element';

class FanAnimation {
angle = 0;

step() {
this.angle = this.angle + 5;

if (this.angle >= 360) {
this.angle = 0;
}
}
}

const fanAnimation = new FanAnimation();
setInterval(() => {
fanAnimation.step();
forceReRender();
}, 10);

export default {
title: 'PC Fan',
component: 'wokwi-pc-fan',
argTypes: {
angle: { control: { type: 'number', min: 0, max: 360, step: 1 } },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using a "range" type for the control? I think it'll be more user friendly

},
args: {
angle: 0,
},
};

const Template = ({ angle }) => html`<wokwi-pc-fan angle=${angle}></wokwi-pc-fan>`;
export const Default = Template.bind({});
Default.args = { angle: 5 };

const TemplateOn = () => html`<wokwi-pc-fan angle=${fanAnimation.angle}></wokwi-pc-fan>`;
export const FanOn = TemplateOn.bind({});
FanOn.args = { angle: 0 };
57 changes: 57 additions & 0 deletions src/pc-fan-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { html, LitElement } from 'lit';
import { customElement, property } from 'lit/decorators.js';
import { ElementPin } from '.';

@customElement('wokwi-pc-fan')
export class PCFanElement extends LitElement {
/**
* The angle of the fan blades
*/
@property() angle = 0;

readonly pinInfo: ElementPin[] = [
{ name: 'VCC', x: 6, y: 152, signals: [{ type: 'power', signal: 'VCC' }] },
{ name: 'GND', x: 6, y: 160, signals: [{ type: 'power', signal: 'GND' }] },
{ name: 'PWM', x: 6, y: 169, signals: [{ type: 'pwm' }] },
];

render() {
/* eslint-disable prettier/prettier */
return html`
<style>
text {
user-select: none;
}
</style>
<svg version="1.1" width="50mm" height="50mm" viewBox="0 0 300 300" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g xmlns="http://www.w3.org/2000/svg">
<!-- Fan Cage -->
<path d="m282 8c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-266 0c-2.17 0-4.07 1.15-5.12 2.88-0.56 0.91-0.88 1.98-0.88 3.12 0 3.31 2.69 6 6 6 1.14 0 2.21-0.32 3.12-0.88 1.73-1.05 2.88-2.95 2.88-5.12 0-3.31-2.69-6-6-6zm134 2c-38.7 0-73.73 15.64-99.07 40.93-25.29 25.24-40.93 60.09-40.93 98.57 0 77.04 62.68 139.5 140 139.5 38.44 0 73.27-15.44 98.57-40.43 25.58-25.28 41.43-60.33 41.43-99.07 0-77.04-62.68-139.5-140-139.5zm132 269c-0.88 0-1.72 0.19-2.47 0.53-2.08 0.94-3.53 3.04-3.53 5.47 0 3.31 2.69 6 6 6 2.43 0 4.53-1.45 5.47-3.53 0.34-0.75 0.53-1.59 0.53-2.47 0-3.31-2.69-6-6-6zm-266 0c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm283.5-278.5v299h-299v-299h299z" fill="#2d2d2d" stroke="#e7e7e7" stroke-miterlimit="10"/>

<!-- Fan Blades and Hub -->
<g transform="translate(150 150) rotate(${this.angle})">
<path transform="rotate(-60)" d="m24.28-130.69c-20.74-1.38-39.98-1.48-60.18 3.59-2.37 0.6-3.19 2.19-3.19 4.98 0 4.45 0.98 5.23 3.19 9.51 8.38 16.19 10.84 14.39 18 31.44 7.56 17.99 8.8 23.41 11.45 38.64 8.44 1.67 8.91 1.23 17.23 4.57 9.4 3.85 9.31 4.02 18.22 9.95 0.74 0.49 1.32 0.85 1.67 0 1.63-3.96 5.81-23.45 6.25-28.45 2.59-13.79 3.65-18.57 3.65-48.93-2.82-17.91 0.35-24.19-16.29-25.3z" fill-rule="evenodd" stroke="#888888"/>
<path transform="rotate(240)" d="m24.28-130.69c-20.74-1.38-39.98-1.48-60.18 3.59-2.37 0.6-3.19 2.19-3.19 4.98 0 4.45 0.98 5.23 3.19 9.51 8.38 16.19 10.84 14.39 18 31.44 7.56 17.99 8.8 23.41 11.45 38.64 8.44 1.67 8.91 1.23 17.23 4.57 9.4 3.85 9.31 4.02 18.22 9.95 0.74 0.49 1.32 0.85 1.67 0 1.63-3.96 5.81-23.45 6.25-28.45 2.59-13.79 3.65-18.57 3.65-48.93-2.82-17.91 0.35-24.19-16.29-25.3z" fill-rule="evenodd" stroke="#888888"/>
<path transform="rotate(180)" d="m24.28-130.69c-20.74-1.38-39.98-1.48-60.18 3.59-2.37 0.6-3.19 2.19-3.19 4.98 0 4.45 0.98 5.23 3.19 9.51 8.38 16.19 10.84 14.39 18 31.44 7.56 17.99 8.8 23.41 11.45 38.64 8.44 1.67 8.91 1.23 17.23 4.57 9.4 3.85 9.31 4.02 18.22 9.95 0.74 0.49 1.32 0.85 1.67 0 1.63-3.96 5.81-23.45 6.25-28.45 2.59-13.79 3.65-18.57 3.65-48.93-2.82-17.91 0.35-24.19-16.29-25.3z" fill-rule="evenodd" stroke="#888888"/>
<path transform="rotate(120)" d="m24.28-130.69c-20.74-1.38-39.98-1.48-60.18 3.59-2.37 0.6-3.19 2.19-3.19 4.98 0 4.45 0.98 5.23 3.19 9.51 8.38 16.19 10.84 14.39 18 31.44 7.56 17.99 8.8 23.41 11.45 38.64 8.44 1.67 8.91 1.23 17.23 4.57 9.4 3.85 9.31 4.02 18.22 9.95 0.74 0.49 1.32 0.85 1.67 0 1.63-3.96 5.81-23.45 6.25-28.45 2.59-13.79 3.65-18.57 3.65-48.93-2.82-17.91 0.35-24.19-16.29-25.3z" fill-rule="evenodd" stroke="#888888"/>
<path transform="rotate(60)" d="m24.28-130.69c-20.74-1.38-39.98-1.48-60.18 3.59-2.37 0.6-3.19 2.19-3.19 4.98 0 4.45 0.98 5.23 3.19 9.51 8.38 16.19 10.84 14.39 18 31.44 7.56 17.99 8.8 23.41 11.45 38.64 8.44 1.67 8.91 1.23 17.23 4.57 9.4 3.85 9.31 4.02 18.22 9.95 0.74 0.49 1.32 0.85 1.67 0 1.63-3.96 5.81-23.45 6.25-28.45 2.59-13.79 3.65-18.57 3.65-48.93-2.82-17.91 0.35-24.19-16.29-25.3z" fill-rule="evenodd" stroke="#888888"/>
<path d="m24.78-128.69c-20.74-1.38-39.98-1.48-60.18 3.59-2.37 0.6-3.19 2.19-3.19 4.98 0 4.45 0.98 5.23 3.19 9.51 8.38 16.19 10.84 14.39 18 31.44 7.56 17.99 8.8 23.41 11.45 38.64 8.44 1.67 8.91 1.23 17.23 4.57 9.4 3.85 9.31 4.02 18.22 9.95 0.74 0.49 1.32 0.85 1.67 0 1.63-3.96 5.81-23.45 6.25-28.45 2.59-13.79 3.65-18.57 3.65-48.93-2.82-17.91 0.35-24.19-16.29-25.3z" fill-rule="evenodd" stroke="#888888"/>
<circle cx="0" cy="0" r="47.5" fill="#484848"/>
<circle cx="0" cy="0" r="40"/>
</g>

<!-- Terminals -->
<g xmlns="http://www.w3.org/2000/svg">
<circle cx="9" cy="269" r="3" fill="#fff" stroke="#c68f11" stroke-miterlimit="10"/>
<circle cx="9" cy="255" r="3" fill="#fff" stroke="#c68f11" stroke-miterlimit="10"/>
<circle cx="9" cy="241" r="3" fill="#fff" stroke="#c68f11" stroke-miterlimit="10"/>
<text fill="rgb(255, 255, 255)" font-family="HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, sans-serif" font-size="9">
<tspan x="15" y="273">PWM</tspan>
<tspan x="15" y="258">GND</tspan>
<tspan x="15" y="245">VCC</tspan>
</text>
</g>
</svg>
`;
}
}
2 changes: 2 additions & 0 deletions src/react-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { MicrosdCardElement } from './microsd-card-element';
import { DipSwitch8Element } from './dip-switch-8-element';
import { StepperMotorElement } from './stepper-motor-element';
import { HX711Element } from './hx711-element';
import { PCFanElement } from './pc-fan-element';

type WokwiElement<T> = Partial<T> & React.ClassAttributes<T>;

Expand Down Expand Up @@ -101,6 +102,7 @@ declare global {
'wokwi-dip-switch-8': WokwiElement<DipSwitch8Element>;
'wokwi-stepper-motor': WokwiElement<StepperMotorElement>;
'wokwi-hx711': WokwiElement<HX711Element>;
'wokwi-pc-fan': WokwiElement<PCFanElement>;
}
}
}